diff --git a/README.md b/README.md index 088c945..5a6fc05 100644 --- a/README.md +++ b/README.md @@ -105,14 +105,10 @@ The function has the following parameters: 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 floor = require( '@stdlib/math-base-special-floor' ); - var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; var y = [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ]; -var N = floor( x.length / 2 ); - -var z = gdot( N, x, 2, y, -1 ); +var z = gdot( 3, x, 2, y, -1 ); // returns 9.0 ``` @@ -122,7 +118,6 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float64Array = require( '@stdlib/array-float64' ); -var floor = require( '@stdlib/math-base-special-floor' ); // Initial arrays... var x0 = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); @@ -132,9 +127,7 @@ var y0 = new Float64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element var y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // start at 4th element -var N = floor( x0.length / 2 ); - -var z = gdot( N, x1, -2, y1, 1 ); +var z = gdot( 3, x1, -2, y1, 1 ); // returns 128.0 ``` @@ -158,14 +151,10 @@ The function has the following additional parameters: 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 floor = require( '@stdlib/math-base-special-floor' ); - var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; var y = [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ]; -var N = floor( x.length / 2 ); - -var z = gdot.ndarray( N, x, 2, 1, y, -1, y.length-1 ); +var z = gdot.ndarray( 3, x, 2, 1, y, -1, y.length-1 ); // returns 128.0 ``` @@ -191,28 +180,18 @@ var z = gdot.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 Float64Array = require( '@stdlib/array-float64' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); +var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ).factory; +var filledarrayBy = require( '@stdlib/array-filled-by' ); var gdot = require( '@stdlib/blas-base-gdot' ); -var x; -var y; -var i; - -x = new Float64Array( 10 ); -y = new Uint8ClampedArray( 10 ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( randu()*500.0 ); - y[ i ] = round( randu()*255.0 ); -} +var x = filledarrayBy( 10, 'float64', discreteUniform( 0, 500 ) ); console.log( x ); + +var y = filledarrayBy( x.length, 'uint8c', discreteUniform( 0, 255 ) ); console.log( y ); -// Compute the dot product: -var dot = gdot.ndarray( x.length, x, 1, 0, y, -1, y.length-1 ); -console.log( dot ); +var out = gdot.ndarray( x.length, x, 1, 0, y, -1, y.length-1 ); +console.log( out ); ``` @@ -314,12 +293,12 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray - - [@stdlib/blas/base/ddot]: https://github.com/stdlib-js/blas-base-ddot [@stdlib/blas/base/sdot]: https://github.com/stdlib-js/blas-base-sdot + + [@stdlib/blas/gdot]: https://github.com/stdlib-js/blas-gdot diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js index 6286691..c93335b 100644 --- a/benchmark/benchmark.js +++ b/benchmark/benchmark.js @@ -21,13 +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 pkg = require( './../package.json' ).name; var gdot = require( './../lib' ); +// VARIABLES // + +var rand = uniform( -100.0, 100.0 ); + + // FUNCTIONS // /** @@ -38,16 +44,8 @@ var gdot = require( './../lib' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var y; - var i; - - x = []; - y = []; - for ( i = 0; i < len; i++ ) { - x.push( ( randu()*20.0 ) - 10.0 ); - y.push( ( randu()*20.0 ) - 10.0 ); - } + var x = filledarrayBy( len, 'generic', rand ); + var y = filledarrayBy( len, 'generic', rand ); return benchmark; /** diff --git a/benchmark/benchmark.ndarray.js b/benchmark/benchmark.ndarray.js index caec281..a13fbbf 100644 --- a/benchmark/benchmark.ndarray.js +++ b/benchmark/benchmark.ndarray.js @@ -21,13 +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 pkg = require( './../package.json' ).name; var gdot = require( './../lib' ).ndarray; +// VARIABLES // + +var rand = uniform( -100.0, 100.0 ); + + // FUNCTIONS // /** @@ -38,16 +44,8 @@ var gdot = require( './../lib' ).ndarray; * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var y; - var i; - - x = []; - y = []; - for ( i = 0; i < len; i++ ) { - x.push( ( randu()*20.0 ) - 10.0 ); - y.push( ( randu()*20.0 ) - 10.0 ); - } + var x = filledarrayBy( len, 'generic', rand ); + var y = filledarrayBy( len, 'generic', rand ); return benchmark; /** diff --git a/dist/index.js.map b/dist/index.js.map index 22b9c8c..505f764 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1,7 +1,7 @@ { "version": 3, "sources": ["../lib/main.js", "../lib/ndarray.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`.\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {NumericArray} x - first input array\n* @param {integer} strideX - `x` stride length\n* @param {NumericArray} 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 x = [ 4.0, 2.0, -3.0, 5.0, -1.0 ];\n* var y = [ 2.0, 6.0, -1.0, -4.0, 8.0 ];\n\n* var z = gdot( x.length, x, 1, y, 1 );\n* // returns -5.0\n*/\nfunction gdot( 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 = gdot;\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`.\n*\n* @param {integer} N - number of indexed elements\n* @param {NumericArray} x - first input array\n* @param {integer} strideX - `x` stride length\n* @param {NonNegativeInteger} offsetX - starting index for `x`\n* @param {NumericArray} 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 x = [ 4.0, 2.0, -3.0, 5.0, -1.0 ];\n* var y = [ 2.0, 6.0, -1.0, -4.0, 8.0 ];\n\n* var z = gdot( x.length, x, 1, 0, y, 1, 0 );\n* // returns -5.0\n*/\nfunction gdot( 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 = gdot;\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`.\n*\n* @module @stdlib/blas-base-gdot\n*\n* @example\n* var gdot = require( '@stdlib/blas-base-gdot' );\n*\n* var x = [ 4.0, 2.0, -3.0, 5.0, -1.0 ];\n* var y = [ 2.0, 6.0, -1.0, -4.0, 8.0 ];\n*\n* var z = gdot( x.length, x, 1, y, 1 );\n* // returns -5.0\n*\n* @example\n* var gdot = require( '@stdlib/blas-base-gdot' );\n*\n* var x = [ 4.0, 2.0, -3.0, 5.0, -1.0 ];\n* var y = [ 2.0, 6.0, -1.0, -4.0, 8.0 ];\n*\n* var z = gdot.ndarray( x.length, x, 1, 0, y, 1, 0 );\n* // returns -5.0\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar ndarray = require( './ndarray.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'ndarray', ndarray );\n\n\n// EXPORTS //\n\nmodule.exports = main;\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`.\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {NumericArray} x - first input array\n* @param {integer} strideX - `x` stride length\n* @param {NumericArray} y - second input array\n* @param {integer} strideY - `y` stride length\n* @returns {number} dot product\n*\n* @example\n* var x = [ 4.0, 2.0, -3.0, 5.0, -1.0 ];\n* var y = [ 2.0, 6.0, -1.0, -4.0, 8.0 ];\n\n* var z = gdot( x.length, x, 1, y, 1 );\n* // returns -5.0\n*/\nfunction gdot( 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 = gdot;\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`.\n*\n* @param {integer} N - number of indexed elements\n* @param {NumericArray} x - first input array\n* @param {integer} strideX - `x` stride length\n* @param {NonNegativeInteger} offsetX - starting index for `x`\n* @param {NumericArray} 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 x = [ 4.0, 2.0, -3.0, 5.0, -1.0 ];\n* var y = [ 2.0, 6.0, -1.0, -4.0, 8.0 ];\n\n* var z = gdot( x.length, x, 1, 0, y, 1, 0 );\n* // returns -5.0\n*/\nfunction gdot( 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 = gdot;\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`.\n*\n* @module @stdlib/blas-base-gdot\n*\n* @example\n* var gdot = require( '@stdlib/blas-base-gdot' );\n*\n* var x = [ 4.0, 2.0, -3.0, 5.0, -1.0 ];\n* var y = [ 2.0, 6.0, -1.0, -4.0, 8.0 ];\n*\n* var z = gdot( x.length, x, 1, y, 1 );\n* // returns -5.0\n*\n* @example\n* var gdot = require( '@stdlib/blas-base-gdot' );\n*\n* var x = [ 4.0, 2.0, -3.0, 5.0, -1.0 ];\n* var y = [ 2.0, 6.0, -1.0, -4.0, 8.0 ];\n*\n* var z = gdot.ndarray( x.length, x, 1, 0, y, 1, 0 );\n* // returns -5.0\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar ndarray = require( './ndarray.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'ndarray', ndarray );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAI,EAsBR,SAASC,EAAMC,EAAGC,EAAGC,EAASC,EAAGC,EAAU,CAC1C,IAAIC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAJ,EAAM,EACDL,GAAK,EACT,OAAOK,EAGR,GAAKH,IAAY,GAAKE,IAAY,EAAI,CAIrC,GAHAI,EAAIR,EAAIF,EAGHU,EAAI,EACR,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IACnBJ,GAAOJ,EAAGQ,CAAE,EAAIN,EAAGM,CAAE,EAGvB,GAAKT,EAAIF,EACR,OAAOO,EAER,IAAMI,EAAID,EAAGC,EAAIT,EAAGS,GAAKX,EACxBO,GAASJ,EAAEQ,CAAC,EAAEN,EAAEM,CAAC,EAAQR,EAAEQ,EAAE,CAAC,EAAEN,EAAEM,EAAE,CAAC,EAAQR,EAAEQ,EAAE,CAAC,EAAEN,EAAEM,EAAE,CAAC,EAAQR,EAAEQ,EAAE,CAAC,EAAEN,EAAEM,EAAE,CAAC,EAAQR,EAAEQ,EAAE,CAAC,EAAEN,EAAEM,EAAE,CAAC,EAElG,OAAOJ,CACR,CAWA,IAVKH,EAAU,EACdI,GAAO,EAAEN,GAAME,EAEfI,EAAK,EAEDF,EAAU,EACdG,GAAO,EAAEP,GAAMI,EAEfG,EAAK,EAEAE,EAAI,EAAGA,EAAIT,EAAGS,IACnBJ,GAASJ,EAAGK,CAAG,EAAIH,EAAGI,CAAG,EACzBD,GAAMJ,EACNK,GAAMH,EAEP,OAAOC,CACR,CAKAR,EAAO,QAAUE,IC9FjB,IAAAW,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAI,EAwBR,SAASC,EAAMC,EAAGC,EAAGC,EAASC,EAASC,EAAGC,EAASC,EAAU,CAC5D,IAAIC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAJ,EAAM,EACDP,GAAK,EACT,OAAOO,EAMR,GAJAC,EAAKL,EACLM,EAAKH,EAGAJ,IAAY,GAAKG,IAAY,EAAI,CAIrC,GAHAK,EAAIV,EAAIF,EAGHY,EAAI,EACR,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IACnBJ,GAASN,EAAGO,CAAG,EAAIJ,EAAGK,CAAG,EACzBD,GAAM,EACNC,GAAM,EAGR,GAAKT,EAAIF,EACR,OAAOS,EAER,IAAMI,EAAID,EAAGC,EAAIX,EAAGW,GAAKb,EACxBS,GAASN,EAAEO,CAAE,EAAEJ,EAAEK,CAAE,EAAQR,EAAEO,EAAG,CAAC,EAAEJ,EAAEK,EAAG,CAAC,EAAQR,EAAEO,EAAG,CAAC,EAAEJ,EAAEK,EAAG,CAAC,EAAQR,EAAEO,EAAG,CAAC,EAAEJ,EAAEK,EAAG,CAAC,EAAQR,EAAEO,EAAG,CAAC,EAAEJ,EAAEK,EAAG,CAAC,EAC3GD,GAAMV,EACNW,GAAMX,EAEP,OAAOS,CACR,CACA,IAAMI,EAAI,EAAGA,EAAIX,EAAGW,IACnBJ,GAAON,EAAGO,CAAG,EAAIJ,EAAGK,CAAG,EACvBD,GAAMN,EACNO,GAAMJ,EAEP,OAAOE,CACR,CAKAV,EAAO,QAAUE,IC/CjB,IAAIa,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", "names": ["require_main", "__commonJSMin", "exports", "module", "M", "gdot", "N", "x", "strideX", "y", "strideY", "dot", "ix", "iy", "m", "i", "require_ndarray", "__commonJSMin", "exports", "module", "M", "gdot", "N", "x", "strideX", "offsetX", "y", "strideY", "offsetY", "dot", "ix", "iy", "m", "i", "setReadOnly", "main", "ndarray"] } diff --git a/docs/repl.txt b/docs/repl.txt index 2215b77..e22377b 100644 --- a/docs/repl.txt +++ b/docs/repl.txt @@ -29,22 +29,21 @@ Returns ------- - dot: number - The dot product of `x` and `y`. + out: number + The dot product. Examples -------- // Standard usage: > var x = [ 4.0, 2.0, -3.0, 5.0, -1.0 ]; > var y = [ 2.0, 6.0, -1.0, -4.0, 8.0 ]; - > var dot = {{alias}}( x.length, x, 1, y, 1 ) + > var out = {{alias}}( x.length, x, 1, y, 1 ) -5.0 // Strides: > x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; > y = [ 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 ) + > out = {{alias}}( 3, x, 2, y, -1 ) 9.0 // Using view offsets: @@ -52,8 +51,7 @@ > y = new {{alias:@stdlib/array/float64}}( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); > var x1 = new {{alias:@stdlib/array/float64}}( x.buffer, x.BYTES_PER_ELEMENT*1 ); > var y1 = new {{alias:@stdlib/array/float64}}( y.buffer, y.BYTES_PER_ELEMENT*3 ); - > N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > dot = {{alias}}( N, x1, -2, y1, 1 ) + > out = {{alias}}( 3, x1, -2, y1, 1 ) 128.0 @@ -89,29 +87,27 @@ Returns ------- - dot: number - The dot product of `x` and `y`. + out: number + The dot product. Examples -------- // Standard usage: > var x = [ 4.0, 2.0, -3.0, 5.0, -1.0 ]; > var y = [ 2.0, 6.0, -1.0, -4.0, 8.0 ]; - > var dot = {{alias}}.ndarray( x.length, x, 1, 0, y, 1, 0 ) + > var out = {{alias}}.ndarray( x.length, x, 1, 0, y, 1, 0 ) -5.0 // Strides: > x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; > y = [ 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 ) + > out = {{alias}}.ndarray( 3, x, 2, 0, y, 2, 0 ) 9.0 // Using offset indices: > x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; > y = [ 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 ) + > out = {{alias}}.ndarray( 3, x, -2, x.length-1, y, 1, 3 ) 128.0 See Also diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts index a3f6681..8d9e418 100644 --- a/docs/types/index.d.ts +++ b/docs/types/index.d.ts @@ -34,7 +34,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 x = [ 4.0, 2.0, -3.0, 5.0, -1.0 ]; @@ -55,7 +55,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 x = [ 4.0, 2.0, -3.0, 5.0, -1.0 ]; @@ -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 x = [ 4.0, 2.0, -3.0, 5.0, -1.0 ]; diff --git a/examples/index.js b/examples/index.js index 23b09d7..38331cc 100644 --- a/examples/index.js +++ b/examples/index.js @@ -18,25 +18,15 @@ 'use strict'; -var randu = require( '@stdlib/random-base-randu' ); -var round = require( '@stdlib/math-base-special-round' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); +var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ).factory; +var filledarrayBy = require( '@stdlib/array-filled-by' ); var gdot = require( './../lib' ).ndarray; -var x; -var y; -var i; - -x = new Float64Array( 10 ); -y = new Uint8ClampedArray( 10 ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( randu()*500.0 ); - y[ i ] = round( randu()*255.0 ); -} +var x = filledarrayBy( 10, 'float64', discreteUniform( 0, 500 ) ); console.log( x ); + +var y = filledarrayBy( x.length, 'uint8c', discreteUniform( 0, 255 ) ); console.log( y ); -// Compute the dot product: -var dot = gdot( x.length, x, 1, 0, y, -1, y.length-1 ); -console.log( dot ); +var out = gdot( x.length, x, 1, 0, y, -1, y.length-1 ); +console.log( out ); diff --git a/lib/main.js b/lib/main.js index 456a916..2428545 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var M = 5; * @param {integer} strideX - `x` stride length * @param {NumericArray} y - second input array * @param {integer} strideY - `y` stride length -* @returns {number} dot product of `x` and `y` +* @returns {number} dot product * * @example * var x = [ 4.0, 2.0, -3.0, 5.0, -1.0 ]; diff --git a/lib/ndarray.js b/lib/ndarray.js index d0f53ed..c8323ae 100644 --- a/lib/ndarray.js +++ b/lib/ndarray.js @@ -35,7 +35,7 @@ var M = 5; * @param {NumericArray} y - second input array * @param {integer} strideY - `y` stride length * @param {NonNegativeInteger} offsetY - starting index for `y` -* @returns {number} dot product of `x` and `y` +* @returns {number} dot product * * @example * var x = [ 4.0, 2.0, -3.0, 5.0, -1.0 ]; diff --git a/package.json b/package.json index 8f73fe4..d8ff877 100644 --- a/package.json +++ b/package.json @@ -41,13 +41,13 @@ "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" }, "devDependencies": { + "@stdlib/array-filled-by": "^0.1.0", "@stdlib/array-float64": "^0.1.1", - "@stdlib/array-uint8c": "^0.1.1", "@stdlib/bench": "^0.2.1", "@stdlib/math-base-assert-is-nan": "^0.1.1", "@stdlib/math-base-special-pow": "^0.1.0", - "@stdlib/math-base-special-round": "^0.1.1", - "@stdlib/random-base-randu": "^0.1.0", + "@stdlib/random-base-discrete-uniform": "^0.1.0", + "@stdlib/random-base-uniform": "^0.1.0", "tape": "git+https://github.com/kgryte/tape.git#fix/globby", "istanbul": "^0.4.1", "tap-min": "git+https://github.com/Planeshifter/tap-min.git" diff --git a/test/test.main.js b/test/test.main.js index 96f246a..c617d3d 100644 --- a/test/test.main.js +++ b/test/test.main.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( gdot.length, 5, 'has expected arity' ); + t.strictEqual( gdot.length, 5, 'returns expected value' ); t.end(); }); diff --git a/test/test.ndarray.js b/test/test.ndarray.js index 5c7d546..1a3214d 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( gdot.length, 7, 'has expected arity' ); + t.strictEqual( gdot.length, 7, 'returns expected value' ); t.end(); });