From fd81f7d97d069fbcce23847bdf84fe6b341d847b Mon Sep 17 00:00:00 2001 From: aman-095 Date: Thu, 12 Sep 2024 07:54:13 +0530 Subject: [PATCH] refactor: add support for stack --- lib/node_modules/@stdlib/blas/sdot/README.md | 84 ++-- .../@stdlib/blas/sdot/benchmark/benchmark.js | 37 +- .../blas/sdot/benchmark/benchmark.stack.js | 122 ++++++ .../@stdlib/blas/sdot/docs/repl.txt | 43 +- .../@stdlib/blas/sdot/docs/types/index.d.ts | 25 +- .../@stdlib/blas/sdot/docs/types/test.ts | 82 ++-- .../@stdlib/blas/sdot/examples/index.js | 30 +- .../@stdlib/blas/sdot/lib/index.js | 3 + .../@stdlib/blas/sdot/lib/main.js | 132 +++++- .../@stdlib/blas/sdot/test/test.js | 408 +++++++++++++++++- 10 files changed, 810 insertions(+), 156 deletions(-) create mode 100644 lib/node_modules/@stdlib/blas/sdot/benchmark/benchmark.stack.js diff --git a/lib/node_modules/@stdlib/blas/sdot/README.md b/lib/node_modules/@stdlib/blas/sdot/README.md index 2c676876361..3590f0f28b0 100644 --- a/lib/node_modules/@stdlib/blas/sdot/README.md +++ b/lib/node_modules/@stdlib/blas/sdot/README.md @@ -33,7 +33,7 @@ The [dot product][dot-product] (or scalar product) is defined as ``` @@ -51,9 +51,9 @@ The [dot product][dot-product] (or scalar product) is defined as var sdot = require( '@stdlib/blas/sdot' ); ``` -#### sdot( x, y ) +#### sdot( x, y\[, dim] ) -Calculates the dot product of vectors `x` and `y`. +Calculates the dot product of two single-precision floating-point vectors `x` and `y`. ```javascript var Float32Array = require( '@stdlib/array/float32' ); @@ -63,25 +63,38 @@ var x = array( new Float32Array( [ 4.0, 2.0, -3.0, 5.0, -1.0 ] ) ); var y = array( new Float32Array( [ 2.0, 6.0, -1.0, -4.0, 8.0 ] ) ); var z = sdot( x, y ); +// returns + +var v = z.get(); // returns -5.0 ``` The function has the following parameters: -- **x**: a 1-dimensional [`ndarray`][@stdlib/ndarray/array] whose underlying data type is `float32`. -- **y**: a 1-dimensional [`ndarray`][@stdlib/ndarray/array] whose underlying data type is `float32`. +- **x**: a non-zero-dimensional [`ndarray`][@stdlib/ndarray/ctor] whose underlying data type is `float32`. Must be [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with `y`. +- **y**: a non-zero-dimensional [`ndarray`][@stdlib/ndarray/ctor] whose underlying data type is `float32`. Must be [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with `x`. +- **dim**: dimension for which to compute the dot product. Must be a negative integer. Negative indices are resolved relative to the last array dimension, with the last dimension corresponding to `-1`. Default: `-1`. -If provided empty vectors, the function returns `0.0`. +If provided at least one input [`ndarray`][@stdlib/ndarray/ctor] having more than one dimension, the input [`ndarrays`][@stdlib/ndarray/ctor] are [broadcasted][@stdlib/ndarray/base/broadcast-shapes] to a common shape. For multi-dimensional input [`ndarrays`][@stdlib/ndarray/ctor], the function performs batched computation, such that the function computes the dot product for each pair of vectors in `x` and `y` according to the specified dimension index. ```javascript var Float32Array = require( '@stdlib/array/float32' ); var array = require( '@stdlib/ndarray/array' ); -var x = array( new Float32Array() ); -var y = array( new Float32Array() ); +var opts = { + 'shape': [ 2, 3 ] +}; +var x = array( new Float32Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 3.0 ] ), opts ); +var y = array( new Float32Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 2.0 ] ), opts ); var z = sdot( x, y ); -// returns 0.0 +// returns + +var v1 = z.get( 0 ); +// returns 23.0 + +var v2 = z.get( 1 ); +// returns -22.0 ``` @@ -92,6 +105,11 @@ var z = sdot( x, y ); ## Notes +- The size of the contracted dimension must be the same for both input [`ndarrays`][@stdlib/ndarray/ctor]. +- The function resolves the dimension index for which to compute the dot product **before** broadcasting. +- Negative indices are resolved relative to the last [`ndarray`][@stdlib/ndarray/ctor] dimension, with the last dimension corresponding to `-1`. +- The output [`ndarray`][@stdlib/ndarray/ctor] has the same data type as the input [`ndarrays`][@stdlib/ndarray/ctor] and has a shape which is determined by broadcasting and excludes the contracted dimension. +- If provided empty vectors, the dot product is `0`. - `sdot()` provides a higher-level interface to the [BLAS][blas] level 1 function [`sdot`][@stdlib/blas/base/sdot]. @@ -105,27 +123,27 @@ var z = sdot( x, y ); ```javascript -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); -var Float32Array = require( '@stdlib/array/float32' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); var array = require( '@stdlib/ndarray/array' ); var sdot = require( '@stdlib/blas/sdot' ); -var x = array( new Float32Array( 10 ) ); -var y = array( new Float32Array( 10 ) ); +var opts = { + 'dtype': 'float32' +}; -var rand1 = discreteUniform.factory( 0, 100 ); -var rand2 = discreteUniform.factory( 0, 10 ); +var x = array( discreteUniform( 10, 0, 100, opts ), { + 'shape': [ 5, 2 ] +}); +console.log( ndarray2array( x ) ); -var i; -for ( i = 0; i < x.length; i++ ) { - x.set( i, rand1() ); - y.set( i, rand2() ); -} -console.log( x.toString() ); -console.log( y.toString() ); +var y = array( discreteUniform( 10, 0, 10, opts ), { + 'shape': x.shape +}); +console.log( ndarray2array( y ) ); -var z = sdot( x, y ); -console.log( z ); +var z = sdot( x, y, -1 ); +console.log( ndarray2array( z ) ); ``` @@ -136,14 +154,6 @@ console.log( z ); @@ -156,18 +166,12 @@ console.log( z ); [blas]: http://www.netlib.org/blas -[@stdlib/ndarray/array]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/ctor - +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes [@stdlib/blas/base/sdot]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/base/sdot -[@stdlib/blas/ddot]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/ddot - -[@stdlib/blas/gdot]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/gdot - - - diff --git a/lib/node_modules/@stdlib/blas/sdot/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/sdot/benchmark/benchmark.js index 1677b1f9ddd..76826c2aca9 100644 --- a/lib/node_modules/@stdlib/blas/sdot/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/sdot/benchmark/benchmark.js @@ -21,15 +21,21 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float32Array = require( '@stdlib/array/float32' ); +var uniform = require( '@stdlib/random/array/uniform' ); var array = require( '@stdlib/ndarray/array' ); var pkg = require( './../package.json' ).name; var sdot = require( './../lib/main.js' ); +// VARIABLES // + +var opts = { + 'dtype': 'float32' +}; + + // FUNCTIONS // /** @@ -40,21 +46,16 @@ var sdot = require( './../lib/main.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 < len; i++ ) { - x[ i ] = ( randu()*10.0 ) - 20.0; - y[ i ] = ( randu()*10.0 ) - 20.0; - } - x = array( x ); - y = array( y ); - + var x = array( uniform( len, -100.0, 100.0, opts ) ); + var y = array( uniform( len, -100.0, 100.0, opts ) ); return benchmark; + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ function benchmark( b ) { var d; var i; @@ -62,12 +63,12 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { d = sdot( x, y ); - if ( isnan( d ) ) { + if ( isnan( d.get() ) ) { b.fail( 'should not return NaN' ); } } b.toc(); - if ( isnan( d ) ) { + if ( isnan( d.get() ) ) { b.fail( 'should not return NaN' ); } b.pass( 'benchmark finished' ); @@ -96,7 +97,7 @@ function main() { for ( i = min; i <= max; i++ ) { len = pow( 10, i ); f = createBenchmark( len ); - bench( pkg+':len='+len, f ); + bench( pkg+'::vectors:len='+len, f ); } } diff --git a/lib/node_modules/@stdlib/blas/sdot/benchmark/benchmark.stack.js b/lib/node_modules/@stdlib/blas/sdot/benchmark/benchmark.stack.js new file mode 100644 index 00000000000..54e77ec64f6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/sdot/benchmark/benchmark.stack.js @@ -0,0 +1,122 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var numel = require( '@stdlib/ndarray/base/numel' ); +var array = require( '@stdlib/ndarray/array' ); +var pkg = require( './../package.json' ).name; +var sdot = require( './../lib/main.js' ); + + +// VARIABLES // + +var OPTS = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveIntegerArray} shape - array shape +* @returns {Function} benchmark function +*/ +function createBenchmark( shape ) { + var x; + var y; + var N; + var o; + + N = numel( shape ); + o = { + 'shape': shape + }; + x = array( uniform( N, -100.0, 100.0, OPTS ), o ); + y = array( uniform( N, -100.0, 100.0, OPTS ), o ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var d; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + d = sdot( x, y ); + if ( isnan( d.iget( 0 ) ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( d.iget( 0 ) ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var shape; + var min; + var max; + var N; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + N = pow( 10, i ); + + shape = [ 2, N/2 ]; + f = createBenchmark( shape ); + bench( pkg+'::stacks:size='+N+',ndims='+shape.length+',shape=('+shape.join( ',' )+')', f ); + + shape = [ N/2, 2 ]; + f = createBenchmark( shape ); + bench( pkg+'::stacks:size='+N+',ndims='+shape.length+',shape=('+shape.join( ',' )+')', f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/sdot/docs/repl.txt b/lib/node_modules/@stdlib/blas/sdot/docs/repl.txt index 4798baa04b1..8b4400c9e68 100644 --- a/lib/node_modules/@stdlib/blas/sdot/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/sdot/docs/repl.txt @@ -1,27 +1,52 @@ -{{alias}}( x, y ) +{{alias}}( x, y[, dim] ) Computes the dot product of two single-precision floating-point vectors. - If provided empty vectors, the function returns `0.0`. + If provided at least one input array having more than one dimension, the + input arrays are broadcasted to a common shape. + + For multi-dimensional input arrays, the function performs batched + computation, such that the function computes the dot product for each pair + of vectors in `x` and `y` according to the specified dimension index. + + The size of the contracted dimension must be the same for both input arrays. + + The function resolves the dimension index for which to compute the dot + product *before* broadcasting. + + If provided empty vectors, the dot product is `0`. Parameters ---------- x: ndarray - First input array whose underlying data type is 'float32'. + First input array. Must have a 'float32' data type. Must have at least + one dimension and be broadcast-compatible with the second input array. y: ndarray - Second input array whose underlying data type is 'float32'. + Second input array. Must have a 'float32' data type. Must have at least + one dimension and be broadcast-compatible with the first input array. + + dim: integer (optional) + Dimension index for which to compute the dot product. Must be a negative + integer. Negative indices are resolved relative to the last array + dimension, with the last dimension corresponding to `-1`. Default: -1. Returns ------- - dot: number - The dot product. + out: ndarray + The dot product. The output array has the same data type as the input + arrays and has a shape which is determined by broadcasting and excludes + the contracted dimension. Examples -------- - > var x = {{alias:@stdlib/ndarray/array}}( new {{alias:@stdlib/array/float32}}( [ 4.0, 2.0, -3.0, 5.0, -1.0 ] ) ); - > var y = {{alias:@stdlib/ndarray/array}}( new {{alias:@stdlib/array/float32}}( [ 2.0, 6.0, -1.0, -4.0, 8.0 ] ) ); - > {{alias}}( x, y ) + > var xbuf = new {{alias:@stdlib/array/float32}}( [ 4.0, 2.0, -3.0, 5.0, -1.0 ] ); + > var x = {{alias:@stdlib/ndarray/array}}( xbuf ); + > var ybuf = new {{alias:@stdlib/array/float32}}( [ 2.0, 6.0, -1.0, -4.0, 8.0 ] ); + > var y = {{alias:@stdlib/ndarray/array}}( ybuf ); + > var z = {{alias}}( x, y ) + + > z.get() -5.0 See Also diff --git a/lib/node_modules/@stdlib/blas/sdot/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/sdot/docs/types/index.d.ts index f27958f0a88..9ccb206d6e7 100644 --- a/lib/node_modules/@stdlib/blas/sdot/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/sdot/docs/types/index.d.ts @@ -20,16 +20,28 @@ /// -import { ndarray } from '@stdlib/types/ndarray'; +import { float32ndarray } from '@stdlib/types/ndarray'; /** * Computes the dot product of two single-precision floating-point vectors. * +* ## Notes +* +* - If provided at least one input array having more than one dimension, the input arrays are broadcasted to a common shape. +* - For multi-dimensional input arrays, the function performs batched computation, such that the function computes the dot product for each pair of vectors in `x` and `y` according to the specified dimension index. +* - The size of the contracted dimension must be the same for both input arrays. +* - The function resolves the dimension index for which to compute the dot product **before** broadcasting. +* - If provided empty vectors, the dot product is `0`. +* - Negative indices are resolved relative to the last array dimension, with the last dimension corresponding to `-1`. +* - The output array has the same data type as the input arrays and has a shape which is determined by broadcasting and excludes the contracted dimension. +* * @param x - first input array * @param y - second input array -* @throws first argument must be a 1-dimensional `ndarray` containing single-precision floating-point numbers -* @throws second argument must be a 1-dimensional `ndarray` containing single-precision floating-point numbers -* @throws input arrays must be the same length +* @param dim - dimension for which to compute the dot product (default: -1) +* @throws first argument must be a non-zero-dimensional ndarray containing single-precision floating-point numbers +* @throws second argument must be a non-zero-dimensional ndarray containing single-precision floating-point numbers +* @throws input arrays must be broadcast-compatible +* @throws the size of the contracted dimension must be the same for both input arrays * @returns dot product * * @example @@ -40,9 +52,12 @@ import { ndarray } from '@stdlib/types/ndarray'; * var y = array( new Float32Array( [ 2.0, 6.0, -1.0, -4.0, 8.0 ] ) ); * * var z = sdot( x, y ); +* returns +* +* var v = z.get(); * // returns -5.0 */ -declare function sdot( x: ndarray, y: ndarray ): number; +declare function sdot( x: float32ndarray, y: float32ndarray, dim?: number ): float32ndarray; // EXPORTS // diff --git a/lib/node_modules/@stdlib/blas/sdot/docs/types/test.ts b/lib/node_modules/@stdlib/blas/sdot/docs/types/test.ts index d82cf43237e..6d83c1f73f2 100644 --- a/lib/node_modules/@stdlib/blas/sdot/docs/types/test.ts +++ b/lib/node_modules/@stdlib/blas/sdot/docs/types/test.ts @@ -16,54 +16,20 @@ * limitations under the License. */ -/// - -import { ndarray } from '@stdlib/types/ndarray'; +import zeros = require( '@stdlib/ndarray/zeros' ); import sdot = require( './index' ); -/** -* Returns an ndarray object. -* -* @returns ndarray object -*/ -function createArray(): ndarray { - const arr: ndarray = { - 'byteLength': null, - 'BYTES_PER_ELEMENT': null, - 'data': new Float64Array( [ 1, 2, 3 ] ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 3, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 3 ], - 'strides': [ 1 ], - 'get': ( i: number ): any => { - return arr.data[ i ]; - }, - 'set': ( i: number, v: any ): ndarray => { - arr.data[ i ] = v; - return arr; - } - }; - return arr; -} - // TESTS // // The function returns a number... { - sdot( createArray(), createArray() ); // $ExpectType number + sdot( zeros( [ 10 ] ), zeros( [ 10 ] ) ); // $ExpectType float32ndarray } // The compiler throws an error if the function is provided a first argument which is not an ndarray... { - const y: ndarray = createArray(); + const y = zeros( [ 10 ] ); sdot( 10, y ); // $ExpectError sdot( '10', y ); // $ExpectError @@ -74,11 +40,21 @@ function createArray(): ndarray { sdot( {}, y ); // $ExpectError sdot( [], y ); // $ExpectError sdot( ( x: number ): number => x, y ); // $ExpectError + + sdot( 10, y, -1 ); // $ExpectError + sdot( '10', y, -1 ); // $ExpectError + sdot( true, y, -1 ); // $ExpectError + sdot( false, y, -1 ); // $ExpectError + sdot( null, y, -1 ); // $ExpectError + sdot( undefined, y, -1 ); // $ExpectError + sdot( {}, y, -1 ); // $ExpectError + sdot( [], y, -1 ); // $ExpectError + sdot( ( x: number ): number => x, y, -1 ); // $ExpectError } // The compiler throws an error if the function is provided a second argument which is not an ndarray... { - const x: ndarray = createArray(); + const x = zeros( [ 10 ] ); sdot( x, 10 ); // $ExpectError sdot( x, '10' ); // $ExpectError @@ -89,14 +65,38 @@ function createArray(): ndarray { sdot( x, {} ); // $ExpectError sdot( x, [] ); // $ExpectError sdot( x, ( x: number ): number => x ); // $ExpectError + + sdot( x, 10, -1 ); // $ExpectError + sdot( x, '10', -1 ); // $ExpectError + sdot( x, true, -1 ); // $ExpectError + sdot( x, false, -1 ); // $ExpectError + sdot( x, null, -1 ); // $ExpectError + sdot( x, undefined, -1 ); // $ExpectError + sdot( x, {}, -1 ); // $ExpectError + sdot( x, [], -1 ); // $ExpectError + sdot( x, ( x: number ): number => x, -1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + const x = zeros( [ 10 ] ); + const y = zeros( [ 10 ] ); + + sdot( x, y, '10' ); // $ExpectError + sdot( x, y, true ); // $ExpectError + sdot( x, y, false ); // $ExpectError + sdot( x, y, null ); // $ExpectError + sdot( x, y, {} ); // $ExpectError + sdot( x, y, [] ); // $ExpectError + sdot( x, y, ( x: number ): number => x ); // $ExpectError } // The compiler throws an error if the function is provided an unsupported number of arguments... { - const x: ndarray = createArray(); - const y: ndarray = createArray(); + const x = zeros( [ 10 ] ); + const y = zeros( [ 10 ] ); sdot(); // $ExpectError sdot( x ); // $ExpectError - sdot( x, y, {} ); // $ExpectError + sdot( x, y, -1, {} ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/blas/sdot/examples/index.js b/lib/node_modules/@stdlib/blas/sdot/examples/index.js index aff21f3b3dc..24e81091612 100644 --- a/lib/node_modules/@stdlib/blas/sdot/examples/index.js +++ b/lib/node_modules/@stdlib/blas/sdot/examples/index.js @@ -18,24 +18,24 @@ 'use strict'; -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); -var Float32Array = require( '@stdlib/array/float32' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); var array = require( '@stdlib/ndarray/array' ); var sdot = require( './../lib' ); -var x = array( new Float32Array( 10 ) ); -var y = array( new Float32Array( 10 ) ); +var opts = { + 'dtype': 'float32' +}; -var rand1 = discreteUniform.factory( 0, 100 ); -var rand2 = discreteUniform.factory( 0, 10 ); +var x = array( discreteUniform( 10, 0, 100, opts ), { + 'shape': [ 5, 2 ] +}); +console.log( ndarray2array( x ) ); -var i; -for ( i = 0; i < x.length; i++ ) { - x.set( i, rand1() ); - y.set( i, rand2() ); -} -console.log( x.toString() ); -console.log( y.toString() ); +var y = array( discreteUniform( 10, 0, 10, opts ), { + 'shape': x.shape +}); +console.log( ndarray2array( y ) ); -var z = sdot( x, y ); -console.log( z ); +var z = sdot( x, y, -1 ); +console.log( ndarray2array( z ) ); diff --git a/lib/node_modules/@stdlib/blas/sdot/lib/index.js b/lib/node_modules/@stdlib/blas/sdot/lib/index.js index 6bac672f22a..816cc4e2780 100644 --- a/lib/node_modules/@stdlib/blas/sdot/lib/index.js +++ b/lib/node_modules/@stdlib/blas/sdot/lib/index.js @@ -32,6 +32,9 @@ * var y = array( new Float32Array( [ 2.0, 6.0, -1.0, -4.0, 8.0 ] ) ); * * var z = sdot( x, y ); +* // returns +* +* var v = z.get(); * // returns -5.0 */ diff --git a/lib/node_modules/@stdlib/blas/sdot/lib/main.js b/lib/node_modules/@stdlib/blas/sdot/lib/main.js index b78c2cbeac0..14ead748b61 100644 --- a/lib/node_modules/@stdlib/blas/sdot/lib/main.js +++ b/lib/node_modules/@stdlib/blas/sdot/lib/main.js @@ -20,8 +20,17 @@ // MODULES // -var isFloat32VectorLike = require( '@stdlib/assert/is-float32vector-like' ); -var dot = require( '@stdlib/blas/base/sdot' ).ndarray; +var isFloat32ndarrayLike = require( '@stdlib/assert/is-float32ndarray-like' ); +var isNegativeInteger = require( '@stdlib/assert/is-negative-integer' ).isPrimitive; +var min = require( '@stdlib/math/base/special/fast/min' ); +var without = require( '@stdlib/array/base/without' ); +var numel = require( '@stdlib/ndarray/base/numel' ); +var normalizeIndex = require( '@stdlib/ndarray/base/normalize-index' ); +var maybeBroadcastArrays = require( '@stdlib/ndarray/base/maybe-broadcast-arrays' ); +var ndarraylike2ndarray = require( '@stdlib/ndarray/base/ndarraylike2ndarray' ); +var nditerStacks = require( '@stdlib/ndarray/iter/stacks' ); +var empty = require( '@stdlib/ndarray/empty' ); +var base = require( '@stdlib/blas/base/sdot' ).ndarray; var format = require( '@stdlib/string/format' ); @@ -30,12 +39,18 @@ var format = require( '@stdlib/string/format' ); /** * Computes the dot product of two single-precision floating-point vectors. * -* @param {VectorLike} x - first input array -* @param {VectorLike} y - second input array -* @throws {TypeError} first argument must be a 1-dimensional ndarray containing single-precision floating-point numbers -* @throws {TypeError} second argument must be a 1-dimensional ndarray containing single-precision floating-point numbers -* @throws {RangeError} input arrays must be the same length -* @returns {number} dot product +* @param {ndarrayLike} x - first input array +* @param {ndarrayLike} y - second input array +* @param {NegativeInteger} [dim] - dimension for which to compute the dot product +* @throws {TypeError} first argument must be a ndarray containing single-precision floating-point numbers +* @throws {TypeError} first argument must have at least one dimension +* @throws {TypeError} second argument must be a ndarray containing single-precision floating-point numbers +* @throws {TypeError} second argument must have at least one dimension +* @throws {TypeError} third argument must be a negative integer +* @throws {Error} input arrays must be broadcast compatible +* @throws {RangeError} the size of the contracted dimension must be the same for both input arrays +* @throws {RangeError} third argument is out-of-bounds +* @returns {ndarray} ndarray containing the dot product * * @example * var Float32Array = require( '@stdlib/array/float32' ); @@ -45,19 +60,106 @@ var format = require( '@stdlib/string/format' ); * var y = array( new Float32Array( [ 2.0, 6.0, -1.0, -4.0, 8.0 ] ) ); * * var z = sdot( x, y ); +* // returns +* +* var v = z.get(); * // returns -5.0 */ function sdot( x, y ) { - if ( !isFloat32VectorLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a one-dimensional ndarray containing single-precision floating-point numbers (i.e., an ndarray whose underlying data buffer is a Float32Array). Value: `%s`.', x ) ); + var dim; + var xsh; + var ysh; + var osh; + var xit; + var yit; + var out; + var tmp; + var xc; + var yc; + var vx; + var vy; + var dm; + var S; + var v; + var i; + + if ( !isFloat32ndarrayLike( x ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an ndarray containing single-precision floating-point numbers. Value: `%s`.', x ) ); + } + if ( !isFloat32ndarrayLike( y ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be an ndarray containing single-precision floating-point numbers. Value: `%s`.', y ) ); + } + // Convert the input arrays to "base" ndarrays: + xc = ndarraylike2ndarray( x ); + yc = ndarraylike2ndarray( y ); + + // Resolve the input array shapes: + xsh = xc.shape; + ysh = yc.shape; + + // Validate that we've been provided non-zero-dimensional arrays... + if ( xsh.length < 1 ) { + throw new TypeError( format( 'invalid argument. First argument must have at least one dimension.' ) ); + } + if ( ysh.length < 1 ) { + throw new TypeError( format( 'invalid argument. Second argument must have at least one dimension.' ) ); + } + // Validate that the dimension argument is a negative integer... + if ( arguments.length > 2 ) { + dim = arguments[ 2 ]; + if ( !isNegativeInteger( dim ) ) { + throw new TypeError( format( 'invalid argument. Third argument must be a negative integer. Value: `%s`.', dim ) ); + } + } else { + dim = -1; } - if ( !isFloat32VectorLike( y ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a one-dimensional ndarray containing single-precision floating-point numbers (i.e., an ndarray whose underlying data buffer is a Float32Array). Value: `%s`.', y ) ); + // Validate that a provided dimension index is within bounds **before** broadcasting... + dm = min( xsh.length, ysh.length ) - 1; + dim = normalizeIndex( dim, dm ); + if ( dim === -1 ) { + throw new RangeError( format( 'invalid argument. Third argument must be a value on the interval: [%d,%d]. Value: `%d`.', -dm, -1, arguments[ 2 ] ) ); } - if ( x.length !== y.length ) { - throw new RangeError( format( 'invalid argument. Arrays must be the same length. First argument length: `%u`. Second argument length: `%u`.', x.length, y.length ) ); + // Validate that the contracted dimension size is the same for both input arrays... + S = xsh[ dim ]; + if ( ysh[ dim ] !== S ) { + throw new RangeError( format( 'invalid argument. The size of the contracted dimension must be the same for both input ndarrays. Dim(%s,%d) = %d. Dim(%s,%d) = %d.', 'x', dim, S, 'y', dim, ysh[ dim ] ) ); + } + // Broadcast the input arrays to a common shape.... + try { + tmp = maybeBroadcastArrays( [ xc, yc ] ); + } catch ( err ) { // eslint-disable-line no-unused-vars + throw new Error( format( 'invalid arguments. Input ndarrays must be broadcast compatible. Shape(%s) = (%s). Shape(%s) = (%s).', 'x', xsh.join( ',' ), 'y', ysh.join( ',' ) ) ); + } + xc = tmp[ 0 ]; + yc = tmp[ 1 ]; + + // Resolve the output array shape by excluding the contracted dimension: + osh = without( xc.shape, dim ); + + // Allocate an empty output array: + out = empty( osh, { + 'dtype': xc.dtype, + 'order': xc.order + }); + + // If we are only provided one-dimensional input arrays, we can skip iterating over stacks... + if ( osh.length === 0 ) { + v = base( S, xc.data, xc.strides[0], xc.offset, yc.data, yc.strides[0], yc.offset ); // eslint-disable-line max-len + out.iset( v ); + return out; + } + // Create iterators for iterating over stacks of vectors: + xit = nditerStacks( xc, [ dim ] ); + yit = nditerStacks( yc, [ dim ] ); + + // Compute the dot product for each pair of vectors... + for ( i = 0; i < numel( osh ); i++ ) { + vx = xit.next().value; + vy = yit.next().value; + v = base( S, vx.data, vx.strides[0], vx.offset, vy.data, vy.strides[0], vy.offset ); // eslint-disable-line max-len + out.iset( i, v ); } - return dot( x.length, x.data, x.strides[ 0 ], x.offset, y.data, y.strides[ 0 ], y.offset ); // eslint-disable-line max-len + return out; } diff --git a/lib/node_modules/@stdlib/blas/sdot/test/test.js b/lib/node_modules/@stdlib/blas/sdot/test/test.js index 0c2076ecf65..700203559c7 100644 --- a/lib/node_modules/@stdlib/blas/sdot/test/test.js +++ b/lib/node_modules/@stdlib/blas/sdot/test/test.js @@ -21,10 +21,13 @@ // MODULES // var tape = require( 'tape' ); -var Float32Array = require( '@stdlib/array/float32' ); var Float64Array = require( '@stdlib/array/float64' ); +var Float32Array = require( '@stdlib/array/float32' ); var array = require( '@stdlib/ndarray/array' ); +var zeros = require( '@stdlib/ndarray/zeros' ); var ndarray = require( '@stdlib/ndarray/ctor' ); +var ndims = require( '@stdlib/ndarray/ndims' ); +var shape = require( '@stdlib/ndarray/shape' ); var sdot = require( './../lib' ); @@ -41,7 +44,7 @@ tape( 'the function has an arity of 2', function test( t ) { t.end(); }); -tape( 'the function throws an error if provided a first argument which is not a 1-dimensional ndarray containing single-precision floating-point numbers', function test( t ) { +tape( 'the function throws an error if provided a first argument which is not a non-zero-dimensional ndarray containing double-precision floating-point numbers', function test( t ) { var values; var i; @@ -55,6 +58,9 @@ tape( 'the function throws an error if provided a first argument which is not a {}, [], function noop() {}, + zeros( [], { + 'dtype': 'float32' + }), array( new Float64Array( 10 ) ) ]; @@ -72,7 +78,7 @@ tape( 'the function throws an error if provided a first argument which is not a } }); -tape( 'the function throws an error if provided a second argument which is not a 1-dimensional ndarray containing single-precision floating-point numbers', function test( t ) { +tape( 'the function throws an error if provided a first argument which is not a non-zero-dimensional ndarray containing double-precision floating-point numbers (dimension)', function test( t ) { var values; var i; @@ -86,6 +92,43 @@ tape( 'the function throws an error if provided a second argument which is not a {}, [], function noop() {}, + zeros( [], { + 'dtype': 'float32' + }), + array( new Float64Array( 10 ) ) + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + var y = array( new Float32Array( 10 ) ); + + return function badValue() { + sdot( value, y, -1 ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not a non-zero-dimensional ndarray containing double-precision floating-point numbers', function test( t ) { + var values; + var i; + + values = [ + 5, + '5', + true, + false, + null, + void 0, + {}, + [], + function noop() {}, + zeros( [], { + 'dtype': 'float32' + }), array( new Float64Array( 10 ) ) ]; @@ -103,7 +146,167 @@ tape( 'the function throws an error if provided a second argument which is not a } }); -tape( 'the function throws an error if provided unequal length vectors', function test( t ) { +tape( 'the function throws an error if provided a second argument which is not a non-zero-dimensional ndarray containing double-precision floating-point numbers (dimension)', function test( t ) { + var values; + var i; + + values = [ + 5, + '5', + true, + false, + null, + void 0, + {}, + [], + function noop() {}, + zeros( [], { + 'dtype': 'float32' + }), + array( new Float64Array( 10 ) ) + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + var x = array( new Float32Array( 10 ) ); + + return function badValue() { + sdot( x, value, -1 ); + }; + } +}); + +tape( 'the function throws an error if provided a third argument which is not a negative integer (vectors)', function test( t ) { + var values; + var i; + + values = [ + '5', + 0, + 5, + NaN, + -3.14, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + var x = array( new Float32Array( 10 ) ); + var y = array( new Float32Array( 10 ) ); + + return function badValue() { + sdot( x, y, value ); + }; + } +}); + +tape( 'the function throws an error if provided a third argument which is not a negative integer (multi-dimensional arrays)', function test( t ) { + var values; + var i; + + values = [ + '5', + 0, + 5, + NaN, + -3.14, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + var opts = { + 'shape': [ 2, 5 ] + }; + var x = array( new Float32Array( 10 ), opts ); + var y = array( new Float32Array( 10 ), opts ); + + return function badValue() { + sdot( x, y, value ); + }; + } +}); + +tape( 'the function throws an error if provided a third argument which is out-of-bounds (vectors)', function test( t ) { + var values; + var i; + + values = [ + -2, + -3, + -4, + -5 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + var x = array( new Float32Array( 10 ) ); + var y = array( new Float32Array( 10 ) ); + + return function badValue() { + sdot( x, y, value ); + }; + } +}); + +tape( 'the function throws an error if provided a third argument which is out-of-bounds (multi-dimensional arrays)', function test( t ) { + var values; + var i; + + values = [ + -3, + -4, + -5, + -10 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + var opts = { + 'shape': [ 2, 5 ] + }; + var x = array( new Float32Array( 10 ), opts ); + var y = array( new Float32Array( 10 ), opts ); + + return function badValue() { + sdot( x, y, value ); + }; + } +}); + +tape( 'the function throws an error if provided arrays having an unequal contracted dimension (vectors)', function test( t ) { t.throws( badValue, RangeError, 'throws an error' ); t.end(); @@ -113,6 +316,37 @@ tape( 'the function throws an error if provided unequal length vectors', functio sdot( x, y ); } }); + +tape( 'the function throws an error if provided arrays having an unequal contracted dimension (multi-dimensional)', function test( t ) { + t.throws( badValue, RangeError, 'throws an error' ); + t.end(); + + function badValue() { + var x = array( new Float32Array( 100 ), { + 'shape': [ 25, 4 ] + }); + var y = array( new Float32Array( 100 ), { + 'shape': [ 50, 2 ] + }); + sdot( x, y, -1 ); + } +}); + +tape( 'the function throws an error if provided broadcast-incompatible input arrays', function test( t ) { + t.throws( badValue, Error, 'throws an error' ); + t.end(); + + function badValue() { + var x = array( new Float32Array( 100 ), { + 'shape': [ 5, 10, 2 ] + }); + var y = array( new Float32Array( 100 ), { + 'shape': [ 50, 1, 2 ] + }); + sdot( x, y, -1 ); + } +}); + tape( 'the function calculates the dot product of vectors `x` and `y`', function test( t ) { var dot; var x; @@ -125,12 +359,132 @@ tape( 'the function calculates the dot product of vectors `x` and `y`', function y = array( y ); dot = sdot( x, y ); - t.strictEqual( dot, -17.0, 'returns expected value' ); + + t.strictEqual( dot instanceof ndarray, true, 'returns expected value' ); + t.strictEqual( ndims( dot ), ndims( x )-1, 'returns expected value' ); + t.deepEqual( shape( dot ), [], 'returns expected value' ); + t.strictEqual( dot.get(), -17.0, 'returns expected value' ); t.end(); }); -tape( 'if provided empty vectors, the function returns `0`', function test( t ) { +tape( 'the function supports operating on stacks of vectors (default)', function test( t ) { + var opts; + var dot; + var x; + var y; + + x = new Float32Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 2.0, -5.0, 6.0 ] ); + y = new Float32Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 8.0, 2.0, -3.0 ] ); + + opts = { + 'shape': [ 4, 2 ] + }; + x = array( x, opts ); + y = array( y, opts ); + + dot = sdot( x, y ); + + t.strictEqual( dot instanceof ndarray, true, 'returns expected value' ); + t.strictEqual( ndims( dot ), ndims( x )-1, 'returns expected value' ); + t.deepEqual( shape( dot ), [ 4 ], 'returns expected value' ); + t.strictEqual( dot.get( 0 ), 20.0, 'returns expected value' ); + t.strictEqual( dot.get( 1 ), -17.0, 'returns expected value' ); + t.strictEqual( dot.get( 2 ), 8.0, 'returns expected value' ); + t.strictEqual( dot.get( 3 ), -28.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports operating on stacks of vectors (dim=-1)', function test( t ) { + var opts; + var dot; + var x; + var y; + + x = new Float32Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 2.0, -5.0, 6.0 ] ); + y = new Float32Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 8.0, 2.0, -3.0 ] ); + + opts = { + 'shape': [ 4, 2 ] + }; + x = array( x, opts ); + y = array( y, opts ); + + dot = sdot( x, y, -1 ); + + t.strictEqual( dot instanceof ndarray, true, 'returns expected value' ); + t.strictEqual( ndims( dot ), ndims( x )-1, 'returns expected value' ); + t.deepEqual( shape( dot ), [ 4 ], 'returns expected value' ); + t.strictEqual( dot.get( 0 ), 20.0, 'returns expected value' ); + t.strictEqual( dot.get( 1 ), -17.0, 'returns expected value' ); + t.strictEqual( dot.get( 2 ), 8.0, 'returns expected value' ); + t.strictEqual( dot.get( 3 ), -28.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports operating on stacks of vectors (dim=-2)', function test( t ) { + var opts; + var dot; + var x; + var y; + + x = new Float32Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 2.0, -5.0, 6.0 ] ); + y = new Float32Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 8.0, 2.0, -3.0 ] ); + + opts = { + 'shape': [ 2, 4 ] + }; + x = array( x, opts ); + y = array( y, opts ); + + dot = sdot( x, y, -2 ); + + t.strictEqual( dot instanceof ndarray, true, 'returns expected value' ); + t.strictEqual( ndims( dot ), ndims( x )-1, 'returns expected value' ); + t.deepEqual( shape( dot ), [ 4 ], 'returns expected value' ); + t.strictEqual( dot.get( 0 ), 0.0, 'returns expected value' ); + t.strictEqual( dot.get( 1 ), 28.0, 'returns expected value' ); + t.strictEqual( dot.get( 2 ), -7.0, 'returns expected value' ); + t.strictEqual( dot.get( 3 ), -38.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports broadcasting', function test( t ) { + var opts; + var dot; + var x; + var y; + + x = new Float32Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 2.0, -5.0, 6.0 ] ); + y = new Float32Array( [ 2.0, 6.0 ] ); + + opts = { + 'shape': [ 4, 2 ] + }; + x = array( x, opts ); + + opts = { + 'shape': [ 1, 2 ] + }; + y = array( y, opts ); + + dot = sdot( x, y, -1 ); + + t.strictEqual( dot instanceof ndarray, true, 'returns expected value' ); + t.strictEqual( ndims( dot ), ndims( x )-1, 'returns expected value' ); + t.deepEqual( shape( dot ), [ 4 ], 'returns expected value' ); + t.strictEqual( dot.get( 0 ), 20.0, 'returns expected value' ); + t.strictEqual( dot.get( 1 ), 24.0, 'returns expected value' ); + t.strictEqual( dot.get( 2 ), 10.0, 'returns expected value' ); + t.strictEqual( dot.get( 3 ), 26.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided empty vectors, the dot product is `0`', function test( t ) { var dot; var x; var y; @@ -142,7 +496,11 @@ tape( 'if provided empty vectors, the function returns `0`', function test( t ) y = array( y ); dot = sdot( x, y ); - t.strictEqual( dot, 0.0, 'returns expected value' ); + + t.strictEqual( dot instanceof ndarray, true, 'returns expected value' ); + t.strictEqual( ndims( dot ), ndims( x )-1, 'returns expected value' ); + t.deepEqual( shape( dot ), [], 'returns expected value' ); + t.strictEqual( dot.get(), 0.0, 'returns expected value' ); t.end(); }); @@ -169,7 +527,11 @@ tape( 'the function supports a strided vector for the first argument', function y = ndarray( 'float32', y, [ 3 ], [ 1 ], 0, 'row-major' ); dot = sdot( x, y ); - t.strictEqual( dot, -12.0, 'returns expected value' ); + + t.strictEqual( dot instanceof ndarray, true, 'returns expected value' ); + t.strictEqual( ndims( dot ), ndims( x )-1, 'returns expected value' ); + t.deepEqual( shape( dot ), [], 'returns expected value' ); + t.strictEqual( dot.get(), -12.0, 'returns expected value' ); t.end(); }); @@ -197,7 +559,11 @@ tape( 'the function supports a strided vector for the second argument', function y = ndarray( 'float32', y, [ 3 ], [ 2 ], 0, 'row-major' ); dot = sdot( x, y ); - t.strictEqual( dot, 45.0, 'returns expected value' ); + + t.strictEqual( dot instanceof ndarray, true, 'returns expected value' ); + t.strictEqual( ndims( dot ), ndims( x )-1, 'returns expected value' ); + t.deepEqual( shape( dot ), [], 'returns expected value' ); + t.strictEqual( dot.get(), 45.0, 'returns expected value' ); t.end(); }); @@ -224,7 +590,11 @@ tape( 'the function supports negative strides', function test( t ) { y = ndarray( 'float32', y, [ 3 ], [ -1 ], y.length-1, 'row-major' ); dot = sdot( x, y ); - t.strictEqual( dot, 67.0, 'returns expected value' ); + + t.strictEqual( dot instanceof ndarray, true, 'returns expected value' ); + t.strictEqual( ndims( dot ), ndims( x )-1, 'returns expected value' ); + t.deepEqual( shape( dot ), [], 'returns expected value' ); + t.strictEqual( dot.get(), 67.0, 'returns expected value' ); t.end(); }); @@ -251,7 +621,11 @@ tape( 'the function supports complex access patterns', function test( t ) { y = ndarray( 'float32', y, [ 3 ], [ -1 ], y.length-1, 'row-major' ); dot = sdot( x, y ); - t.strictEqual( dot, 59.0, 'returns expected value' ); + + t.strictEqual( dot instanceof ndarray, true, 'returns expected value' ); + t.strictEqual( ndims( dot ), ndims( x )-1, 'returns expected value' ); + t.deepEqual( shape( dot ), [], 'returns expected value' ); + t.strictEqual( dot.get(), 59.0, 'returns expected value' ); t.end(); }); @@ -281,7 +655,11 @@ tape( 'the function supports strided vectors having offsets', function test( t ) y = ndarray( 'float32', y, [ 3 ], [ 1 ], 2, 'row-major' ); dot = sdot( x, y ); - t.strictEqual( dot, -12.0, 'returns expected value' ); + + t.strictEqual( dot instanceof ndarray, true, 'returns expected value' ); + t.strictEqual( ndims( dot ), ndims( x )-1, 'returns expected value' ); + t.deepEqual( shape( dot ), [], 'returns expected value' ); + t.strictEqual( dot.get(), -12.0, 'returns expected value' ); t.end(); }); @@ -317,7 +695,11 @@ tape( 'the function supports underlying data buffers with view offsets', functio y1 = ndarray( 'float32', y1, [ 3 ], [ 1 ], 0, 'row-major' ); dot = sdot( x1, y1 ); - t.strictEqual( dot, 124.0, 'returns expected value' ); + + t.strictEqual( dot instanceof ndarray, true, 'returns expected value' ); + t.strictEqual( ndims( dot ), ndims( x1 )-1, 'returns expected value' ); + t.deepEqual( shape( dot ), [], 'returns expected value' ); + t.strictEqual( dot.get(), 124.0, 'returns expected value' ); t.end(); });