diff --git a/ext/base/dsapxsumpw/README.md b/ext/base/dsapxsumpw/README.md index 8556a5a28..ff65cc0bd 100644 --- a/ext/base/dsapxsumpw/README.md +++ b/ext/base/dsapxsumpw/README.md @@ -56,16 +56,14 @@ The function has the following parameters: - **x**: input [`Float32Array`][@stdlib/array/float32]. - **stride**: index increment for `x`. -The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to access every other element in `x`, +The `N` and `stride` parameters determine which elements in the strided array are accessed at runtime. For example, to access every other element in `x`, ```javascript var Float32Array = require( '@stdlib/array/float32' ); -var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] ); -var N = floor( x.length / 2 ); -var v = dsapxsumpw( N, 5.0, x, 2 ); +var v = dsapxsumpw( 4, 5.0, x, 2 ); // returns 25.0 ``` @@ -75,14 +73,11 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float32Array = require( '@stdlib/array/float32' ); -var floor = require( '@stdlib/math/base/special/floor' ); var x0 = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var N = floor( x0.length / 2 ); - -var v = dsapxsumpw( N, 5.0, x1, 2 ); +var v = dsapxsumpw( 4, 5.0, x1, 2 ); // returns 25.0 ``` @@ -108,12 +103,10 @@ While [`typed array`][mdn-typed-array] views mandate a view offset based on the ```javascript var Float32Array = require( '@stdlib/array/float32' ); -var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); -var N = floor( x.length / 2 ); -var v = dsapxsumpw.ndarray( N, 5.0, x, 2, 1 ); +var v = dsapxsumpw.ndarray( 4, 5.0, x, 2, 1 ); // returns 25.0 ``` @@ -139,18 +132,11 @@ var v = dsapxsumpw.ndarray( N, 5.0, x, 2, 1 ); ```javascript -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); -var Float32Array = require( '@stdlib/array/float32' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var dsapxsumpw = require( '@stdlib/blas/ext/base/dsapxsumpw' ); -var x; -var i; - -x = new Float32Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( randu()*100.0 ); -} +var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) ); console.log( x ); var v = dsapxsumpw( x.length, 5.0, x, 1 ); diff --git a/ext/base/dsapxsumpw/benchmark/benchmark.js b/ext/base/dsapxsumpw/benchmark/benchmark.js index 332259c16..c59df6cb3 100644 --- a/ext/base/dsapxsumpw/benchmark/benchmark.js +++ b/ext/base/dsapxsumpw/benchmark/benchmark.js @@ -21,14 +21,19 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float32Array = require( '@stdlib/array/float32' ); var pkg = require( './../package.json' ).name; var dsapxsumpw = require( './../lib/dsapxsumpw.js' ); +// VARIABLES // + +var rand = uniform( -100.0, 100.0 ); + + // FUNCTIONS // /** @@ -39,13 +44,7 @@ var dsapxsumpw = require( './../lib/dsapxsumpw.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = filledarrayBy( len, 'float32', rand ); return benchmark; function benchmark( b ) { diff --git a/ext/base/dsapxsumpw/benchmark/benchmark.native.js b/ext/base/dsapxsumpw/benchmark/benchmark.native.js index 693f662dd..918d07f00 100644 --- a/ext/base/dsapxsumpw/benchmark/benchmark.native.js +++ b/ext/base/dsapxsumpw/benchmark/benchmark.native.js @@ -22,10 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,6 +36,7 @@ var dsapxsumpw = tryRequire( resolve( __dirname, './../lib/dsapxsumpw.native.js' var opts = { 'skip': ( dsapxsumpw instanceof Error ) }; +var rand = uniform( -100.0, 100.0 ); // FUNCTIONS // @@ -48,13 +49,7 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = filledarrayBy( len, 'float32', rand ); return benchmark; function benchmark( b ) { diff --git a/ext/base/dsapxsumpw/benchmark/benchmark.ndarray.js b/ext/base/dsapxsumpw/benchmark/benchmark.ndarray.js index d39c59f32..6334702a3 100644 --- a/ext/base/dsapxsumpw/benchmark/benchmark.ndarray.js +++ b/ext/base/dsapxsumpw/benchmark/benchmark.ndarray.js @@ -21,14 +21,19 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float32Array = require( '@stdlib/array/float32' ); var pkg = require( './../package.json' ).name; var dsapxsumpw = require( './../lib/ndarray.js' ); +// VARIABLES // + +var rand = uniform( -100.0, 100.0 ); + + // FUNCTIONS // /** @@ -39,13 +44,7 @@ var dsapxsumpw = require( './../lib/ndarray.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = filledarrayBy( len, 'float32', rand ); return benchmark; function benchmark( b ) { diff --git a/ext/base/dsapxsumpw/benchmark/benchmark.ndarray.native.js b/ext/base/dsapxsumpw/benchmark/benchmark.ndarray.native.js index b962b5d8f..52a7e5467 100644 --- a/ext/base/dsapxsumpw/benchmark/benchmark.ndarray.native.js +++ b/ext/base/dsapxsumpw/benchmark/benchmark.ndarray.native.js @@ -22,10 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,6 +36,7 @@ var dsapxsumpw = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) var opts = { 'skip': ( dsapxsumpw instanceof Error ) }; +var rand = uniform( -100.0, 100.0 ); // FUNCTIONS // @@ -48,13 +49,7 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = filledarrayBy( len, 'float32', rand ); return benchmark; function benchmark( b ) { diff --git a/ext/base/dsapxsumpw/docs/repl.txt b/ext/base/dsapxsumpw/docs/repl.txt index 16f6318cb..fccb48a65 100644 --- a/ext/base/dsapxsumpw/docs/repl.txt +++ b/ext/base/dsapxsumpw/docs/repl.txt @@ -4,8 +4,8 @@ element and computes the sum using pairwise summation with extended accumulation and returning an extended precision result. - The `N` and `stride` parameters determine which elements in `x` are accessed - at runtime. + The `N` and `stride` parameters determine which elements in + the strided array are accessed at runtime. Indexing is relative to the first index. To introduce an offset, use a typed array view. @@ -39,20 +39,17 @@ 16.0 // Using `N` and `stride` parameters: - > x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > var stride = 2; - > {{alias}}( N, 5.0, x, stride ) + > x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] ) + > {{alias}}( 3, 5.0, x, 2 ) 16.0 // Using view offsets: > var x0 = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); > var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); - > stride = 2; - > {{alias}}( N, 5.0, x1, stride ) + > {{alias}}( 3, 5.0, x1, 2 ) 14.0 + {{alias}}.ndarray( N, alpha, x, stride, offset ) Adds a constant to each single-precision floating-point strided array element and computes the sum using pairwise summation with extended @@ -94,8 +91,7 @@ // Using offset parameter: > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > {{alias}}.ndarray( N, 5.0, x, 2, 1 ) + > {{alias}}.ndarray( 3, 5.0, x, 2, 1 ) 14.0 See Also diff --git a/ext/base/dsapxsumpw/examples/index.js b/ext/base/dsapxsumpw/examples/index.js index bf7b6c412..c35a255ec 100644 --- a/ext/base/dsapxsumpw/examples/index.js +++ b/ext/base/dsapxsumpw/examples/index.js @@ -18,18 +18,11 @@ 'use strict'; -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); -var Float32Array = require( '@stdlib/array/float32' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var dsapxsumpw = require( './../lib' ); -var x; -var i; - -x = new Float32Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( randu()*100.0 ); -} +var x = filledarrayBy( 10, 'float32', discreteUniform( -100.0, 100.0 ) ); console.log( x ); var v = dsapxsumpw( x.length, 5.0, x, 1 ); diff --git a/ext/base/dsapxsumpw/include.gypi b/ext/base/dsapxsumpw/include.gypi index 868c5c12e..26476a8c2 100644 --- a/ext/base/dsapxsumpw/include.gypi +++ b/ext/base/dsapxsumpw/include.gypi @@ -36,7 +36,7 @@ # Source files: 'src_files': [ - '<(src_dir)/addon.cpp', + '<(src_dir)/addon.c', ' +#include + +/** +* Receives JavaScript callback invocation data. +* +* @private +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 4 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_DOUBLE( env, alpha, argv, 1 ); + STDLIB_NAPI_ARGV_INT64( env, stride, argv, 3 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, stride, argv, 2 ); + + napi_value v; + napi_status status = napi_create_double( env, stdlib_strided_dsapxsumpw( N, alpha, X, stride ), &v ); + assert( status == napi_ok ); + + return v; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) \ No newline at end of file diff --git a/ext/base/dsapxsumpw/src/addon.cpp b/ext/base/dsapxsumpw/src/addon.cpp deleted file mode 100644 index 653350651..000000000 --- a/ext/base/dsapxsumpw/src/addon.cpp +++ /dev/null @@ -1,130 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/blas/ext/base/dsapxsumpw.h" -#include -#include -#include -#include -#include - -/** -* Add-on namespace. -*/ -namespace stdlib_blas_ext_base_dsapxsumpw { - - /** - * Adds a constant to each single-precision floating-point strided array element and computes the sum using pairwise summation with extended accumulation and returning an extended precision result. - * - * ## Notes - * - * - When called from JavaScript, the function expects four arguments: - * - * - `N`: number of indexed elements - * - `alpha`: constant - * - `X`: input array - * - `stride`: stride length - */ - napi_value node_dsapxsumpw( napi_env env, napi_callback_info info ) { - napi_status status; - - size_t argc = 4; - napi_value argv[ 4 ]; - status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr ); - assert( status == napi_ok ); - - if ( argc < 4 ) { - napi_throw_error( env, nullptr, "invalid invocation. Must provide 4 arguments." ); - return nullptr; - } - - napi_valuetype vtype0; - status = napi_typeof( env, argv[ 0 ], &vtype0 ); - assert( status == napi_ok ); - if ( vtype0 != napi_number ) { - napi_throw_type_error( env, nullptr, "invalid argument. First argument must be a number." ); - return nullptr; - } - - napi_valuetype vtype1; - status = napi_typeof( env, argv[ 1 ], &vtype1 ); - assert( status == napi_ok ); - if ( vtype1 != napi_number ) { - napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a number." ); - return nullptr; - } - - bool res; - status = napi_is_typedarray( env, argv[ 2 ], &res ); - assert( status == napi_ok ); - if ( res == false ) { - napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a Float32Array." ); - return nullptr; - } - - napi_valuetype vtype3; - status = napi_typeof( env, argv[ 3 ], &vtype3 ); - assert( status == napi_ok ); - if ( vtype3 != napi_number ) { - napi_throw_type_error( env, nullptr, "invalid argument. Fourth argument must be a number." ); - return nullptr; - } - - int64_t N; - status = napi_get_value_int64( env, argv[ 0 ], &N ); - assert( status == napi_ok ); - - double alpha; - status = napi_get_value_double( env, argv[ 1 ], &alpha ); - assert( status == napi_ok ); - - int64_t stride; - status = napi_get_value_int64( env, argv[ 3 ], &stride ); - assert( status == napi_ok ); - - napi_typedarray_type vtype2; - size_t xlen; - void *X; - status = napi_get_typedarray_info( env, argv[ 2 ], &vtype2, &xlen, &X, nullptr, nullptr ); - assert( status == napi_ok ); - if ( vtype2 != napi_float32_array ) { - napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a Float32Array." ); - return nullptr; - } - if ( (N-1)*llabs(stride) >= (int64_t)xlen ) { - napi_throw_range_error( env, nullptr, "invalid argument. Third argument has insufficient elements based on the associated stride and the number of indexed elements." ); - return nullptr; - } - - napi_value v; - status = napi_create_double( env, stdlib_strided_dsapxsumpw( N, (float)alpha, (float *)X, stride ), &v ); - assert( status == napi_ok ); - - return v; - } - - napi_value Init( napi_env env, napi_value exports ) { - napi_status status; - napi_value fcn; - status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, node_dsapxsumpw, NULL, &fcn ); - assert( status == napi_ok ); - return fcn; - } - - NAPI_MODULE( NODE_GYP_MODULE_NAME, Init ) -} // end namespace stdlib_blas_ext_base_dsapxsumpw diff --git a/ext/base/dsapxsumpw/test/test.dsapxsumpw.js b/ext/base/dsapxsumpw/test/test.dsapxsumpw.js index baae90f34..f69376f0c 100644 --- a/ext/base/dsapxsumpw/test/test.dsapxsumpw.js +++ b/ext/base/dsapxsumpw/test/test.dsapxsumpw.js @@ -21,7 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var dsapxsumpw = require( './../lib/dsapxsumpw.js' ); @@ -36,7 +35,7 @@ tape( 'main export is a function', function test( t ) { }); tape( 'the function has an arity of 4', function test( t ) { - t.strictEqual( dsapxsumpw.length, 4, 'has expected arity' ); + t.strictEqual( dsapxsumpw.length, 4, 'returns expected value' ); t.end(); }); @@ -103,7 +102,6 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', function test( t ) { - var N; var x; var v; @@ -118,15 +116,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]); - N = floor( x.length / 2 ); - v = dsapxsumpw( N, 5.0, x, 2 ); + v = dsapxsumpw( 4, 5.0, x, 2 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { - var N; var x; var v; var i; @@ -142,8 +138,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - N = floor( x.length / 2 ); - v = dsapxsumpw( N, 5.0, x, -2 ); + v = dsapxsumpw( 4, 5.0, x, -2 ); t.strictEqual( v, 25.0, 'returns expected value' ); @@ -172,7 +167,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f tape( 'the function supports view offsets', function test( t ) { var x0; var x1; - var N; var v; x0 = new Float32Array([ @@ -188,9 +182,8 @@ tape( 'the function supports view offsets', function test( t ) { ]); x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - N = floor(x1.length / 2); - v = dsapxsumpw( N, 5.0, x1, 2 ); + v = dsapxsumpw( 4, 5.0, x1, 2 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); diff --git a/ext/base/dsapxsumpw/test/test.dsapxsumpw.native.js b/ext/base/dsapxsumpw/test/test.dsapxsumpw.native.js index 30cf41fcf..1c7f5c6da 100644 --- a/ext/base/dsapxsumpw/test/test.dsapxsumpw.native.js +++ b/ext/base/dsapxsumpw/test/test.dsapxsumpw.native.js @@ -22,7 +22,6 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -45,7 +44,7 @@ tape( 'main export is a function', opts, function test( t ) { }); tape( 'the function has an arity of 4', opts, function test( t ) { - t.strictEqual( dsapxsumpw.length, 4, 'has expected arity' ); + t.strictEqual( dsapxsumpw.length, 4, 'returns expected value' ); t.end(); }); @@ -221,7 +220,6 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', opts, function test( t ) { - var N; var x; var v; @@ -236,15 +234,13 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { 2.0 ]); - N = floor( x.length / 2 ); - v = dsapxsumpw( N, 5.0, x, 2 ); + v = dsapxsumpw( 4, 5.0, x, 2 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { - var N; var x; var v; var i; @@ -260,8 +256,7 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - N = floor( x.length / 2 ); - v = dsapxsumpw( N, 5.0, x, -2 ); + v = dsapxsumpw( 4, 5.0, x, -2 ); t.strictEqual( v, 25.0, 'returns expected value' ); @@ -290,7 +285,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f tape( 'the function supports view offsets', opts, function test( t ) { var x0; var x1; - var N; var v; x0 = new Float32Array([ @@ -306,9 +300,8 @@ tape( 'the function supports view offsets', opts, function test( t ) { ]); x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - N = floor(x1.length / 2); - v = dsapxsumpw( N, 5.0, x1, 2 ); + v = dsapxsumpw( 4, 5.0, x1, 2 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); diff --git a/ext/base/dsapxsumpw/test/test.ndarray.js b/ext/base/dsapxsumpw/test/test.ndarray.js index 30e7ba481..0bff2d21e 100644 --- a/ext/base/dsapxsumpw/test/test.ndarray.js +++ b/ext/base/dsapxsumpw/test/test.ndarray.js @@ -21,7 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var dsapxsumpw = require( './../lib/ndarray.js' ); @@ -36,7 +35,7 @@ tape( 'main export is a function', function test( t ) { }); tape( 'the function has an arity of 5', function test( t ) { - t.strictEqual( dsapxsumpw.length, 5, 'has expected arity' ); + t.strictEqual( dsapxsumpw.length, 5, 'returns expected value' ); t.end(); }); @@ -103,7 +102,6 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', function test( t ) { - var N; var x; var v; @@ -118,15 +116,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]); - N = floor( x.length / 2 ); - v = dsapxsumpw( N, 5.0, x, 2, 0 ); + v = dsapxsumpw( 4, 5.0, x, 2, 0 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { - var N; var x; var v; var i; @@ -142,8 +138,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - N = floor( x.length / 2 ); - v = dsapxsumpw( N, 5.0, x, -2, 6 ); + v = dsapxsumpw( 4, 5.0, x, -2, 6 ); t.strictEqual( v, 25.0, 'returns expected value' ); @@ -170,7 +165,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f }); tape( 'the function supports an `offset` parameter', function test( t ) { - var N; var x; var v; @@ -184,9 +178,8 @@ tape( 'the function supports an `offset` parameter', function test( t ) { 3.0, 4.0 // 3 ]); - N = floor( x.length / 2 ); - v = dsapxsumpw( N, 5.0, x, 2, 1 ); + v = dsapxsumpw( 4, 5.0, x, 2, 1 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); diff --git a/ext/base/dsapxsumpw/test/test.ndarray.native.js b/ext/base/dsapxsumpw/test/test.ndarray.native.js index a5413bd2d..5357b0867 100644 --- a/ext/base/dsapxsumpw/test/test.ndarray.native.js +++ b/ext/base/dsapxsumpw/test/test.ndarray.native.js @@ -22,7 +22,6 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -45,7 +44,7 @@ tape( 'main export is a function', opts, function test( t ) { }); tape( 'the function has an arity of 5', opts, function test( t ) { - t.strictEqual( dsapxsumpw.length, 5, 'has expected arity' ); + t.strictEqual( dsapxsumpw.length, 5, 'returns expected value' ); t.end(); }); @@ -112,7 +111,6 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', opts, function test( t ) { - var N; var x; var v; @@ -127,15 +125,13 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { 2.0 ]); - N = floor( x.length / 2 ); - v = dsapxsumpw( N, 5.0, x, 2, 0 ); + v = dsapxsumpw( 4, 5.0, x, 2, 0 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { - var N; var x; var v; var i; @@ -151,8 +147,7 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - N = floor( x.length / 2 ); - v = dsapxsumpw( N, 5.0, x, -2, 6 ); + v = dsapxsumpw( 4, 5.0, x, -2, 6 ); t.strictEqual( v, 25.0, 'returns expected value' ); @@ -179,7 +174,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f }); tape( 'the function supports an `offset` parameter', opts, function test( t ) { - var N; var x; var v; @@ -193,9 +187,8 @@ tape( 'the function supports an `offset` parameter', opts, function test( t ) { 3.0, 4.0 // 3 ]); - N = floor( x.length / 2 ); - v = dsapxsumpw( N, 5.0, x, 2, 1 ); + v = dsapxsumpw( 4, 5.0, x, 2, 1 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end();