diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml index ec90164..f92a6c5 100644 --- a/.github/workflows/productionize.yml +++ b/.github/workflows/productionize.yml @@ -344,7 +344,6 @@ jobs: uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 with: status: ${{ job.status }} - steps: ${{ toJson(steps) }} channel: '#npm-ci' if: failure() @@ -518,7 +517,6 @@ jobs: uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 with: status: ${{ job.status }} - steps: ${{ toJson(steps) }} channel: '#npm-ci' if: failure() @@ -698,7 +696,6 @@ jobs: uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 with: status: ${{ job.status }} - steps: ${{ toJson(steps) }} channel: '#npm-ci' if: failure() diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 3eec50e..ad3a3e0 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -218,7 +218,6 @@ jobs: uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 with: status: ${{ job.status }} - steps: ${{ toJson(steps) }} channel: '#npm-ci' if: failure() diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 22868e6..d1b0546 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -95,6 +95,5 @@ jobs: uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 with: status: ${{ job.status }} - steps: ${{ toJson(steps) }} channel: '#npm-ci' if: failure() diff --git a/.github/workflows/test_bundles.yml b/.github/workflows/test_bundles.yml index 6d77abd..5b5879a 100644 --- a/.github/workflows/test_bundles.yml +++ b/.github/workflows/test_bundles.yml @@ -94,7 +94,6 @@ jobs: uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 with: status: ${{ job.status }} - steps: ${{ toJson(steps) }} channel: '#npm-ci' if: failure() @@ -139,7 +138,6 @@ jobs: uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 with: status: ${{ job.status }} - steps: ${{ toJson(steps) }} channel: '#npm-ci' if: failure() @@ -184,6 +182,5 @@ jobs: uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 with: status: ${{ job.status }} - steps: ${{ toJson(steps) }} channel: '#npm-ci' if: failure() diff --git a/.github/workflows/test_coverage.yml b/.github/workflows/test_coverage.yml index f4eda1e..2bcf0cd 100644 --- a/.github/workflows/test_coverage.yml +++ b/.github/workflows/test_coverage.yml @@ -119,7 +119,6 @@ jobs: uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 with: status: ${{ job.status }} - steps: ${{ toJson(steps) }} channel: '#npm-ci' if: failure() diff --git a/.github/workflows/test_install.yml b/.github/workflows/test_install.yml index c7141a3..f8a6a58 100644 --- a/.github/workflows/test_install.yml +++ b/.github/workflows/test_install.yml @@ -81,6 +81,5 @@ jobs: uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 with: status: ${{ job.status }} - steps: ${{ toJson(steps) }} channel: '#npm-ci' if: failure() diff --git a/README.md b/README.md index 0da9c06..2a38058 100644 --- a/README.md +++ b/README.md @@ -89,16 +89,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 compute the sum of every other element in `x`, +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the sum of 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, NaN, -7.0, NaN, 3.0, 4.0, 2.0 ] ); -var N = floor( x.length / 2 ); -var v = dsnansumors( N, x, 2 ); +var v = dsnansumors( 4, x, 2 ); // returns 5.0 ``` @@ -108,14 +106,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, NaN, -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 = dsnansumors( N, x1, 2 ); +var v = dsnansumors( 4, x1, 2 ); // returns 5.0 ``` @@ -127,9 +122,8 @@ Computes the sum of single-precision floating-point strided array elements, igno var Float32Array = require( '@stdlib/array-float32' ); var x = new Float32Array( [ 1.0, -2.0, NaN, 2.0 ] ); -var N = x.length; -var v = dsnansumors.ndarray( N, x, 1, 0 ); +var v = dsnansumors.ndarray( 4, x, 1, 0 ); // returns 1.0 ``` @@ -137,16 +131,14 @@ The function has the following additional parameters: - **offset**: starting index for `x`. -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offset` parameter supports indexing semantics based on a starting index. For example, to calculate the sum of every other value in `x` starting from the second value +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the offset parameter supports indexing semantics based on a starting index. For example, to calculate the sum of every other value in `x` starting from the second value ```javascript var Float32Array = require( '@stdlib/array-float32' ); -var floor = require( '@stdlib/math-base-special-floor' ); var x = new Float32Array( [ 2.0, 1.0, NaN, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); -var N = floor( x.length / 2 ); -var v = dsnansumors.ndarray( N, x, 2, 1 ); +var v = dsnansumors.ndarray( 4, x, 2, 1 ); // returns 5.0 ``` @@ -172,22 +164,19 @@ var v = dsnansumors.ndarray( N, 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' ); +var bernoulli = require( '@stdlib/random-base-bernoulli' ); +var filledarrayBy = require( '@stdlib/array-filled-by' ); var dsnansumors = require( '@stdlib/blas-ext-base-dsnansumors' ); -var x; -var i; - -x = new Float32Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - if ( randu() < 0.2 ) { - x[ i ] = NaN; - } else { - x[ i ] = round( randu()*100.0 ); +function rand() { + if ( bernoulli( 0.8 ) > 0 ) { + return NaN; } + return discreteUniform( 0, 100 ); } + +var x = filledarrayBy( 10, 'float32', rand ); console.log( x ); var v = dsnansumors( x.length, x, 1 ); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js index d4cad7e..259e76b 100644 --- a/benchmark/benchmark.js +++ b/benchmark/benchmark.js @@ -21,10 +21,11 @@ // MODULES // var bench = require( '@stdlib/bench-harness' ); -var randu = require( '@stdlib/random-base-randu' ); +var uniform = require( '@stdlib/random-base-uniform' ); +var bernoulli = require( '@stdlib/random-base-bernoulli' ); +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 dsnansumors = require( './../lib/dsnansumors.js' ); @@ -39,18 +40,15 @@ var dsnansumors = require( './../lib/dsnansumors.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; + var x = filledarrayBy( len, 'float32', rand ); + return benchmark; - x = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - if ( randu() < 0.2 ) { - x[ i ] = NaN; - } else { - x[ i ] = ( randu()*20.0 ) - 10.0; + function rand() { + if ( bernoulli( 0.8 ) > 0 ) { + return NaN; } + return uniform( -10, 10 ); } - return benchmark; function benchmark( b ) { var v; diff --git a/benchmark/benchmark.native.js b/benchmark/benchmark.native.js index a47df1d..767c8aa 100644 --- a/benchmark/benchmark.native.js +++ b/benchmark/benchmark.native.js @@ -22,10 +22,11 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench-harness' ); -var randu = require( '@stdlib/random-base-randu' ); +var uniform = require( '@stdlib/random-base-uniform' ); +var bernoulli = require( '@stdlib/random-base-bernoulli' ); +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; @@ -48,18 +49,15 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; + var x = filledarrayBy( len, 'float32', rand ); + return benchmark; - x = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - if ( randu() < 0.2 ) { - x[ i ] = NaN; - } else { - x[ i ] = ( randu()*20.0 ) - 10.0; + function rand() { + if ( bernoulli( 0.8 ) > 0 ) { + return NaN; } + return uniform( -10, 10 ); } - return benchmark; function benchmark( b ) { var v; diff --git a/benchmark/benchmark.ndarray.js b/benchmark/benchmark.ndarray.js index 52f8691..75923fc 100644 --- a/benchmark/benchmark.ndarray.js +++ b/benchmark/benchmark.ndarray.js @@ -21,10 +21,11 @@ // MODULES // var bench = require( '@stdlib/bench-harness' ); -var randu = require( '@stdlib/random-base-randu' ); +var uniform = require( '@stdlib/random-base-uniform' ); +var bernoulli = require( '@stdlib/random-base-bernoulli' ); +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 dsnansumors = require( './../lib/ndarray.js' ); @@ -39,18 +40,15 @@ var dsnansumors = require( './../lib/ndarray.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; + var x = filledarrayBy( len, 'float32', rand ); + return benchmark; - x = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - if ( randu() < 0.2 ) { - x[ i ] = NaN; - } else { - x[ i ] = ( randu()*20.0 ) - 10.0; + function rand() { + if ( bernoulli( 0.8 ) > 0 ) { + return NaN; } + return uniform( -10, 10 ); } - return benchmark; function benchmark( b ) { var v; diff --git a/benchmark/benchmark.ndarray.native.js b/benchmark/benchmark.ndarray.native.js index 2864f85..6e95948 100644 --- a/benchmark/benchmark.ndarray.native.js +++ b/benchmark/benchmark.ndarray.native.js @@ -22,10 +22,11 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench-harness' ); -var randu = require( '@stdlib/random-base-randu' ); +var uniform = require( '@stdlib/random-base-uniform' ); +var bernoulli = require( '@stdlib/random-base-bernoulli' ); +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; @@ -48,18 +49,15 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; + var x = filledarrayBy( len, 'float32', rand ); + return benchmark; - x = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - if ( randu() < 0.2 ) { - x[ i ] = NaN; - } else { - x[ i ] = ( randu()*20.0 ) - 10.0; + function rand() { + if ( bernoulli( 0.8 ) > 0 ) { + return NaN; } + return uniform( -10, 10 ); } - return benchmark; function benchmark( b ) { var v; diff --git a/dist/index.js.map b/dist/index.js.map index 0dd203e..94e2ab2 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1,7 +1,7 @@ { "version": 3, "sources": ["../lib/dsnansumors.js", "../lib/ndarray.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using ordinary recursive summation with extended accumulation, and returning an extended precision result.\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {Float32Array} x - input array\n* @param {integer} stride - stride length\n* @returns {number} sum\n*\n* @example\n* var Float32Array = require( '@stdlib/array-float32' );\n*\n* var x = new Float32Array( [ 1.0, -2.0, NaN, 2.0 ] );\n* var N = x.length;\n*\n* var v = dsnansumors( N, x, 1 );\n* // returns 1.0\n*/\nfunction dsnansumors( N, x, stride ) {\n\tvar sum;\n\tvar ix;\n\tvar i;\n\n\tsum = 0.0;\n\tif ( N <= 0 ) {\n\t\treturn sum;\n\t}\n\tif ( N === 1 || stride === 0 ) {\n\t\tif ( isnan( x[ 0 ] ) ) {\n\t\t\treturn sum;\n\t\t}\n\t\treturn x[ 0 ];\n\t}\n\tif ( stride < 0 ) {\n\t\tix = (1-N) * stride;\n\t} else {\n\t\tix = 0;\n\t}\n\tfor ( i = 0; i < N; i++ ) {\n\t\tif ( isnan( x[ ix ] ) === false ) {\n\t\t\tsum += x[ ix ];\n\t\t}\n\t\tix += stride;\n\t}\n\treturn sum;\n}\n\n\n// EXPORTS //\n\nmodule.exports = dsnansumors;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using ordinary recursive summation with extended accumulation, and returning an extended precision result.\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {Float32Array} x - input array\n* @param {integer} stride - stride length\n* @param {NonNegativeInteger} offset - starting index\n* @returns {number} sum\n*\n* @example\n* var Float32Array = require( '@stdlib/array-float32' );\n* var floor = require( '@stdlib/math-base-special-floor' );\n*\n* var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] );\n* var N = floor( x.length / 2 );\n*\n* var v = dsnansumors( N, x, 2, 1 );\n* // returns 5.0\n*/\nfunction dsnansumors( N, x, stride, offset ) {\n\tvar sum;\n\tvar ix;\n\tvar i;\n\n\tsum = 0.0;\n\tif ( N <= 0 ) {\n\t\treturn sum;\n\t}\n\tif ( N === 1 || stride === 0 ) {\n\t\tif ( isnan( x[ offset ] ) ) {\n\t\t\treturn sum;\n\t\t}\n\t\treturn x[ offset ];\n\t}\n\tix = offset;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tif ( isnan( x[ ix ] ) === false ) {\n\t\t\tsum += x[ ix ];\n\t\t}\n\t\tix += stride;\n\t}\n\treturn sum;\n}\n\n\n// EXPORTS //\n\nmodule.exports = dsnansumors;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar dsnansumors = require( './dsnansumors.js' );\nvar ndarray = require( './ndarray.js' );\n\n\n// MAIN //\n\nsetReadOnly( dsnansumors, 'ndarray', ndarray );\n\n\n// EXPORTS //\n\nmodule.exports = dsnansumors;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Compute the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using ordinary recursive summation with extended accumulation, and returning an extended precision result.\n*\n* @module @stdlib/blas-ext-base-dsnansumors\n*\n* @example\n* var Float32Array = require( '@stdlib/array-float32' );\n* var dsnansumors = require( '@stdlib/blas-ext-base-dsnansumors' );\n*\n* var x = new Float32Array( [ 1.0, -2.0, NaN, 2.0 ] );\n* var N = x.length;\n*\n* var v = dsnansumors( N, x, 1 );\n* // returns 1.0\n*\n* @example\n* var Float32Array = require( '@stdlib/array-float32' );\n* var floor = require( '@stdlib/math-base-special-floor' );\n* var dsnansumors = require( '@stdlib/blas-ext-base-dsnansumors' );\n*\n* var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] );\n* var N = floor( x.length / 2 );\n*\n* var v = dsnansumors.ndarray( N, x, 2, 1 );\n* // returns 5.0\n*/\n\n// MODULES //\n\nvar join = require( 'path' ).join;\nvar tryRequire = require( '@stdlib/utils-try-require' );\nvar isError = require( '@stdlib/assert-is-error' );\nvar main = require( './main.js' );\n\n\n// MAIN //\n\nvar dsnansumors;\nvar tmp = tryRequire( join( __dirname, './native.js' ) );\nif ( isError( tmp ) ) {\n\tdsnansumors = main;\n} else {\n\tdsnansumors = tmp;\n}\n\n\n// EXPORTS //\n\nmodule.exports = dsnansumors;\n\n// exports: { \"ndarray\": \"dsnansumors.ndarray\" }\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAQ,QAAS,iCAAkC,EAsBvD,SAASC,EAAaC,EAAGC,EAAGC,EAAS,CACpC,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAM,EACDH,GAAK,EACT,OAAOG,EAER,GAAKH,IAAM,GAAKE,IAAW,EAC1B,OAAKJ,EAAOG,EAAG,CAAE,CAAE,EACXE,EAEDF,EAAG,CAAE,EAOb,IALKC,EAAS,EACbE,GAAM,EAAEJ,GAAKE,EAEbE,EAAK,EAEAC,EAAI,EAAGA,EAAIL,EAAGK,IACdP,EAAOG,EAAGG,CAAG,CAAE,IAAM,KACzBD,GAAOF,EAAGG,CAAG,GAEdA,GAAMF,EAEP,OAAOC,CACR,CAKAN,EAAO,QAAUE,IC5EjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAQ,QAAS,iCAAkC,EAwBvD,SAASC,EAAaC,EAAGC,EAAGC,EAAQC,EAAS,CAC5C,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAM,EACDJ,GAAK,EACT,OAAOI,EAER,GAAKJ,IAAM,GAAKE,IAAW,EAC1B,OAAKJ,EAAOG,EAAGE,CAAO,CAAE,EAChBC,EAEDH,EAAGE,CAAO,EAGlB,IADAE,EAAKF,EACCG,EAAI,EAAGA,EAAIN,EAAGM,IACdR,EAAOG,EAAGI,CAAG,CAAE,IAAM,KACzBD,GAAOH,EAAGI,CAAG,GAEdA,GAAMH,EAEP,OAAOE,CACR,CAKAP,EAAO,QAAUE,IC1EjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAc,IACdC,EAAU,IAKdF,EAAaC,EAAa,UAAWC,CAAQ,EAK7CH,EAAO,QAAUE,ICejB,IAAIE,EAAO,QAAS,MAAO,EAAE,KACzBC,EAAa,QAAS,2BAA4B,EAClDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAO,IAKPC,EACAC,EAAMJ,EAAYD,EAAM,UAAW,aAAc,CAAE,EAClDE,EAASG,CAAI,EACjBD,EAAcD,EAEdC,EAAcC,EAMf,OAAO,QAAUD", + "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using ordinary recursive summation with extended accumulation, and returning an extended precision result.\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {Float32Array} x - input array\n* @param {integer} stride - stride length\n* @returns {number} sum\n*\n* @example\n* var Float32Array = require( '@stdlib/array-float32' );\n*\n* var x = new Float32Array( [ 1.0, -2.0, NaN, 2.0 ] );\n* var N = x.length;\n*\n* var v = dsnansumors( N, x, 1 );\n* // returns 1.0\n*/\nfunction dsnansumors( N, x, stride ) {\n\tvar sum;\n\tvar ix;\n\tvar i;\n\n\tsum = 0.0;\n\tif ( N <= 0 ) {\n\t\treturn sum;\n\t}\n\tif ( N === 1 || stride === 0 ) {\n\t\tif ( isnan( x[ 0 ] ) ) {\n\t\t\treturn sum;\n\t\t}\n\t\treturn x[ 0 ];\n\t}\n\tif ( stride < 0 ) {\n\t\tix = (1-N) * stride;\n\t} else {\n\t\tix = 0;\n\t}\n\tfor ( i = 0; i < N; i++ ) {\n\t\tif ( isnan( x[ ix ] ) === false ) {\n\t\t\tsum += x[ ix ];\n\t\t}\n\t\tix += stride;\n\t}\n\treturn sum;\n}\n\n\n// EXPORTS //\n\nmodule.exports = dsnansumors;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using ordinary recursive summation with extended accumulation, and returning an extended precision result.\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {Float32Array} x - input array\n* @param {integer} stride - stride length\n* @param {NonNegativeInteger} offset - starting index\n* @returns {number} sum\n*\n* @example\n* var Float32Array = require( '@stdlib/array-float32' );\n*\n* var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] );\n*\n* var v = dsnansumors( 5, x, 2, 1 );\n* // returns 5.0\n*/\nfunction dsnansumors( N, x, stride, offset ) {\n\tvar sum;\n\tvar ix;\n\tvar i;\n\n\tsum = 0.0;\n\tif ( N <= 0 ) {\n\t\treturn sum;\n\t}\n\tif ( N === 1 || stride === 0 ) {\n\t\tif ( isnan( x[ offset ] ) ) {\n\t\t\treturn sum;\n\t\t}\n\t\treturn x[ offset ];\n\t}\n\tix = offset;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tif ( isnan( x[ ix ] ) === false ) {\n\t\t\tsum += x[ ix ];\n\t\t}\n\t\tix += stride;\n\t}\n\treturn sum;\n}\n\n\n// EXPORTS //\n\nmodule.exports = dsnansumors;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar dsnansumors = require( './dsnansumors.js' );\nvar ndarray = require( './ndarray.js' );\n\n\n// MAIN //\n\nsetReadOnly( dsnansumors, 'ndarray', ndarray );\n\n\n// EXPORTS //\n\nmodule.exports = dsnansumors;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Compute the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using ordinary recursive summation with extended accumulation, and returning an extended precision result.\n*\n* @module @stdlib/blas-ext-base-dsnansumors\n*\n* @example\n* var Float32Array = require( '@stdlib/array-float32' );\n* var dsnansumors = require( '@stdlib/blas-ext-base-dsnansumors' );\n*\n* var x = new Float32Array( [ 1.0, -2.0, NaN, 2.0 ] );\n* var N = x.length;\n*\n* var v = dsnansumors( N, x, 1 );\n* // returns 1.0\n*\n* @example\n* var Float32Array = require( '@stdlib/array-float32' );\n* var dsnansumors = require( '@stdlib/blas-ext-base-dsnansumors' );\n*\n* var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] );\n*\n* var v = dsnansumors.ndarray( 5, x, 2, 1 );\n* // returns 5.0\n*/\n\n// MODULES //\n\nvar join = require( 'path' ).join;\nvar tryRequire = require( '@stdlib/utils-try-require' );\nvar isError = require( '@stdlib/assert-is-error' );\nvar main = require( './main.js' );\n\n\n// MAIN //\n\nvar dsnansumors;\nvar tmp = tryRequire( join( __dirname, './native.js' ) );\nif ( isError( tmp ) ) {\n\tdsnansumors = main;\n} else {\n\tdsnansumors = tmp;\n}\n\n\n// EXPORTS //\n\nmodule.exports = dsnansumors;\n\n// exports: { \"ndarray\": \"dsnansumors.ndarray\" }\n"], + "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAQ,QAAS,iCAAkC,EAsBvD,SAASC,EAAaC,EAAGC,EAAGC,EAAS,CACpC,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAM,EACDH,GAAK,EACT,OAAOG,EAER,GAAKH,IAAM,GAAKE,IAAW,EAC1B,OAAKJ,EAAOG,EAAG,CAAE,CAAE,EACXE,EAEDF,EAAG,CAAE,EAOb,IALKC,EAAS,EACbE,GAAM,EAAEJ,GAAKE,EAEbE,EAAK,EAEAC,EAAI,EAAGA,EAAIL,EAAGK,IACdP,EAAOG,EAAGG,CAAG,CAAE,IAAM,KACzBD,GAAOF,EAAGG,CAAG,GAEdA,GAAMF,EAEP,OAAOC,CACR,CAKAN,EAAO,QAAUE,IC5EjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAQ,QAAS,iCAAkC,EAsBvD,SAASC,EAAaC,EAAGC,EAAGC,EAAQC,EAAS,CAC5C,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAM,EACDJ,GAAK,EACT,OAAOI,EAER,GAAKJ,IAAM,GAAKE,IAAW,EAC1B,OAAKJ,EAAOG,EAAGE,CAAO,CAAE,EAChBC,EAEDH,EAAGE,CAAO,EAGlB,IADAE,EAAKF,EACCG,EAAI,EAAGA,EAAIN,EAAGM,IACdR,EAAOG,EAAGI,CAAG,CAAE,IAAM,KACzBD,GAAOH,EAAGI,CAAG,GAEdA,GAAMH,EAEP,OAAOE,CACR,CAKAP,EAAO,QAAUE,ICxEjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAc,IACdC,EAAU,IAKdF,EAAaC,EAAa,UAAWC,CAAQ,EAK7CH,EAAO,QAAUE,ICajB,IAAIE,EAAO,QAAS,MAAO,EAAE,KACzBC,EAAa,QAAS,2BAA4B,EAClDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAO,IAKPC,EACAC,EAAMJ,EAAYD,EAAM,UAAW,aAAc,CAAE,EAClDE,EAASG,CAAI,EACjBD,EAAcD,EAEdC,EAAcC,EAMf,OAAO,QAAUD", "names": ["require_dsnansumors", "__commonJSMin", "exports", "module", "isnan", "dsnansumors", "N", "x", "stride", "sum", "ix", "i", "require_ndarray", "__commonJSMin", "exports", "module", "isnan", "dsnansumors", "N", "x", "stride", "offset", "sum", "ix", "i", "require_main", "__commonJSMin", "exports", "module", "setReadOnly", "dsnansumors", "ndarray", "join", "tryRequire", "isError", "main", "dsnansumors", "tmp"] } diff --git a/examples/index.js b/examples/index.js index 49da903..cf55192 100644 --- a/examples/index.js +++ b/examples/index.js @@ -18,22 +18,19 @@ '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' ); +var bernoulli = require( '@stdlib/random-base-bernoulli' ); +var filledarrayBy = require( '@stdlib/array-filled-by' ); var dsnansumors = require( './../lib' ); -var x; -var i; - -x = new Float32Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - if ( randu() < 0.2 ) { - x[ i ] = NaN; - } else { - x[ i ] = round( randu()*100.0 ); +function rand() { + if ( bernoulli( 0.8 ) > 0 ) { + return NaN; } + return discreteUniform( 0, 100 ); } + +var x = filledarrayBy( 10, 'float32', rand ); console.log( x ); var v = dsnansumors( x.length, x, 1 ); diff --git a/include.gypi b/include.gypi index 2fa318f..9212937 100644 --- a/include.gypi +++ b/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, 3 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 1 ); + + napi_value v; + napi_status status = napi_create_double( env, stdlib_strided_dsnansumors( N, X, strideX ), &v ); + assert( status == napi_ok ); + + return v; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) \ No newline at end of file diff --git a/src/addon.cpp b/src/addon.cpp deleted file mode 100644 index 5085410..0000000 --- a/src/addon.cpp +++ /dev/null @@ -1,117 +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/dsnansumors.h" -#include -#include -#include -#include -#include - -/** -* Add-on namespace. -*/ -namespace stdlib_blas_ext_base_dsnansumors { - - /** - * Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using ordinary recursive summation with extended accumulation, and returning an extended precision result. - * - * ## Notes - * - * - When called from JavaScript, the function expects three arguments: - * - * - `N`: number of indexed elements - * - `X`: input array - * - `stride`: stride length - */ - napi_value node_dsnansumors( napi_env env, napi_callback_info info ) { - napi_status status; - - size_t argc = 3; - napi_value argv[ 3 ]; - status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr ); - assert( status == napi_ok ); - - if ( argc < 3 ) { - napi_throw_error( env, nullptr, "invalid invocation. Must provide 3 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; - } - - bool res; - status = napi_is_typedarray( env, argv[ 1 ], &res ); - assert( status == napi_ok ); - if ( res == false ) { - napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a Float32Array." ); - return nullptr; - } - - napi_valuetype vtype2; - status = napi_typeof( env, argv[ 2 ], &vtype2 ); - assert( status == napi_ok ); - if ( vtype2 != napi_number ) { - napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a number." ); - return nullptr; - } - - int64_t N; - status = napi_get_value_int64( env, argv[ 0 ], &N ); - assert( status == napi_ok ); - - int64_t stride; - status = napi_get_value_int64( env, argv[ 2 ], &stride ); - assert( status == napi_ok ); - - napi_typedarray_type vtype1; - size_t xlen; - void *X; - status = napi_get_typedarray_info( env, argv[ 1 ], &vtype1, &xlen, &X, nullptr, nullptr ); - assert( status == napi_ok ); - if ( vtype1 != napi_float32_array ) { - napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a Float32Array." ); - return nullptr; - } - if ( (N-1)*llabs(stride) >= (int64_t)xlen ) { - napi_throw_range_error( env, nullptr, "invalid argument. Second 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_dsnansumors( N, (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_dsnansumors, NULL, &fcn ); - assert( status == napi_ok ); - return fcn; - } - - NAPI_MODULE( NODE_GYP_MODULE_NAME, Init ) -} // end namespace stdlib_blas_ext_base_dsnansumors diff --git a/test/test.dsnansumors.js b/test/test.dsnansumors.js index ed542ac..7e2efb4 100644 --- a/test/test.dsnansumors.js +++ b/test/test.dsnansumors.js @@ -21,7 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math-base-special-floor' ); var Float32Array = require( '@stdlib/array-float32' ); var dsnansumors = require( './../lib/dsnansumors.js' ); @@ -35,7 +34,7 @@ tape( 'main export is a function', function test( t ) { }); tape( 'the function has an arity of 3', function test( t ) { - t.strictEqual( dsnansumors.length, 3, 'has expected arity' ); + t.strictEqual( dsnansumors.length, 3, 'returns expected value' ); t.end(); }); @@ -106,7 +105,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; @@ -123,15 +121,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) { NaN ]); - N = floor( x.length / 2 ); - v = dsnansumors( N, x, 2 ); + v = dsnansumors( 5, x, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { - var N; var x; var v; @@ -148,8 +144,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - N = floor( x.length / 2 ); - v = dsnansumors( N, x, -2 ); + v = dsnansumors( 5, x, -2 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); @@ -170,7 +165,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 = dsnansumors( N, x1, 2 ); + v = dsnansumors( 5, x1, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); diff --git a/test/test.dsnansumors.native.js b/test/test.dsnansumors.native.js index 03c7e4d..cdfdb4b 100644 --- a/test/test.dsnansumors.native.js +++ b/test/test.dsnansumors.native.js @@ -22,7 +22,6 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); -var floor = require( '@stdlib/math-base-special-floor' ); var Float32Array = require( '@stdlib/array-float32' ); var tryRequire = require( '@stdlib/utils-try-require' ); @@ -44,7 +43,7 @@ tape( 'main export is a function', opts, function test( t ) { }); tape( 'the function has an arity of 3', opts, function test( t ) { - t.strictEqual( dsnansumors.length, 3, 'has expected arity' ); + t.strictEqual( dsnansumors.length, 3, 'returns expected value' ); t.end(); }); @@ -197,7 +196,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; @@ -214,15 +212,13 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { NaN ]); - N = floor( x.length / 2 ); - v = dsnansumors( N, x, 2 ); + v = dsnansumors( 5, x, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { - var N; var x; var v; @@ -239,8 +235,7 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - N = floor( x.length / 2 ); - v = dsnansumors( N, x, -2 ); + v = dsnansumors( 5, x, -2 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); @@ -261,7 +256,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([ @@ -279,9 +273,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 = dsnansumors( N, x1, 2 ); + v = dsnansumors( 5, x1, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); diff --git a/test/test.ndarray.js b/test/test.ndarray.js index 8a38c73..92ea7ac 100644 --- a/test/test.ndarray.js +++ b/test/test.ndarray.js @@ -21,7 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math-base-special-floor' ); var Float32Array = require( '@stdlib/array-float32' ); var dsnansumors = require( './../lib/ndarray.js' ); @@ -35,7 +34,7 @@ tape( 'main export is a function', function test( t ) { }); tape( 'the function has an arity of 4', function test( t ) { - t.strictEqual( dsnansumors.length, 4, 'has expected arity' ); + t.strictEqual( dsnansumors.length, 4, 'returns expected value' ); t.end(); }); @@ -106,7 +105,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; @@ -123,15 +121,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) { NaN ]); - N = floor( x.length / 2 ); - v = dsnansumors( N, x, 2, 0 ); + v = dsnansumors( 5, x, 2, 0 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { - var N; var x; var v; @@ -148,8 +144,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - N = floor( x.length / 2 ); - v = dsnansumors( N, x, -2, 8 ); + v = dsnansumors( 5, x, -2, 8 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); @@ -168,7 +163,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 ) { NaN, NaN // 4 ]); - N = floor( x.length / 2 ); - v = dsnansumors( N, x, 2, 1 ); + v = dsnansumors( 5, x, 2, 1 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); diff --git a/test/test.ndarray.native.js b/test/test.ndarray.native.js index e62abac..2c0a057 100644 --- a/test/test.ndarray.native.js +++ b/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 Float32Array = require( '@stdlib/array-float32' ); var tryRequire = require( '@stdlib/utils-try-require' ); @@ -44,7 +43,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( dsnansumors.length, 4, 'has expected arity' ); + t.strictEqual( dsnansumors.length, 4, 'returns expected value' ); t.end(); }); @@ -115,7 +114,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; @@ -132,15 +130,13 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { NaN ]); - N = floor( x.length / 2 ); - v = dsnansumors( N, x, 2, 0 ); + v = dsnansumors( 5, x, 2, 0 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { - var N; var x; var v; @@ -157,8 +153,7 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - N = floor( x.length / 2 ); - v = dsnansumors( N, x, -2, 8 ); + v = dsnansumors( 5, x, -2, 8 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); @@ -177,7 +172,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 ) { NaN, NaN // 4 ]); - N = floor( x.length / 2 ); - v = dsnansumors( N, x, 2, 1 ); + v = dsnansumors( 5, x, 2, 1 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end();