From a5ea0c6a11601650169eecf3b158f8ff3968996d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Oct 2024 22:19:26 +0000 Subject: [PATCH] Auto-generated commit --- .github/.keepalive | 1 - CHANGELOG.md | 45 +++++++++ README.md | 129 ++++++++++++++++++++++-- benchmark/c/benchmark.length.c | 52 +++++++++- dist/index.js | 14 +-- dist/index.js.map | 8 +- docs/repl.txt | 16 +-- docs/types/index.d.ts | 12 +-- examples/c/example.c | 7 +- include/stdlib/blas/ext/base/dnanasum.h | 9 +- lib/dnanasum.js | 9 +- lib/dnanasum.native.js | 6 +- lib/ndarray.js | 8 +- lib/ndarray.native.js | 17 +--- manifest.json | 45 ++++++--- package.json | 5 +- src/addon.c | 30 ++++-- src/dnanasum.c | 33 ------ src/main.c | 48 +++++++++ test/test.dnanasum.js | 4 +- test/test.dnanasum.native.js | 4 +- test/test.ndarray.js | 4 +- test/test.ndarray.native.js | 4 +- 23 files changed, 382 insertions(+), 128 deletions(-) delete mode 100644 .github/.keepalive delete mode 100644 src/dnanasum.c create mode 100644 src/main.c diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 9c4e663..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-10-01T04:36:00.294Z diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a7d01f..b93db3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,51 @@ > Package changelog. +
+ +## Unreleased (2024-10-04) + +
+ +### Features + +- [`ea7b344`](https://github.com/stdlib-js/stdlib/commit/ea7b34499a4847bd917e120595a0c677fe8bddb9) - add C `ndarray` API and refactor `blas/ext/base/dnanasum` [(#2984)](https://github.com/stdlib-js/stdlib/pull/2984) + +
+ + + +
+ +### Commits + +
+ +- [`ea7b344`](https://github.com/stdlib-js/stdlib/commit/ea7b34499a4847bd917e120595a0c677fe8bddb9) - **feat:** add C `ndarray` API and refactor `blas/ext/base/dnanasum` [(#2984)](https://github.com/stdlib-js/stdlib/pull/2984) _(by Muhammad Haris, Athan Reines)_ + +
+ +
+ + + +
+ +### Contributors + +A total of 2 people contributed to this release. Thank you to the following contributors: + +- Athan Reines +- Muhammad Haris + +
+ + + +
+ + +
## 0.2.2 (2024-07-28) diff --git a/README.md b/README.md index a4b2fdf..edfc009 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ To view installation and usage instructions specific to each branch build, be su var dnanasum = require( '@stdlib/blas-ext-base-dnanasum' ); ``` -#### dnanasum( N, x, stride ) +#### dnanasum( N, x, strideX ) Computes the sum of absolute values ([_L1_ norm][l1norm]) of double-precision floating-point strided array elements, ignoring `NaN` values. @@ -102,9 +102,9 @@ The function has the following parameters: - **N**: number of indexed elements. - **x**: input [`Float64Array`][@stdlib/array/float64]. -- **stride**: index increment for `x`. +- **strideX**: index increment for `x`. -The `N` and `stride` parameters determine which elements in the strided array are accessed at runtime. For example, to compute the sum of absolute values ([_L1_ norm][l1norm]) every other element in the strided array, +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the sum of absolute values ([_L1_ norm][l1norm]) for every other element in the strided array, ```javascript var Float64Array = require( '@stdlib/array-float64' ); @@ -129,7 +129,7 @@ var v = dnanasum( 4, x1, 2 ); // returns 9.0 ``` -#### dnanasum.ndarray( N, x, stride, offset ) +#### dnanasum.ndarray( N, x, strideX, offsetX ) Computes the sum of absolute values ([_L1_ norm][l1norm]) of double-precision floating-point strided array elements, ignoring `NaN` values and using alternative indexing semantics. @@ -144,9 +144,9 @@ var v = dnanasum.ndarray( 4, x, 1, 0 ); The function has the following additional parameters: -- **offset**: starting index for `x`. +- **offsetX**: 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 absolute values ([_L1_ norm][l1norm]) every other value in the strided array 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 absolute values ([_L1_ norm][l1norm]) for every other value in the strided array starting from the second value ```javascript var Float64Array = require( '@stdlib/array-float64' ); @@ -202,6 +202,123 @@ console.log( v ); + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/ext/base/dnanasum.h" +``` + +#### stdlib_strided_dnanasum( N, \*X, strideX ) + +Computes the sum of absolute values ([_L1_ norm][l1norm]) of double-precision floating-point strided array elements, ignoring `NaN` values. + +```c +const double x[] = { 1.0, 2.0, 0.0/0.0, 4.0 }; + +double v = stdlib_strided_dnanasum( 4, x, 1 ); +// returns 7.0 +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **X**: `[in] double*` input array. +- **strideX**: `[in] CBLAS_INT` index increment for `X`. + +```c +double stdlib_strided_dnanasum( const CBLAS_INT N, const double *X, const CBLAS_INT strideX ); +``` + +#### stdlib_strided_dnanasum_ndarray( N, \*X, strideX, offsetX ) + +Computes the sum of absolute values ([_L1_ norm][l1norm]) of double-precision floating-point strided array elements, ignoring `NaN` values and using alternative indexing semantics. + +```c +const double x[] = { 1.0, 2.0, 0.0/0.0, 4.0 }; + +double v = stdlib_strided_dnanasum_ndarray( 4, x, 1, 0 ); +// returns 7.0 +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **X**: `[in] double*` input array. +- **strideX**: `[in] CBLAS_INT` index increment for `X`. +- **offsetX**: `[in] CBLAS_INT` starting index for `X`. + +```c +double stdlib_strided_dnanasum_ndarray( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/ext/base/dnanasum.h" +#include + +int main( void ) { + // Create a strided array: + const double x[] = { 1.0, 2.0, -3.0, -4.0, 5.0, -6.0, -7.0, 8.0, 0.0/0.0, 0.0/0.0 }; + + // Specify the number of elements: + const int N = 5; + + // Specify the stride length: + const int strideX = 2; + + // Compute the sum: + double v = stdlib_strided_dnanasum( N, x, strideX ); + + // Print the result: + printf( "sumabs: %lf\n", v ); +} +``` + +
+ + + +
+ + +
diff --git a/benchmark/c/benchmark.length.c b/benchmark/c/benchmark.length.c index 6928051..250c9ea 100644 --- a/benchmark/c/benchmark.length.c +++ b/benchmark/c/benchmark.length.c @@ -94,7 +94,7 @@ static double rand_double( void ) { * @param len array length * @return elapsed time in seconds */ -static double benchmark( int iterations, int len ) { +static double benchmark1( int iterations, int len ) { double elapsed; double x[ len ]; double v; @@ -124,6 +124,43 @@ static double benchmark( int iterations, int len ) { return elapsed; } +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark2( int iterations, int len ) { + double elapsed; + double x[ len ]; + double v; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + if ( rand_double() < 0.2 ) { + x[ i ] = 0.0 / 0.0; // NaN + } else { + x[ i ] = ( rand_double() * 20000.0 ) - 10000.0; + } + } + v = 0.0; + t = tic(); + for ( i = 0; i < iterations; i++ ) { + v = stdlib_strided_dnanasum_ndarray( len, x, 1, 0 ); + if ( v != v ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( v != v ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + /** * Main execution sequence. */ @@ -146,7 +183,18 @@ int main( void ) { for ( j = 0; j < REPEATS; j++ ) { count += 1; printf( "# c::%s:len=%d\n", NAME, len ); - elapsed = benchmark( iter, len ); + elapsed = benchmark1( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } + for ( i = MIN; i <= MAX; i++ ) { + len = pow( 10, i ); + iter = ITERATIONS / pow( 10, i-1 ); + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:ndarray:len=%d\n", NAME, len ); + elapsed = benchmark2( iter, len ); print_results( iter, elapsed ); printf( "ok %d benchmark finished\n", count ); } diff --git a/dist/index.js b/dist/index.js index d5f58fe..5fc514c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,9 +1,9 @@ -"use strict";var n=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var i=n(function(g,u){ -var p=require('@stdlib/blas-ext-base-dnanasumors/dist');function y(e,r,a){return p(e,r,a)}u.exports=y -});var v=n(function(h,t){ -var x=require('@stdlib/blas-ext-base-dnanasumors/dist').ndarray;function f(e,r,a,c){return x(e,r,a,c)}t.exports=f -});var q=n(function(k,o){ -var j=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),d=i(),l=v();j(d,"ndarray",l);o.exports=d -});var R=require("path").join,_=require('@stdlib/utils-try-require/dist'),E=require('@stdlib/assert-is-error/dist'),O=q(),s,m=_(R(__dirname,"./native.js"));E(m)?s=O:s=m;module.exports=s; +"use strict";var n=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var i=n(function(h,s){ +var y=require('@stdlib/blas-ext-base-dnanasumors/dist').ndarray;function f(e,r,a,c){return y(e,r,a,c)}s.exports=f +});var v=n(function(k,t){ +var p=require('@stdlib/strided-base-stride2offset/dist'),x=i();function j(e,r,a){return x(e,r,a,p(e,a))}t.exports=j +});var q=n(function(w,o){ +var l=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),d=v(),R=i();l(d,"ndarray",R);o.exports=d +});var _=require("path").join,E=require('@stdlib/utils-try-require/dist'),O=require('@stdlib/assert-is-error/dist'),b=q(),u,m=E(_(__dirname,"./native.js"));O(m)?u=b:u=m;module.exports=u; /** @license Apache-2.0 */ //# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map index f205a78..a0a2a7e 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1,7 +1,7 @@ { "version": 3, - "sources": ["../lib/dnanasum.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 dnanasumors = require( '@stdlib/blas-ext-base-dnanasumors' );\n\n\n// MAIN //\n\n/**\n* Computes the sum of absolute values (L1 norm) of double-precision floating-point strided array elements, ignoring `NaN` values.\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {Float64Array} x - input array\n* @param {integer} stride - stride length\n* @returns {number} sum\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] );\n*\n* var v = dnanasum( 4, x, 1 );\n* // returns 5.0\n*/\nfunction dnanasum( N, x, stride ) {\n\treturn dnanasumors( N, x, stride );\n}\n\n\n// EXPORTS //\n\nmodule.exports = dnanasum;\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 dnanasumors = require( '@stdlib/blas-ext-base-dnanasumors' ).ndarray;\n\n\n// MAIN //\n\n/**\n* Computes the sum of absolute values (L1 norm) of double-precision floating-point strided array elements, ignoring `NaN` values.\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {Float64Array} x - input array\n* @param {integer} stride - stride length\n* @param {NonNegativeInteger} offset - starting index\n* @returns {number} sum\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var floor = require( '@stdlib/math-base-special-floor' );\n*\n* var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] );\n*\n* var v = dnanasum( 5, x, 2, 1 );\n* // returns 9.0\n*/\nfunction dnanasum( N, x, stride, offset ) {\n\treturn dnanasumors( N, x, stride, offset );\n}\n\n\n// EXPORTS //\n\nmodule.exports = dnanasum;\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 dnanasum = require( './dnanasum.js' );\nvar ndarray = require( './ndarray.js' );\n\n\n// MAIN //\n\nsetReadOnly( dnanasum, 'ndarray', ndarray );\n\n\n// EXPORTS //\n\nmodule.exports = dnanasum;\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 absolute values (L1 norm) of double-precision floating-point strided array elements, ignoring `NaN` values.\n*\n* @module @stdlib/blas-ext-base-dnanasum\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var dnanasum = require( '@stdlib/blas-ext-base-dnanasum' );\n*\n* var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] );\n*\n* var v = dnanasum( 4, x, 1 );\n* // returns 5.0\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var dnanasum = require( '@stdlib/blas-ext-base-dnanasum' );\n*\n* var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] );\n*\n* var v = dnanasum.ndarray( 5, x, 2, 1 );\n* // returns 9.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 dnanasum;\nvar tmp = tryRequire( join( __dirname, './native.js' ) );\nif ( isError( tmp ) ) {\n\tdnanasum = main;\n} else {\n\tdnanasum = tmp;\n}\n\n\n// EXPORTS //\n\nmodule.exports = dnanasum;\n\n// exports: { \"ndarray\": \"dnanasum.ndarray\" }\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,mCAAoC,EAqB/D,SAASC,EAAUC,EAAGC,EAAGC,EAAS,CACjC,OAAOJ,EAAaE,EAAGC,EAAGC,CAAO,CAClC,CAKAL,EAAO,QAAUE,IClDjB,IAAAI,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,mCAAoC,EAAE,QAuBjE,SAASC,EAAUC,EAAGC,EAAGC,EAAQC,EAAS,CACzC,OAAOL,EAAaE,EAAGC,EAAGC,EAAQC,CAAO,CAC1C,CAKAN,EAAO,QAAUE,ICpDjB,IAAAK,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAW,IACXC,EAAU,IAKdF,EAAaC,EAAU,UAAWC,CAAQ,EAK1CH,EAAO,QAAUE,ICYjB,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,EAAWD,EAEXC,EAAWC,EAMZ,OAAO,QAAUD", - "names": ["require_dnanasum", "__commonJSMin", "exports", "module", "dnanasumors", "dnanasum", "N", "x", "stride", "require_ndarray", "__commonJSMin", "exports", "module", "dnanasumors", "dnanasum", "N", "x", "stride", "offset", "require_main", "__commonJSMin", "exports", "module", "setReadOnly", "dnanasum", "ndarray", "join", "tryRequire", "isError", "main", "dnanasum", "tmp"] + "sources": ["../lib/ndarray.js", "../lib/dnanasum.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 dnanasumors = require( '@stdlib/blas-ext-base-dnanasumors' ).ndarray;\n\n\n// MAIN //\n\n/**\n* Computes the sum of absolute values (L1 norm) of double-precision floating-point strided array elements, ignoring `NaN` values.\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {Float64Array} x - input array\n* @param {integer} strideX - index increment\n* @param {NonNegativeInteger} offsetX - starting index\n* @returns {number} sum\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var floor = require( '@stdlib/math-base-special-floor' );\n*\n* var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] );\n*\n* var v = dnanasum( 5, x, 2, 1 );\n* // returns 9.0\n*/\nfunction dnanasum( N, x, strideX, offsetX ) {\n\treturn dnanasumors( N, x, strideX, offsetX );\n}\n\n\n// EXPORTS //\n\nmodule.exports = dnanasum;\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 stride2offset = require( '@stdlib/strided-base-stride2offset' );\nvar ndarray = require( './ndarray.js' );\n\n\n// MAIN //\n\n/**\n* Computes the sum of absolute values (L1 norm) of double-precision floating-point strided array elements, ignoring `NaN` values.\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {Float64Array} x - input array\n* @param {integer} strideX - stride length\n* @returns {number} sum\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] );\n*\n* var v = dnanasum( 4, x, 1 );\n* // returns 5.0\n*/\nfunction dnanasum( N, x, strideX ) {\n\treturn ndarray( N, x, strideX, stride2offset( N, strideX ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = dnanasum;\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 dnanasum = require( './dnanasum.js' );\nvar ndarray = require( './ndarray.js' );\n\n\n// MAIN //\n\nsetReadOnly( dnanasum, 'ndarray', ndarray );\n\n\n// EXPORTS //\n\nmodule.exports = dnanasum;\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 absolute values (L1 norm) of double-precision floating-point strided array elements, ignoring `NaN` values.\n*\n* @module @stdlib/blas-ext-base-dnanasum\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var dnanasum = require( '@stdlib/blas-ext-base-dnanasum' );\n*\n* var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] );\n*\n* var v = dnanasum( 4, x, 1 );\n* // returns 5.0\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var dnanasum = require( '@stdlib/blas-ext-base-dnanasum' );\n*\n* var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] );\n*\n* var v = dnanasum.ndarray( 5, x, 2, 1 );\n* // returns 9.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 dnanasum;\nvar tmp = tryRequire( join( __dirname, './native.js' ) );\nif ( isError( tmp ) ) {\n\tdnanasum = main;\n} else {\n\tdnanasum = tmp;\n}\n\n\n// EXPORTS //\n\nmodule.exports = dnanasum;\n\n// exports: { \"ndarray\": \"dnanasum.ndarray\" }\n"], + "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,mCAAoC,EAAE,QAuBjE,SAASC,EAAUC,EAAGC,EAAGC,EAASC,EAAU,CAC3C,OAAOL,EAAaE,EAAGC,EAAGC,EAASC,CAAQ,CAC5C,CAKAN,EAAO,QAAUE,ICpDjB,IAAAK,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,oCAAqC,EAC9DC,EAAU,IAqBd,SAASC,EAAUC,EAAGC,EAAGC,EAAU,CAClC,OAAOJ,EAASE,EAAGC,EAAGC,EAASL,EAAeG,EAAGE,CAAQ,CAAE,CAC5D,CAKAN,EAAO,QAAUG,ICnDjB,IAAAI,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAW,IACXC,EAAU,IAKdF,EAAaC,EAAU,UAAWC,CAAQ,EAK1CH,EAAO,QAAUE,ICYjB,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,EAAWD,EAEXC,EAAWC,EAMZ,OAAO,QAAUD", + "names": ["require_ndarray", "__commonJSMin", "exports", "module", "dnanasumors", "dnanasum", "N", "x", "strideX", "offsetX", "require_dnanasum", "__commonJSMin", "exports", "module", "stride2offset", "ndarray", "dnanasum", "N", "x", "strideX", "require_main", "__commonJSMin", "exports", "module", "setReadOnly", "dnanasum", "ndarray", "join", "tryRequire", "isError", "main", "dnanasum", "tmp"] } diff --git a/docs/repl.txt b/docs/repl.txt index 5af6fed..b9507af 100644 --- a/docs/repl.txt +++ b/docs/repl.txt @@ -1,9 +1,9 @@ -{{alias}}( N, x, stride ) +{{alias}}( N, x, strideX ) Computes the sum of absolute values (L1 norm) of double-precision floating- point strided array elements, ignoring `NaN` values. - The `N` and `stride` parameters determine which elements in the strided + 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 @@ -19,7 +19,7 @@ x: Float64Array Input array. - stride: integer + strideX: integer Index increment. Returns @@ -46,14 +46,14 @@ 5.0 -{{alias}}.ndarray( N, x, stride, offset ) +{{alias}}.ndarray( N, x, strideX, offsetX ) Computes the sum of absolute values (L1 norm) of double-precision floating- point strided array elements, ignoring `NaN` values and using alternative indexing semantics. While typed array views mandate a view offset based on the underlying - buffer, the `offset` parameter supports indexing semantics based on a - starting index. + buffer, the offset parameter supports indexing semantics based on a starting + index. Parameters ---------- @@ -63,10 +63,10 @@ x: Float64Array Input array. - stride: integer + strideX: integer Index increment. - offset: integer + offsetX: integer Starting index. Returns diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts index 0ea81b8..2a35cae 100644 --- a/docs/types/index.d.ts +++ b/docs/types/index.d.ts @@ -27,7 +27,7 @@ interface Routine { * * @param N - number of indexed elements * @param x - input array - * @param stride - stride length + * @param strideX - stride length * @returns sum * * @example @@ -38,15 +38,15 @@ interface Routine { * var v = dnanasum( x.length, x, 1 ); * // returns 5.0 */ - ( N: number, x: Float64Array, stride: number ): number; + ( N: number, x: Float64Array, strideX: number ): number; /** * Computes the sum of absolute values (L1 norm) of double-precision floating-point strided array elements, ignoring `NaN` values and using alternative indexing semantics. * * @param N - number of indexed elements * @param x - input array - * @param stride - stride length - * @param offset - starting index + * @param strideX - stride length + * @param offsetX - starting index * @returns sum * * @example @@ -57,7 +57,7 @@ interface Routine { * var v = dnanasum.ndarray( x.length, x, 1, 0 ); * // returns 5.0 */ - ndarray( N: number, x: Float64Array, stride: number, offset: number ): number; + ndarray( N: number, x: Float64Array, strideX: number, offsetX: number ): number; } /** @@ -65,7 +65,7 @@ interface Routine { * * @param N - number of indexed elements * @param x - input array -* @param stride - stride length +* @param strideX - stride length * @returns sum * * @example diff --git a/examples/c/example.c b/examples/c/example.c index 670d0fc..b2d8620 100644 --- a/examples/c/example.c +++ b/examples/c/example.c @@ -17,7 +17,6 @@ */ #include "stdlib/blas/ext/base/dnanasum.h" -#include #include int main( void ) { @@ -25,13 +24,13 @@ int main( void ) { const double x[] = { 1.0, 2.0, -3.0, -4.0, 5.0, -6.0, -7.0, 8.0, 0.0/0.0, 0.0/0.0 }; // Specify the number of elements: - const int64_t N = 5; + const int N = 5; // Specify the stride length: - const int64_t stride = 2; + const int strideX = 2; // Compute the sum: - double v = stdlib_strided_dnanasum( N, x, stride ); + double v = stdlib_strided_dnanasum( N, x, strideX ); // Print the result: printf( "sumabs: %lf\n", v ); diff --git a/include/stdlib/blas/ext/base/dnanasum.h b/include/stdlib/blas/ext/base/dnanasum.h index d4ddb16..7972855 100644 --- a/include/stdlib/blas/ext/base/dnanasum.h +++ b/include/stdlib/blas/ext/base/dnanasum.h @@ -19,7 +19,7 @@ #ifndef STDLIB_BLAS_EXT_BASE_DNANASUM_H #define STDLIB_BLAS_EXT_BASE_DNANASUM_H -#include +#include "stdlib/blas/base/shared.h" /* * If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. @@ -31,7 +31,12 @@ extern "C" { /** * Computes the sum of absolute values (L1 norm) of double-precision floating-point strided array elements, ignoring `NaN` values. */ -double stdlib_strided_dnanasum( const int64_t N, const double *X, const int64_t stride ); +double API_SUFFIX(stdlib_strided_dnanasum)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX ); + +/** +* Computes the sum of absolute values (L1 norm) of double-precision floating-point strided array elements, ignoring `NaN` values and using alternative indexing semantics. +*/ +double API_SUFFIX(stdlib_strided_dnanasum_ndarray)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); #ifdef __cplusplus } diff --git a/lib/dnanasum.js b/lib/dnanasum.js index 17b8626..563b28d 100644 --- a/lib/dnanasum.js +++ b/lib/dnanasum.js @@ -20,7 +20,8 @@ // MODULES // -var dnanasumors = require( '@stdlib/blas-ext-base-dnanasumors' ); +var stride2offset = require( '@stdlib/strided-base-stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // @@ -30,7 +31,7 @@ var dnanasumors = require( '@stdlib/blas-ext-base-dnanasumors' ); * * @param {PositiveInteger} N - number of indexed elements * @param {Float64Array} x - input array -* @param {integer} stride - stride length +* @param {integer} strideX - stride length * @returns {number} sum * * @example @@ -41,8 +42,8 @@ var dnanasumors = require( '@stdlib/blas-ext-base-dnanasumors' ); * var v = dnanasum( 4, x, 1 ); * // returns 5.0 */ -function dnanasum( N, x, stride ) { - return dnanasumors( N, x, stride ); +function dnanasum( N, x, strideX ) { + return ndarray( N, x, strideX, stride2offset( N, strideX ) ); } diff --git a/lib/dnanasum.native.js b/lib/dnanasum.native.js index c8e4f86..fde21bb 100644 --- a/lib/dnanasum.native.js +++ b/lib/dnanasum.native.js @@ -30,7 +30,7 @@ var addon = require( './../src/addon.node' ); * * @param {PositiveInteger} N - number of indexed elements * @param {Float64Array} x - input array -* @param {integer} stride - stride length +* @param {integer} strideX - stride length * @returns {number} sum * * @example @@ -41,8 +41,8 @@ var addon = require( './../src/addon.node' ); * var v = dnanasum( 4, x, 1 ); * // returns 5.0 */ -function dnanasum( N, x, stride ) { - return addon( N, x, stride ); +function dnanasum( N, x, strideX ) { + return addon( N, x, strideX ); } diff --git a/lib/ndarray.js b/lib/ndarray.js index 0536a51..ee27d99 100644 --- a/lib/ndarray.js +++ b/lib/ndarray.js @@ -30,8 +30,8 @@ var dnanasumors = require( '@stdlib/blas-ext-base-dnanasumors' ).ndarray; * * @param {PositiveInteger} N - number of indexed elements * @param {Float64Array} x - input array -* @param {integer} stride - stride length -* @param {NonNegativeInteger} offset - starting index +* @param {integer} strideX - index increment +* @param {NonNegativeInteger} offsetX - starting index * @returns {number} sum * * @example @@ -43,8 +43,8 @@ var dnanasumors = require( '@stdlib/blas-ext-base-dnanasumors' ).ndarray; * var v = dnanasum( 5, x, 2, 1 ); * // returns 9.0 */ -function dnanasum( N, x, stride, offset ) { - return dnanasumors( N, x, stride, offset ); +function dnanasum( N, x, strideX, offsetX ) { + return dnanasumors( N, x, strideX, offsetX ); } diff --git a/lib/ndarray.native.js b/lib/ndarray.native.js index 4e0e809..653c365 100644 --- a/lib/ndarray.native.js +++ b/lib/ndarray.native.js @@ -20,9 +20,7 @@ // MODULES // -var minViewBufferIndex = require( '@stdlib/strided-base-min-view-buffer-index' ); -var offsetView = require( '@stdlib/strided-base-offset-view' ); -var addon = require( './dnanasum.native.js' ); +var addon = require( './../src/addon.node' ); // MAIN // @@ -32,8 +30,8 @@ var addon = require( './dnanasum.native.js' ); * * @param {PositiveInteger} N - number of indexed elements * @param {Float64Array} x - input array -* @param {integer} stride - stride length -* @param {NonNegativeInteger} offset - starting index +* @param {integer} strideX - index increment +* @param {NonNegativeInteger} offsetX - starting index * @returns {number} sum * * @example @@ -44,13 +42,8 @@ var addon = require( './dnanasum.native.js' ); * var v = dnanasum( 5, x, 2, 1 ); * // returns 9.0 */ -function dnanasum( N, x, stride, offset ) { - var view; - - offset = minViewBufferIndex( N, stride, offset ); - view = offsetView( x, offset ); - - return addon( N, view, stride ); +function dnanasum( N, x, strideX, offsetX ) { + return addon.ndarray( N, x, strideX, offsetX ); } diff --git a/manifest.json b/manifest.json index 6f4bd1e..e2c3897 100644 --- a/manifest.json +++ b/manifest.json @@ -28,53 +28,70 @@ { "task": "build", "src": [ - "./src/dnanasum.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], "dependencies": [ "@stdlib/napi-export", "@stdlib/napi-argv", "@stdlib/napi-argv-int64", "@stdlib/napi-argv-strided-float64array", - "@stdlib/blas-ext-base-dnanasumors" + "@stdlib/blas-ext-base-dnanasumors", + "@stdlib/blas-base-shared", + "@stdlib/strided-base-stride2offset", + "@stdlib/napi-create-double" ] }, { "task": "benchmark", "src": [ - "./src/dnanasum.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas-ext-base-dnanasumors", + "@stdlib/blas-base-shared", + "@stdlib/strided-base-stride2offset" + ] + }, + { + "task": "examples", + "src": [ + "./src/main.c" ], + "include": [ + "./include" + ], + "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas-ext-base-dnanasumors" + "@stdlib/blas-ext-base-dnanasumors", + "@stdlib/blas-base-shared", + "@stdlib/strided-base-stride2offset" ] }, { "task": "test", "src": [ - "./src/dnanasum.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas-ext-base-dnanasumors" + "@stdlib/blas-ext-base-dnanasumors", + "@stdlib/blas-base-shared", + "@stdlib/strided-base-stride2offset" ] } ] diff --git a/package.json b/package.json index 280cde7..5d7f6cc 100644 --- a/package.json +++ b/package.json @@ -42,11 +42,14 @@ }, "dependencies": { "@stdlib/assert-is-error": "^0.2.2", + "@stdlib/blas-base-shared": "^0.1.0", "@stdlib/blas-ext-base-dnanasumors": "^0.2.2", "@stdlib/napi-argv": "^0.2.2", "@stdlib/napi-argv-int64": "^0.2.2", "@stdlib/napi-argv-strided-float64array": "^0.2.2", + "@stdlib/napi-create-double": "^0.0.2", "@stdlib/napi-export": "^0.2.2", + "@stdlib/strided-base-stride2offset": "^0.1.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", "@stdlib/utils-library-manifest": "^0.2.2", "@stdlib/utils-try-require": "^0.2.2" @@ -60,8 +63,6 @@ "@stdlib/random-base-bernoulli": "^0.2.1", "@stdlib/random-base-discrete-uniform": "^0.2.1", "@stdlib/random-base-uniform": "^0.2.1", - "@stdlib/strided-base-min-view-buffer-index": "^0.2.2", - "@stdlib/strided-base-offset-view": "^0.2.2", "proxyquire": "^2.0.0", "tape": "git+https://github.com/kgryte/tape.git#fix/globby", "istanbul": "^0.4.1", diff --git a/src/addon.c b/src/addon.c index 5c9a07a..765e9fd 100644 --- a/src/addon.c +++ b/src/addon.c @@ -17,12 +17,13 @@ */ #include "stdlib/blas/ext/base/dnanasum.h" +#include "stdlib/blas/base/shared.h" #include "stdlib/napi/export.h" #include "stdlib/napi/argv.h" #include "stdlib/napi/argv_int64.h" #include "stdlib/napi/argv_strided_float64array.h" +#include "stdlib/napi/create_double.h" #include -#include /** * Receives JavaScript callback invocation data. @@ -34,14 +35,27 @@ 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, stride, argv, 2 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, stride, argv, 1 ); - - napi_value v; - napi_status status = napi_create_double( env, stdlib_strided_dnanasum( N, X, stride ), &v ); - assert( status == napi_ok ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 1 ); + STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(stdlib_strided_dnanasum)( N, X, strideX ), v ); + return v; +} +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon_method( 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_INT64( env, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 3 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 1 ); + STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(stdlib_strided_dnanasum_ndarray)( N, X, strideX, offsetX ), v ); return v; } -STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/src/dnanasum.c b/src/dnanasum.c deleted file mode 100644 index 88b7ba6..0000000 --- a/src/dnanasum.c +++ /dev/null @@ -1,33 +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/dnanasum.h" -#include "stdlib/blas/ext/base/dnanasumors.h" -#include - -/** -* Computes the sum of absolute values (L1 norm) of double-precision floating-point strided array elements, ignoring `NaN` values. -* -* @param N number of indexed elements -* @param X input array -* @param stride stride length -* @return output value -*/ -double stdlib_strided_dnanasum( const int64_t N, const double *X, const int64_t stride ) { - return stdlib_strided_dnanasumors( N, X, stride ); -} diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..43ee9d0 --- /dev/null +++ b/src/main.c @@ -0,0 +1,48 @@ +/** +* @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/dnanasum.h" +#include "stdlib/blas/ext/base/dnanasumors.h" +#include "stdlib/strided/base/stride2offset.h" +#include "stdlib/blas/base/shared.h" + +/** +* Computes the sum of absolute values (L1 norm) of double-precision floating-point strided array elements, ignoring `NaN` values. +* +* @param N number of indexed elements +* @param X input array +* @param strideX stride length +* @return output value +*/ +double API_SUFFIX(stdlib_strided_dnanasum)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX ) { + CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + return API_SUFFIX(stdlib_strided_dnanasum_ndarray)( N, X, strideX, ox ); +} + +/** +* Computes the sum of absolute values (L1 norm) of double-precision floating-point strided array elements, ignoring `NaN` values and using alternative indexing semantics. +* +* @param N number of indexed elements +* @param X input array +* @param strideX index increment +* @param offsetX starting index +* @return output value +*/ +double API_SUFFIX(stdlib_strided_dnanasum_ndarray)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { + return API_SUFFIX(stdlib_strided_dnanasumors_ndarray)( N, X, strideX, offsetX ); +} diff --git a/test/test.dnanasum.js b/test/test.dnanasum.js index 1568081..3aa844b 100644 --- a/test/test.dnanasum.js +++ b/test/test.dnanasum.js @@ -150,14 +150,14 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) t.end(); }); -tape( 'if provided a `stride` parameter equal to `0`, the function returns the first element', function test( t ) { +tape( 'if provided a `stride` parameter equal to `0`, the function returns the sum of the first element repeated N times', function test( t ) { var x; var v; x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); v = dnanasum( x.length, x, 0 ); - t.strictEqual( v, 1.0, 'returns expected value' ); + t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); diff --git a/test/test.dnanasum.native.js b/test/test.dnanasum.native.js index e85fd0e..1bde1de 100644 --- a/test/test.dnanasum.native.js +++ b/test/test.dnanasum.native.js @@ -241,14 +241,14 @@ tape( 'the function supports a negative `stride` parameter', opts, function test t.end(); }); -tape( 'if provided a `stride` parameter equal to `0`, the function returns the first element', opts, function test( t ) { +tape( 'if provided a `stride` parameter equal to `0`, the function returns the sum of the first element repeated N times', opts, function test( t ) { var x; var v; x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); v = dnanasum( x.length, x, 0 ); - t.strictEqual( v, 1.0, 'returns expected value' ); + t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); diff --git a/test/test.ndarray.js b/test/test.ndarray.js index 622a190..c686183 100644 --- a/test/test.ndarray.js +++ b/test/test.ndarray.js @@ -150,14 +150,14 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) t.end(); }); -tape( 'if provided a `stride` parameter equal to `0`, the function returns the first indexed element', function test( t ) { +tape( 'if provided a `stride` parameter equal to `0`, the function returns the sum of the first element repeated N times', function test( t ) { var x; var v; x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); v = dnanasum( x.length, x, 0, 0 ); - t.strictEqual( v, 1.0, 'returns expected value' ); + 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 16499c9..9789ab7 100644 --- a/test/test.ndarray.native.js +++ b/test/test.ndarray.native.js @@ -159,14 +159,14 @@ tape( 'the function supports a negative `stride` parameter', opts, function test t.end(); }); -tape( 'if provided a `stride` parameter equal to `0`, the function returns the first indexed element', opts, function test( t ) { +tape( 'if provided a `stride` parameter equal to `0`, the function returns the sum of the first element repeated N times', opts, function test( t ) { var x; var v; x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); v = dnanasum( x.length, x, 0, 0 ); - t.strictEqual( v, 1.0, 'returns expected value' ); + t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); });