From 735deeabd653ffec0526945edd57d3f6d0a838ba Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Dec 2023 14:35:35 +0000 Subject: [PATCH] Auto-generated commit --- README.md | 41 ++-- benchmark/benchmark.js | 21 +- benchmark/benchmark.native.js | 17 +- benchmark/benchmark.ndarray.js | 21 +- benchmark/benchmark.ndarray.native.js | 17 +- dist/index.js.map | 2 +- docs/repl.txt | 26 +-- docs/types/index.d.ts | 6 +- examples/index.js | 22 +- include.gypi | 2 +- lib/dsdot.js | 2 +- lib/dsdot.native.js | 2 +- lib/ndarray.js | 2 +- lib/ndarray.native.js | 20 +- manifest.json | 287 +++++++++++++++----------- package.json | 14 +- src/addon.c | 50 +++++ src/addon.cpp | 153 -------------- src/dsdot.c | 2 +- src/dsdot.f | 2 +- src/dsdot_cblas.c | 2 +- src/dsdot_f.c | 2 +- test/test.dsdot.js | 2 +- test/test.dsdot.native.js | 2 +- test/test.js | 4 +- test/test.ndarray.js | 2 +- test/test.ndarray.native.js | 2 +- 27 files changed, 317 insertions(+), 408 deletions(-) create mode 100644 src/addon.c delete mode 100644 src/addon.cpp diff --git a/README.md b/README.md index 46410a9..5233255 100644 --- a/README.md +++ b/README.md @@ -104,18 +104,15 @@ The function has the following parameters: - **y**: input [`Float32Array`][@stdlib/array/float32]. - **strideY**: index increment for `y`. -The `N` and `stride` parameters determine which elements in `x` and `y` are accessed at runtime. For example, to calculate the dot product of every other value in `x` and the first `N` elements of `y` in reverse order, +The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to calculate the dot product of every other value in `x` and the first `N` elements of `y` in reverse order, ```javascript var Float32Array = require( '@stdlib/array-float32' ); -var floor = require( '@stdlib/math-base-special-floor' ); var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); var y = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); -var N = floor( x.length / 2 ); - -var z = dsdot( N, x, 2, y, -1 ); +var z = dsdot( 3, x, 2, y, -1 ); // returns 9.0 ``` @@ -125,7 +122,6 @@ 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' ); // Initial arrays... var x0 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); @@ -135,9 +131,7 @@ var y0 = new Float32Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element var y1 = new Float32Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // start at 4th element -var N = floor( x0.length / 2 ); - -var z = dsdot( N, x1, -2, y1, 1 ); +var z = dsdot( 3, x1, -2, y1, 1 ); // returns 128.0 ``` @@ -160,18 +154,15 @@ The function has the following additional parameters: - **offsetX**: starting index for `x`. - **offsetY**: starting index for `y`. -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offsetX` and `offsetY` parameters support indexing semantics based on starting indices. For example, to calculate the dot product of every other value in `x` starting from the second value with the last 3 elements in `y` in reverse order +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example, to calculate the dot product of every other value in `x` starting from the second value with the last 3 elements in `y` in reverse order ```javascript var Float32Array = require( '@stdlib/array-float32' ); -var floor = require( '@stdlib/math-base-special-floor' ); var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); var y = new Float32Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); -var N = floor( x.length / 2 ); - -var z = dsdot.ndarray( N, x, 2, 1, y, -1, y.length-1 ); +var z = dsdot.ndarray( 3, x, 2, 1, y, -1, y.length-1 ); // returns 128.0 ``` @@ -197,26 +188,18 @@ var z = dsdot.ndarray( N, x, 2, 1, y, -1, y.length-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 dsdot = require( '@stdlib/blas-base-dsdot' ); -var x; -var y; -var i; - -x = new Float32Array( 10 ); -y = new Float32Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( randu() * 100.0 ); - y[ i ] = round( randu() * 10.0 ); -} +var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) ); console.log( x ); + +var y = filledarrayBy( x.length, 'float32', discreteUniform( 0, 10 ) ); console.log( y ); -var z = dsdot( x.length, x, 1, y, -1 ); -console.log( z ); +var out = dsdot.ndarray( x.length, x, 1, 0, y, -1, y.length-1 ); +console.log( out ); ``` diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js index ba8358d..e5f9c23 100644 --- a/benchmark/benchmark.js +++ b/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 dsdot = require( './../lib/dsdot.js' ); +// VARIABLES // + +var rand = uniform( -100.0, 100.0 ); + + // FUNCTIONS // /** @@ -39,16 +44,8 @@ var dsdot = require( './../lib/dsdot.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var y; - var i; - - x = new Float32Array( len ); - y = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - y[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = filledarrayBy( len, 'float32', rand ); + var y = filledarrayBy( len, 'float32', rand ); return benchmark; function benchmark( b ) { diff --git a/benchmark/benchmark.native.js b/benchmark/benchmark.native.js index 00e85d6..13a48e8 100644 --- a/benchmark/benchmark.native.js +++ b/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 dsdot = tryRequire( resolve( __dirname, './../lib/dsdot.native.js' ) ); var opts = { 'skip': ( dsdot instanceof Error ) }; +var rand = uniform( -100.0, 100.0 ); // FUNCTIONS // @@ -48,16 +49,8 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var y; - var i; - - x = new Float32Array( len ); - y = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - y[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = filledarrayBy( len, 'float32', rand ); + var y = filledarrayBy( len, 'float32', rand ); return benchmark; function benchmark( b ) { diff --git a/benchmark/benchmark.ndarray.js b/benchmark/benchmark.ndarray.js index e4be118..0e277ec 100644 --- a/benchmark/benchmark.ndarray.js +++ b/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 dsdot = require( './../lib/ndarray.js' ); +// VARIABLES // + +var rand = uniform( -100.0, 100.0 ); + + // FUNCTIONS // /** @@ -39,16 +44,8 @@ var dsdot = require( './../lib/ndarray.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var y; - var i; - - x = new Float32Array( len ); - y = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - y[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = filledarrayBy( len, 'float32', rand ); + var y = filledarrayBy( len, 'float32', rand ); return benchmark; function benchmark( b ) { diff --git a/benchmark/benchmark.ndarray.native.js b/benchmark/benchmark.ndarray.native.js index 8eee1e4..4adf594 100644 --- a/benchmark/benchmark.ndarray.native.js +++ b/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 dsdot = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); var opts = { 'skip': ( dsdot instanceof Error ) }; +var rand = uniform( -100.0, 100.0 ); // FUNCTIONS // @@ -48,16 +49,8 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var y; - var i; - - x = new Float32Array( len ); - y = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - y[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = filledarrayBy( len, 'float32', rand ); + var y = filledarrayBy( len, 'float32', rand ); return benchmark; function benchmark( b ) { diff --git a/dist/index.js.map b/dist/index.js.map index ac1f46c..e3f6bf4 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1,7 +1,7 @@ { "version": 3, "sources": ["../lib/dsdot.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// VARIABLES //\n\nvar M = 5;\n\n\n// MAIN //\n\n/**\n* Computes the dot product of `x` and `y` with extended accumulation and result.\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {Float32Array} x - first input array\n* @param {integer} strideX - `x` stride length\n* @param {Float32Array} y - second input array\n* @param {integer} strideY - `y` stride length\n* @returns {number} dot product of `x` and `y`\n*\n* @example\n* var Float32Array = require( '@stdlib/array-float32' );\n*\n* var x = new Float32Array( [ 4.0, 2.0, -3.0, 5.0, -1.0 ] );\n* var y = new Float32Array( [ 2.0, 6.0, -1.0, -4.0, 8.0 ] );\n*\n* var z = dsdot( x.length, x, 1, y, 1 );\n* // returns -5.0\n*/\nfunction dsdot( N, x, strideX, y, strideY ) {\n\tvar dot;\n\tvar ix;\n\tvar iy;\n\tvar m;\n\tvar i;\n\n\tdot = 0.0;\n\tif ( N <= 0 ) {\n\t\treturn dot;\n\t}\n\t// Use unrolled loops if both strides are equal to `1`...\n\tif ( strideX === 1 && strideY === 1 ) {\n\t\tm = N % M;\n\n\t\t// If we have a remainder, run a clean-up loop...\n\t\tif ( m > 0 ) {\n\t\t\tfor ( i = 0; i < m; i++ ) {\n\t\t\t\tdot += x[ i ] * y[ i ];\n\t\t\t}\n\t\t}\n\t\tif ( N < M ) {\n\t\t\treturn dot;\n\t\t}\n\t\tfor ( i = m; i < N; i += M ) {\n\t\t\tdot += ( x[i]*y[i] ) + ( x[i+1]*y[i+1] ) + ( x[i+2]*y[i+2] ) + ( x[i+3]*y[i+3] ) + ( x[i+4]*y[i+4] ); // eslint-disable-line max-len\n\t\t}\n\t\treturn dot;\n\t}\n\tif ( strideX < 0 ) {\n\t\tix = ( 1-N ) * strideX;\n\t} else {\n\t\tix = 0;\n\t}\n\tif ( strideY < 0 ) {\n\t\tiy = ( 1-N ) * strideY;\n\t} else {\n\t\tiy = 0;\n\t}\n\tfor ( i = 0; i < N; i++ ) {\n\t\tdot += x[ ix ] * y[ iy ];\n\t\tix += strideX;\n\t\tiy += strideY;\n\t}\n\treturn dot;\n}\n\n\n// EXPORTS //\n\nmodule.exports = dsdot;\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// VARIABLES //\n\nvar M = 5;\n\n\n// MAIN //\n\n/**\n* Computes the dot product of `x` and `y` with extended accumulation and result.\n*\n* @param {integer} N - number of indexed elements\n* @param {Float32Array} x - first input array\n* @param {integer} strideX - `x` stride length\n* @param {NonNegativeInteger} offsetX - starting index for `x`\n* @param {Float32Array} y - second input array\n* @param {integer} strideY - `y` stride length\n* @param {NonNegativeInteger} offsetY - starting index for `y`\n* @returns {number} dot product of `x` and `y`\n*\n* @example\n* var Float32Array = require( '@stdlib/array-float32' );\n*\n* var x = new Float32Array( [ 4.0, 2.0, -3.0, 5.0, -1.0 ] );\n* var y = new Float32Array( [ 2.0, 6.0, -1.0, -4.0, 8.0 ] );\n*\n* var z = dsdot( x.length, x, 1, 0, y, 1, 0 );\n* // returns -5.0\n*/\nfunction dsdot( N, x, strideX, offsetX, y, strideY, offsetY ) {\n\tvar dot;\n\tvar ix;\n\tvar iy;\n\tvar m;\n\tvar i;\n\n\tdot = 0.0;\n\tif ( N <= 0 ) {\n\t\treturn dot;\n\t}\n\tix = offsetX;\n\tiy = offsetY;\n\n\t// Use unrolled loops if both strides are equal to `1`...\n\tif ( strideX === 1 && strideY === 1 ) {\n\t\tm = N % M;\n\n\t\t// If we have a remainder, run a clean-up loop...\n\t\tif ( m > 0 ) {\n\t\t\tfor ( i = 0; i < m; i++ ) {\n\t\t\t\tdot += x[ ix ] * y[ iy ];\n\t\t\t\tix += 1;\n\t\t\t\tiy += 1;\n\t\t\t}\n\t\t}\n\t\tif ( N < M ) {\n\t\t\treturn dot;\n\t\t}\n\t\tfor ( i = m; i < N; i += M ) {\n\t\t\tdot += ( x[ix]*y[iy] ) + ( x[ix+1]*y[iy+1] ) + ( x[ix+2]*y[iy+2] ) + ( x[ix+3]*y[iy+3] ) + ( x[ix+4]*y[iy+4] ); // eslint-disable-line max-len\n\t\t\tix += M;\n\t\t\tiy += M;\n\t\t}\n\t\treturn dot;\n\t}\n\tfor ( i = 0; i < N; i++ ) {\n\t\tdot += x[ ix ] * y[ iy ];\n\t\tix += strideX;\n\t\tiy += strideY;\n\t}\n\treturn dot;\n}\n\n\n// EXPORTS //\n\nmodule.exports = dsdot;\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 dsdot = require( './dsdot.js' );\nvar ndarray = require( './ndarray.js' );\n\n\n// MAIN //\n\nsetReadOnly( dsdot, 'ndarray', ndarray );\n\n\n// EXPORTS //\n\nmodule.exports = dsdot;\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* BLAS level 1 routine to compute the dot product of vectors `x` and `y` with extended accumulation and result.\n*\n* @module @stdlib/blas-base-dsdot\n*\n* @example\n* var Float32Array = require( '@stdlib/array-float32' );\n* var dsdot = require( '@stdlib/blas-base-dsdot' );\n*\n* var x = new Float32Array( [ 4.0, 2.0, -3.0, 5.0, -1.0 ] );\n* var y = new Float32Array( [ 2.0, 6.0, -1.0, -4.0, 8.0 ] );\n*\n* var z = dsdot( x.length, x, 1, y, 1 );\n* // returns -12.0\n*\n* @example\n* var Float32Array = require( '@stdlib/array-float32' );\n* var dsdot = require( '@stdlib/blas-base-dsdot' );\n*\n* var x = new Float32Array( [ 4.0, 2.0, -3.0, 5.0, -1.0 ] );\n* var y = new Float32Array( [ 2.0, 6.0, -1.0, -4.0, 8.0 ] );\n*\n* var z = dsdot.ndarray( x.length, x, 1, 0, y, 1, 0 );\n* // returns -12.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 dsdot;\nvar tmp = tryRequire( join( __dirname, './native.js' ) );\nif ( isError( tmp ) ) {\n\tdsdot = main;\n} else {\n\tdsdot = tmp;\n}\n\n\n// EXPORTS //\n\nmodule.exports = dsdot;\n\n// exports: { \"ndarray\": \"dsdot.ndarray\" }\n"], + "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// VARIABLES //\n\nvar M = 5;\n\n\n// MAIN //\n\n/**\n* Computes the dot product of `x` and `y` with extended accumulation and result.\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {Float32Array} x - first input array\n* @param {integer} strideX - `x` stride length\n* @param {Float32Array} y - second input array\n* @param {integer} strideY - `y` stride length\n* @returns {number} dot product\n*\n* @example\n* var Float32Array = require( '@stdlib/array-float32' );\n*\n* var x = new Float32Array( [ 4.0, 2.0, -3.0, 5.0, -1.0 ] );\n* var y = new Float32Array( [ 2.0, 6.0, -1.0, -4.0, 8.0 ] );\n*\n* var z = dsdot( x.length, x, 1, y, 1 );\n* // returns -5.0\n*/\nfunction dsdot( N, x, strideX, y, strideY ) {\n\tvar dot;\n\tvar ix;\n\tvar iy;\n\tvar m;\n\tvar i;\n\n\tdot = 0.0;\n\tif ( N <= 0 ) {\n\t\treturn dot;\n\t}\n\t// Use unrolled loops if both strides are equal to `1`...\n\tif ( strideX === 1 && strideY === 1 ) {\n\t\tm = N % M;\n\n\t\t// If we have a remainder, run a clean-up loop...\n\t\tif ( m > 0 ) {\n\t\t\tfor ( i = 0; i < m; i++ ) {\n\t\t\t\tdot += x[ i ] * y[ i ];\n\t\t\t}\n\t\t}\n\t\tif ( N < M ) {\n\t\t\treturn dot;\n\t\t}\n\t\tfor ( i = m; i < N; i += M ) {\n\t\t\tdot += ( x[i]*y[i] ) + ( x[i+1]*y[i+1] ) + ( x[i+2]*y[i+2] ) + ( x[i+3]*y[i+3] ) + ( x[i+4]*y[i+4] ); // eslint-disable-line max-len\n\t\t}\n\t\treturn dot;\n\t}\n\tif ( strideX < 0 ) {\n\t\tix = ( 1-N ) * strideX;\n\t} else {\n\t\tix = 0;\n\t}\n\tif ( strideY < 0 ) {\n\t\tiy = ( 1-N ) * strideY;\n\t} else {\n\t\tiy = 0;\n\t}\n\tfor ( i = 0; i < N; i++ ) {\n\t\tdot += x[ ix ] * y[ iy ];\n\t\tix += strideX;\n\t\tiy += strideY;\n\t}\n\treturn dot;\n}\n\n\n// EXPORTS //\n\nmodule.exports = dsdot;\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// VARIABLES //\n\nvar M = 5;\n\n\n// MAIN //\n\n/**\n* Computes the dot product of `x` and `y` with extended accumulation and result.\n*\n* @param {integer} N - number of indexed elements\n* @param {Float32Array} x - first input array\n* @param {integer} strideX - `x` stride length\n* @param {NonNegativeInteger} offsetX - starting index for `x`\n* @param {Float32Array} y - second input array\n* @param {integer} strideY - `y` stride length\n* @param {NonNegativeInteger} offsetY - starting index for `y`\n* @returns {number} dot product\n*\n* @example\n* var Float32Array = require( '@stdlib/array-float32' );\n*\n* var x = new Float32Array( [ 4.0, 2.0, -3.0, 5.0, -1.0 ] );\n* var y = new Float32Array( [ 2.0, 6.0, -1.0, -4.0, 8.0 ] );\n*\n* var z = dsdot( x.length, x, 1, 0, y, 1, 0 );\n* // returns -5.0\n*/\nfunction dsdot( N, x, strideX, offsetX, y, strideY, offsetY ) {\n\tvar dot;\n\tvar ix;\n\tvar iy;\n\tvar m;\n\tvar i;\n\n\tdot = 0.0;\n\tif ( N <= 0 ) {\n\t\treturn dot;\n\t}\n\tix = offsetX;\n\tiy = offsetY;\n\n\t// Use unrolled loops if both strides are equal to `1`...\n\tif ( strideX === 1 && strideY === 1 ) {\n\t\tm = N % M;\n\n\t\t// If we have a remainder, run a clean-up loop...\n\t\tif ( m > 0 ) {\n\t\t\tfor ( i = 0; i < m; i++ ) {\n\t\t\t\tdot += x[ ix ] * y[ iy ];\n\t\t\t\tix += 1;\n\t\t\t\tiy += 1;\n\t\t\t}\n\t\t}\n\t\tif ( N < M ) {\n\t\t\treturn dot;\n\t\t}\n\t\tfor ( i = m; i < N; i += M ) {\n\t\t\tdot += ( x[ix]*y[iy] ) + ( x[ix+1]*y[iy+1] ) + ( x[ix+2]*y[iy+2] ) + ( x[ix+3]*y[iy+3] ) + ( x[ix+4]*y[iy+4] ); // eslint-disable-line max-len\n\t\t\tix += M;\n\t\t\tiy += M;\n\t\t}\n\t\treturn dot;\n\t}\n\tfor ( i = 0; i < N; i++ ) {\n\t\tdot += x[ ix ] * y[ iy ];\n\t\tix += strideX;\n\t\tiy += strideY;\n\t}\n\treturn dot;\n}\n\n\n// EXPORTS //\n\nmodule.exports = dsdot;\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 dsdot = require( './dsdot.js' );\nvar ndarray = require( './ndarray.js' );\n\n\n// MAIN //\n\nsetReadOnly( dsdot, 'ndarray', ndarray );\n\n\n// EXPORTS //\n\nmodule.exports = dsdot;\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* BLAS level 1 routine to compute the dot product of vectors `x` and `y` with extended accumulation and result.\n*\n* @module @stdlib/blas-base-dsdot\n*\n* @example\n* var Float32Array = require( '@stdlib/array-float32' );\n* var dsdot = require( '@stdlib/blas-base-dsdot' );\n*\n* var x = new Float32Array( [ 4.0, 2.0, -3.0, 5.0, -1.0 ] );\n* var y = new Float32Array( [ 2.0, 6.0, -1.0, -4.0, 8.0 ] );\n*\n* var z = dsdot( x.length, x, 1, y, 1 );\n* // returns -12.0\n*\n* @example\n* var Float32Array = require( '@stdlib/array-float32' );\n* var dsdot = require( '@stdlib/blas-base-dsdot' );\n*\n* var x = new Float32Array( [ 4.0, 2.0, -3.0, 5.0, -1.0 ] );\n* var y = new Float32Array( [ 2.0, 6.0, -1.0, -4.0, 8.0 ] );\n*\n* var z = dsdot.ndarray( x.length, x, 1, 0, y, 1, 0 );\n* // returns -12.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 dsdot;\nvar tmp = tryRequire( join( __dirname, './native.js' ) );\nif ( isError( tmp ) ) {\n\tdsdot = main;\n} else {\n\tdsdot = tmp;\n}\n\n\n// EXPORTS //\n\nmodule.exports = dsdot;\n\n// exports: { \"ndarray\": \"dsdot.ndarray\" }\n"], "mappings": "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", "names": ["require_dsdot", "__commonJSMin", "exports", "module", "M", "dsdot", "N", "x", "strideX", "y", "strideY", "dot", "ix", "iy", "m", "i", "require_ndarray", "__commonJSMin", "exports", "module", "M", "dsdot", "N", "x", "strideX", "offsetX", "y", "strideY", "offsetY", "dot", "ix", "iy", "m", "i", "require_main", "__commonJSMin", "exports", "module", "setReadOnly", "dsdot", "ndarray", "join", "tryRequire", "isError", "main", "dsdot", "tmp"] } diff --git a/docs/repl.txt b/docs/repl.txt index e88e037..e2deb79 100644 --- a/docs/repl.txt +++ b/docs/repl.txt @@ -3,13 +3,13 @@ Computes the dot product of two single-precision floating-point vectors with extended accumulation and result. - The `N`, `strideX`, and `strideY` parameters determine which elements in `x` - and `y` are accessed at runtime. + The `N` and stride parameters determine which elements in the strided arrays + are accessed at runtime. Indexing is relative to the first index. To introduce an offset, use a typed array view. - If `N <= 0` the function returns `0.0`. + If `N <= 0` the function returns `0`. Parameters ---------- @@ -31,7 +31,7 @@ Returns ------- dot: number - The dot product of `x` and `y`. + Dot product. Examples -------- @@ -44,8 +44,7 @@ // Strides: > x = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); > y = new {{alias:@stdlib/array/float32}}( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > dot = {{alias}}( N, x, 2, y, -1 ) + > dot = {{alias}}( 3, x, 2, y, -1 ) 9.0 // Using view offsets: @@ -53,18 +52,17 @@ > y = new {{alias:@stdlib/array/float32}}( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); > var x1 = new {{alias:@stdlib/array/float32}}( x.buffer, x.BYTES_PER_ELEMENT*1 ); > var y1 = new {{alias:@stdlib/array/float32}}( y.buffer, y.BYTES_PER_ELEMENT*3 ); - > N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > dot = {{alias}}( N, x1, -2, y1, 1 ) + > dot = {{alias}}( 3, x1, -2, y1, 1 ) 128.0 + {{alias}}.ndarray( N, x, strideX, offsetX, y, strideY, offsetY ) Computes the dot product of two single-precision floating-point vectors using alternative indexing semantics and with extended accumulation and result. While typed array views mandate a view offset based on the underlying - buffer, the `offsetX` and `offsetY` parameters support indexing based on a - starting index. + buffer, the offset parameters support indexing based on a starting index. Parameters ---------- @@ -92,7 +90,7 @@ Returns ------- dot: number - The dot product of `x` and `y`. + Dot product. Examples -------- @@ -105,15 +103,13 @@ // Strides: > x = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); > y = new {{alias:@stdlib/array/float32}}( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > dot = {{alias}}.ndarray( N, x, 2, 0, y, 2, 0 ) + > dot = {{alias}}.ndarray( 3, x, 2, 0, y, 2, 0 ) 9.0 // Using offset indices: > x = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); > y = new {{alias:@stdlib/array/float32}}( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); - > N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > dot = {{alias}}.ndarray( N, x, -2, x.length-1, y, 1, 3 ) + > dot = {{alias}}.ndarray( 3, x, -2, x.length-1, y, 1, 3 ) 128.0 References diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts index e75a15b..2a830e9 100644 --- a/docs/types/index.d.ts +++ b/docs/types/index.d.ts @@ -30,7 +30,7 @@ interface Routine { * @param strideX - `x` stride length * @param y - second input array * @param strideY - `y` stride length - * @returns dot product of `x` and `y` + * @returns dot product * * @example * var Float32Array = require( `@stdlib/array/float32` ); @@ -53,7 +53,7 @@ interface Routine { * @param y - second input array * @param strideY - `y` stride length * @param offsetY - starting index for `y` - * @returns dot product of `x` and `y` + * @returns dot product * * @example * var Float32Array = require( `@stdlib/array/float32` ); @@ -75,7 +75,7 @@ interface Routine { * @param strideX - `x` stride length * @param y - second input array * @param strideY - `y` stride length -* @returns dot product of `x` and `y` +* @returns dot product * * @example * var Float32Array = require( `@stdlib/array/float32` ); diff --git a/examples/index.js b/examples/index.js index 88925b0..126d85e 100644 --- a/examples/index.js +++ b/examples/index.js @@ -18,23 +18,15 @@ '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 dsdot = require( './../lib' ).ndarray; -var x; -var y; -var i; - -x = new Float32Array( 10 ); -y = new Float32Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( randu()*100.0 ); - y[ i ] = round( randu()*10.0 ); -} +var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) ); console.log( x ); + +var y = filledarrayBy( x.length, 'float32', discreteUniform( 0, 10 ) ); console.log( y ); -var dot = dsdot( x.length, x, 1, 0, y, -1, y.length-1 ); -console.log( dot ); +var out = dsdot( x.length, x, 1, 0, y, -1, y.length-1 ); +console.log( out ); diff --git a/include.gypi b/include.gypi index d9347f4..85d47ea 100644 --- a/include.gypi +++ b/include.gypi @@ -52,7 +52,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, 5 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 4 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 1 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Y, N, strideY, argv, 3 ); + + napi_value v; + napi_status status = napi_create_double( env, c_dsdot( N, X, strideX, Y, strideY ), &v ); + assert( status == napi_ok ); + + return v; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/src/addon.cpp b/src/addon.cpp deleted file mode 100644 index ca7703d..0000000 --- a/src/addon.cpp +++ /dev/null @@ -1,153 +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/base/dsdot.h" -#include -#include -#include -#include -#include - -/** -* Add-on namespace. -*/ -namespace stdlib_blas_base_dsdot { - - /** - * Computes the dot product of two single-precision floating-point vectors with extended accumulation and result. - * - * ## Notes - * - * - When called from JavaScript, the function expects five arguments: - * - * - `N`: number of indexed elements - * - `X`: input array - * - `strideX`: `X` stride length - * - `Y`: destination array - * - `strideY`: `Y` stride length - */ - napi_value node_dsdot( napi_env env, napi_callback_info info ) { - napi_status status; - - size_t argc = 5; - napi_value argv[ 5 ]; - status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr ); - assert( status == napi_ok ); - - if ( argc < 5 ) { - napi_throw_error( env, nullptr, "invalid invocation. Must provide 5 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 res1; - status = napi_is_typedarray( env, argv[ 1 ], &res1 ); - assert( status == napi_ok ); - if ( res1 == 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; - } - - bool res3; - status = napi_is_typedarray( env, argv[ 3 ], &res3 ); - assert( status == napi_ok ); - if ( res3 == false ) { - napi_throw_type_error( env, nullptr, "invalid argument. Fourth argument must be a Float32Array." ); - return nullptr; - } - - napi_valuetype vtype4; - status = napi_typeof( env, argv[ 4 ], &vtype4 ); - assert( status == napi_ok ); - if ( vtype4 != napi_number ) { - napi_throw_type_error( env, nullptr, "invalid argument. Fifth 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 strideX; - status = napi_get_value_int64( env, argv[ 2 ], &strideX ); - assert( status == napi_ok ); - - int64_t strideY; - status = napi_get_value_int64( env, argv[ 4 ], &strideY ); - 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(strideX) >= (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_typedarray_type vtype3; - size_t ylen; - void *Y; - status = napi_get_typedarray_info( env, argv[ 3 ], &vtype3, &ylen, &Y, nullptr, nullptr ); - assert( status == napi_ok ); - if ( vtype3 != napi_float32_array ) { - napi_throw_type_error( env, nullptr, "invalid argument. Fourth argument must be a Float32Array." ); - return nullptr; - } - if ( (N-1)*llabs(strideY) >= (int64_t)ylen ) { - napi_throw_range_error( env, nullptr, "invalid argument. Fourth 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, c_dsdot( N, (float *)X, strideX, (float *)Y, strideY ), &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_dsdot, NULL, &fcn ); - assert( status == napi_ok ); - return fcn; - } - - NAPI_MODULE( NODE_GYP_MODULE_NAME, Init ) -} // end namespace stdlib_blas_base_dsdot diff --git a/src/dsdot.c b/src/dsdot.c index 377e207..d931405 100644 --- a/src/dsdot.c +++ b/src/dsdot.c @@ -31,7 +31,7 @@ * @param strideX X stride length * @param Y second array * @param strideY Y stride length -* @returns the dot product of X and Y +* @returns the dot product */ double c_dsdot( const int N, const float *X, const int strideX, const float *Y, const int strideY ) { double dot; diff --git a/src/dsdot.f b/src/dsdot.f index addab92..f90d78c 100644 --- a/src/dsdot.f +++ b/src/dsdot.f @@ -60,7 +60,7 @@ ! @param {integer} strideX - `sx` stride length ! @param {Array} sy - second array ! @param {integer} strideY - `sy` stride length -! @returns {double} the dot product of `sx` and `sy` +! @returns {double} the dot product !< double precision function dsdot( N, sx, strideX, sy, strideY ) implicit none diff --git a/src/dsdot_cblas.c b/src/dsdot_cblas.c index ac63e7a..f12e8fa 100644 --- a/src/dsdot_cblas.c +++ b/src/dsdot_cblas.c @@ -27,7 +27,7 @@ * @param strideX X stride length * @param Y second array * @param strideY Y stride length -* @returns the dot product of X and Y +* @returns the dot product */ double c_dsdot( const int N, const float *X, const int strideX, const float *Y, const int strideY ) { return cblas_dsdot( N, X, strideX, Y, strideY ); diff --git a/src/dsdot_f.c b/src/dsdot_f.c index 221da3e..e8e3c7d 100644 --- a/src/dsdot_f.c +++ b/src/dsdot_f.c @@ -32,7 +32,7 @@ * @param strideX X stride length * @param Y second array * @param strideY Y stride length -* @returns the dot product of X and Y +* @returns the dot product */ double c_dsdot( const int N, const float *X, const int strideX, const float *Y, const int strideY ) { double dot; diff --git a/test/test.dsdot.js b/test/test.dsdot.js index a48aa7d..adb648b 100644 --- a/test/test.dsdot.js +++ b/test/test.dsdot.js @@ -34,7 +34,7 @@ tape( 'main export is a function', function test( t ) { }); tape( 'the function has an arity of 5', function test( t ) { - t.strictEqual( dsdot.length, 5, 'has expected arity' ); + t.strictEqual( dsdot.length, 5, 'returns expected value' ); t.end(); }); diff --git a/test/test.dsdot.native.js b/test/test.dsdot.native.js index 435f299..108e6fc 100644 --- a/test/test.dsdot.native.js +++ b/test/test.dsdot.native.js @@ -43,7 +43,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( dsdot.length, 5, 'has expected arity' ); + t.strictEqual( dsdot.length, 5, 'returns expected value' ); t.end(); }); diff --git a/test/test.js b/test/test.js index 6d6516d..2776dc7 100644 --- a/test/test.js +++ b/test/test.js @@ -51,7 +51,7 @@ tape( 'if a native implementation is available, the main export is the native im '@stdlib/utils-try-require': tryRequire }); - t.strictEqual( dsdot, mock, 'returns native implementation' ); + t.strictEqual( dsdot, mock, 'returns expected value' ); t.end(); function tryRequire() { @@ -73,7 +73,7 @@ tape( 'if a native implementation is not available, the main export is a JavaScr '@stdlib/utils-try-require': tryRequire }); - t.strictEqual( dsdot, main, 'returns JavaScript implementation' ); + t.strictEqual( dsdot, main, 'returns expected value' ); t.end(); function tryRequire() { diff --git a/test/test.ndarray.js b/test/test.ndarray.js index 8a1e297..c9b9cac 100644 --- a/test/test.ndarray.js +++ b/test/test.ndarray.js @@ -34,7 +34,7 @@ tape( 'main export is a function', function test( t ) { }); tape( 'the function has an arity of 7', function test( t ) { - t.strictEqual( dsdot.length, 7, 'has expected arity' ); + t.strictEqual( dsdot.length, 7, 'returns expected value' ); t.end(); }); diff --git a/test/test.ndarray.native.js b/test/test.ndarray.native.js index ff65c43..0a253e6 100644 --- a/test/test.ndarray.native.js +++ b/test/test.ndarray.native.js @@ -43,7 +43,7 @@ tape( 'main export is a function', opts, function test( t ) { }); tape( 'the function has an arity of 7', opts, function test( t ) { - t.strictEqual( dsdot.length, 7, 'has expected arity' ); + t.strictEqual( dsdot.length, 7, 'returns expected value' ); t.end(); });