From 1b1de6f590296772bbef449c46ae7dbf72fe84a3 Mon Sep 17 00:00:00 2001 From: aman-095 Date: Fri, 13 Sep 2024 12:09:48 +0530 Subject: [PATCH 1/5] refactor: add support for stack --- lib/node_modules/@stdlib/blas/sswap/README.md | 85 ++-- .../blas/sswap/benchmark/benchmark.stack.js | 122 ++++++ .../@stdlib/blas/sswap/examples/index.js | 30 +- .../@stdlib/blas/sswap/lib/main.js | 111 +++++- .../@stdlib/blas/sswap/test/test.js | 377 +++++++++++++++++- 5 files changed, 657 insertions(+), 68 deletions(-) create mode 100644 lib/node_modules/@stdlib/blas/sswap/benchmark/benchmark.stack.js diff --git a/lib/node_modules/@stdlib/blas/sswap/README.md b/lib/node_modules/@stdlib/blas/sswap/README.md index e40934dbd90..81d0baf2c3d 100644 --- a/lib/node_modules/@stdlib/blas/sswap/README.md +++ b/lib/node_modules/@stdlib/blas/sswap/README.md @@ -36,7 +36,7 @@ limitations under the License. var sswap = require( '@stdlib/blas/sswap' ); ``` -#### sswap( x, y ) +#### sswap( x, y\[, dim] ) Interchanges two single-precision floating-point vectors `x` and `y`. @@ -58,8 +58,36 @@ var ybuf = y.data; 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 have the same shape as `y`. +- **y**: a non-zero-dimensional [`ndarray`][@stdlib/ndarray/ctor] whose underlying data type is `float32`. Must have the same shape as `x`. +- **dim**: dimension along which to interchange vectors. Must be a negative integer. Negative indices are resolved relative to the last array dimension, with the last dimension corresponding to `-1`. Default: `-1`. + +For multi-dimensional input [`ndarrays`][@stdlib/ndarray/ctor], the function performs batched computation, such that the function interchanges 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 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 v1 = x.get( 0, 0 ); +// returns 4.0 + +var v2 = y.get( 0, 0 ); +// returns 2.0 + +sswap( x, y ); + +v1 = x.get( 0, 0 ); +// returns 2.0 + +v2 = y.get( 0, 0 ); +// returns 4.0 +``` @@ -69,6 +97,9 @@ The function has the following parameters: ## Notes +- Both input [`ndarrays`][@stdlib/ndarray/ctor] must have the same shape. +- Negative indices are resolved relative to the last [`ndarray`][@stdlib/ndarray/ctor] dimension, with the last dimension corresponding to `-1`. +- For multi-dimensional [`ndarrays`][@stdlib/ndarray/ctor], batched computation effectively means swapping all of `x` with all of `y`; however, the choice of `dim` will significantly affect performance. For best performance, specify a `dim` which best aligns with the [memory layout][@stdlib/ndarray/orders] of provided [`ndarrays`][@stdlib/ndarray/ctor]. - `sswap()` provides a higher-level interface to the [BLAS][blas] level 1 function [`sswap`][@stdlib/blas/base/sswap]. @@ -82,28 +113,28 @@ The function has the following parameters: ```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 sswap = require( '@stdlib/blas/sswap' ); -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.data ); -console.log( y.data ); +var y = array( discreteUniform( 10, 0, 10, opts ), { + 'shape': x.shape +}); +console.log( ndarray2array( y ) ); sswap( x, y ); -console.log( x.data ); -console.log( y.data ); +console.log( ndarray2array( x ) ); +console.log( ndarray2array( y ) ); ``` @@ -114,14 +145,6 @@ console.log( y.data ); @@ -132,18 +155,12 @@ console.log( y.data ); [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/orders]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/orders [@stdlib/blas/base/sswap]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/base/sswap -[@stdlib/blas/dswap]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/dswap - -[@stdlib/blas/gswap]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/gswap - - - diff --git a/lib/node_modules/@stdlib/blas/sswap/benchmark/benchmark.stack.js b/lib/node_modules/@stdlib/blas/sswap/benchmark/benchmark.stack.js new file mode 100644 index 00000000000..f027899c21d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/sswap/benchmark/benchmark.stack.js @@ -0,0 +1,122 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 sswap = 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 = sswap( x, y ); + if ( isnan( d.data[ i%N ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( d.data[ i%N ] ) ) { + 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/sswap/examples/index.js b/lib/node_modules/@stdlib/blas/sswap/examples/index.js index 21152f317c5..21d7bf228d6 100644 --- a/lib/node_modules/@stdlib/blas/sswap/examples/index.js +++ b/lib/node_modules/@stdlib/blas/sswap/examples/index.js @@ -18,25 +18,25 @@ '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 sswap = 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.data ); -console.log( y.data ); +var y = array( discreteUniform( 10, 0, 10, opts ), { + 'shape': x.shape +}); +console.log( ndarray2array( y ) ); sswap( x, y ); -console.log( x.data ); -console.log( y.data ); +console.log( ndarray2array( x ) ); +console.log( ndarray2array( y ) ); diff --git a/lib/node_modules/@stdlib/blas/sswap/lib/main.js b/lib/node_modules/@stdlib/blas/sswap/lib/main.js index 1c85384eabe..b33a393556b 100644 --- a/lib/node_modules/@stdlib/blas/sswap/lib/main.js +++ b/lib/node_modules/@stdlib/blas/sswap/lib/main.js @@ -20,9 +20,18 @@ // MODULES // -var isFloat32VectorLike = require( '@stdlib/assert/is-float32vector-like' ); +var isFloat32ndarrayLike = require( '@stdlib/assert/is-float32ndarray-like' ); +var isNegativeInteger = require( '@stdlib/assert/is-negative-integer' ).isPrimitive; +var isReadOnly = require( '@stdlib/ndarray/base/assert/is-read-only' ); +var hasEqualValues = require( '@stdlib/array/base/assert/has-equal-values-indexed' ); +var min = require( '@stdlib/math/base/special/fast/min' ); +var without = require( '@stdlib/array/base/without' ); +var ndarraylike2ndarray = require( '@stdlib/ndarray/base/ndarraylike2ndarray' ); +var normalizeIndex = require( '@stdlib/ndarray/base/normalize-index' ); +var nditerStacks = require( '@stdlib/ndarray/iter/stacks' ); +var numel = require( '@stdlib/ndarray/base/numel' ); +var base = require( '@stdlib/blas/base/sswap' ).ndarray; var format = require( '@stdlib/string/format' ); -var swap = require( '@stdlib/blas/base/sswap' ).ndarray; // MAIN // @@ -30,12 +39,17 @@ var swap = require( '@stdlib/blas/base/sswap' ).ndarray; /** * Interchanges 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 {VectorLike} `y` +* @param {ndarrayLike} x - first input array +* @param {ndarrayLike} y - second input array +* @param {NegativeInteger} [dim] - dimension along which to interchange elements +* @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 {Error} both input arrays must have the same shape +* @throws {RangeError} third argument is out-of-bounds +* @throws {Error} cannot write to read-only array +* @returns {ndarrayLike} `y` * * @example * var Float32Array = require( '@stdlib/array/float32' ); @@ -53,16 +67,83 @@ var swap = require( '@stdlib/blas/base/sswap' ).ndarray; * // returns [ 4.0, 2.0, -3.0, 5.0, -1.0 ] */ function sswap( 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 xit; + var yit; + var xc; + var yc; + var vx; + var vy; + var dm; + var S; + var N; + 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 ( !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 ) ); + if ( !isFloat32ndarrayLike( y ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be an ndarray containing single-precision floating-point numbers. Value: `%s`.', y ) ); } - 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 ) ); + if ( isReadOnly( x ) || isReadOnly( y ) ) { + throw new Error( 'invalid argument. Cannot write to read-only array.' ); + } + // 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 arrays have the same shape... + if ( !hasEqualValues( xsh, ysh ) ) { + throw new Error( 'invalid arguments. The first and second arguments must have the shape.' ); + } + // 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; + } + // Validate that a provided dimension index is within bounds... + 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 ] ) ); + } + // Resolve the size of the interchange dimension: + S = xsh[ dim ]; + + // If we are only provided one-dimensional input arrays, we can skip iterating over stacks... + if ( xsh.length === 1 ) { + base( S, xc.data, xc.strides[0], xc.offset, yc.data, yc.strides[0], yc.offset ); // eslint-disable-line max-len + return y; + } + // Resolve the number of stacks: + N = numel( without( xsh, dim ) ); + + // Create iterators for iterating over stacks of vectors: + xit = nditerStacks( xc, [ dim ] ); + yit = nditerStacks( yc, [ dim ] ); + + // Interchange each pair of vectors... + for ( i = 0; i < N; i++ ) { + vx = xit.next().value; + vy = yit.next().value; + base( S, vx.data, vx.strides[0], vx.offset, vy.data, vy.strides[0], vy.offset ); // eslint-disable-line max-len } - swap( x.length, x.data, x.strides[ 0 ], x.offset, y.data, y.strides[ 0 ], y.offset ); // eslint-disable-line max-len return y; } diff --git a/lib/node_modules/@stdlib/blas/sswap/test/test.js b/lib/node_modules/@stdlib/blas/sswap/test/test.js index db2a66dfee6..ff86e569bf3 100644 --- a/lib/node_modules/@stdlib/blas/sswap/test/test.js +++ b/lib/node_modules/@stdlib/blas/sswap/test/test.js @@ -24,6 +24,7 @@ var tape = require( 'tape' ); var Float32Array = require( '@stdlib/array/float32' ); var Int16Array = require( '@stdlib/array/int16' ); var array = require( '@stdlib/ndarray/array' ); +var zeros = require( '@stdlib/ndarray/zeros' ); var ndarray = require( '@stdlib/ndarray/ctor' ); var scopy = require( '@stdlib/blas/base/scopy' ).ndarray; var sswap = require( './../lib' ); @@ -42,7 +43,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 +56,9 @@ tape( 'the function throws an error if provided a first argument which is not a void 0, {}, function noop() {}, + zeros( [], { + 'dtype': 'float32' + }), array( new Int16Array( 10 ) ) ]; @@ -72,7 +76,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; @@ -85,6 +89,70 @@ tape( 'the function throws an error if provided a second argument which is not a void 0, {}, function noop() {}, + zeros( [], { + 'dtype': 'float32' + }), + array( new Int16Array( 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() { + sswap( value, y, -1 ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is a read-only ndarray', function test( t ) { + var values; + var opts; + var i; + + opts = { + 'readonly': true + }; + + values = [ + array( new Float32Array( 10 ), opts ), + array( new Float32Array( 5 ), opts ) + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + var y = array( new Float32Array( value.length ) ); + + return function badValue() { + sswap( value, y ); + }; + } +}); + +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 Int16Array( 10 ) ) ]; @@ -102,8 +170,195 @@ 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 ) { - t.throws( badValue, RangeError, 'throws an error' ); +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 Int16Array( 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() { + sswap( x, value, -1 ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is a read-only ndarray', function test( t ) { + var values; + var opts; + var i; + + opts = { + 'readonly': true + }; + + values = [ + array( new Float32Array( 10 ), opts ), + array( new Float32Array( 5 ), opts ) + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + var x = array( new Float32Array( value.length ) ); + + return function badValue() { + sswap( x, value ); + }; + } +}); + +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() { + sswap( 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() { + sswap( 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() { + sswap( 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() { + sswap( x, y, value ); + }; + } +}); + +tape( 'the function throws an error if provided arrays having different shapes (vectors)', function test( t ) { + t.throws( badValue, Error, 'throws an error' ); t.end(); function badValue() { @@ -113,6 +368,21 @@ tape( 'the function throws an error if provided unequal length vectors', functio } }); +tape( 'the function throws an error if provided arrays having different shapes (multi-dimensional)', function test( t ) { + t.throws( badValue, Error, '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 ] + }); + sswap( x, y, -1 ); + } +}); + tape( 'the function interchanges vectors `x` and `y`', function test( t ) { var xe; var ye; @@ -142,6 +412,105 @@ tape( 'the function interchanges vectors `x` and `y`', function test( t ) { t.end(); }); +tape( 'the function supports operating on stacks of vectors (default)', function test( t ) { + var opts; + var xe; + var ye; + 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 ] ); + + xe = new Float32Array( y.length ); + scopy( y.length, y, 1, 0, xe, 1, 0 ); + + ye = new Float32Array( x.length ); + scopy( x.length, x, 1, 0, ye, 1, 0 ); + + opts = { + 'shape': [ 4, 2 ] + }; + x = array( x, opts ); + y = array( y, opts ); + + sswap( x, y ); + + t.deepEqual( x.data, xe, 'deep equal' ); + t.notEqual( x.data, xe, 'different references' ); + + t.deepEqual( y.data, ye, 'deep equal' ); + t.notEqual( y.data, ye, 'different references' ); + + t.end(); +}); + +tape( 'the function supports operating on stacks of vectors (dim=-1)', function test( t ) { + var opts; + var xe; + var ye; + 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 ] ); + + xe = new Float32Array( y.length ); + scopy( y.length, y, 1, 0, xe, 1, 0 ); + + ye = new Float32Array( x.length ); + scopy( x.length, x, 1, 0, ye, 1, 0 ); + + opts = { + 'shape': [ 4, 2 ] + }; + x = array( x, opts ); + y = array( y, opts ); + + sswap( x, y, -1 ); + + t.deepEqual( x.data, xe, 'deep equal' ); + t.notEqual( x.data, xe, 'different references' ); + + t.deepEqual( y.data, ye, 'deep equal' ); + t.notEqual( y.data, ye, 'different references' ); + + t.end(); +}); + +tape( 'the function supports operating on stacks of vectors (dim=-2)', function test( t ) { + var opts; + var xe; + var ye; + 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 ] ); + + xe = new Float32Array( y.length ); + scopy( y.length, y, 1, 0, xe, 1, 0 ); + + ye = new Float32Array( x.length ); + scopy( x.length, x, 1, 0, ye, 1, 0 ); + + opts = { + 'shape': [ 4, 2 ] + }; + x = array( x, opts ); + y = array( y, opts ); + + sswap( x, y, -2 ); + + t.deepEqual( x.data, xe, 'deep equal' ); + t.notEqual( x.data, xe, 'different references' ); + + t.deepEqual( y.data, ye, 'deep equal' ); + t.notEqual( y.data, ye, 'different references' ); + + t.end(); +}); + tape( 'the function supports a strided vector for the first argument', function test( t ) { var xe; var ye; From 5c99c175c38014265a8977f1532d5e0cb31d1847 Mon Sep 17 00:00:00 2001 From: aman-095 Date: Fri, 13 Sep 2024 12:34:37 +0530 Subject: [PATCH 2/5] chore: update benchmarks, docs, and package.json --- .../@stdlib/blas/sswap/benchmark/benchmark.js | 33 ++++---- .../@stdlib/blas/sswap/docs/repl.txt | 19 ++++- .../@stdlib/blas/sswap/docs/types/index.d.ts | 17 ++-- .../@stdlib/blas/sswap/docs/types/test.ts | 82 +++++++++---------- .../@stdlib/blas/sswap/package.json | 1 - 5 files changed, 86 insertions(+), 66 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/sswap/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/sswap/benchmark/benchmark.js index 647c1f0c382..2ee3a6b731f 100644 --- a/lib/node_modules/@stdlib/blas/sswap/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/sswap/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 sswap = require( './../lib/main.js' ); +// VARIABLES // + +var opts = { + 'dtype': 'float32' +}; + + // FUNCTIONS // /** @@ -40,21 +46,16 @@ var sswap = 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; @@ -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/sswap/docs/repl.txt b/lib/node_modules/@stdlib/blas/sswap/docs/repl.txt index c40e6403834..f09770da661 100644 --- a/lib/node_modules/@stdlib/blas/sswap/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/sswap/docs/repl.txt @@ -1,14 +1,27 @@ -{{alias}}( x, y ) +{{alias}}( x, y[, dim] ) Interchanges two single-precision floating-point vectors. + For multi-dimensional input arrays, the function performs batched + computation, such that the function interchanges each pair of vectors in `x` + and `y` according to the specified dimension index. + + Both input arrays must have the same shape. + 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 must have the same shape as 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 must have the same shape as the first input array. + + dim: integer (optional) + Dimension index along which to interchange vectors. 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 ------- diff --git a/lib/node_modules/@stdlib/blas/sswap/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/sswap/docs/types/index.d.ts index d273b4e4c77..d799bb7663a 100644 --- a/lib/node_modules/@stdlib/blas/sswap/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/sswap/docs/types/index.d.ts @@ -20,16 +20,23 @@ /// -import { ndarray } from '@stdlib/types/ndarray'; +import { float32ndarray } from '@stdlib/types/ndarray'; /** * Interchanges two single-precision floating-point vectors. * +* ## Notes +* +* - For multi-dimensional input arrays, the function performs batched computation, such that the function interchanges each pair of vectors in `x` and `y` according to the specified dimension index. +* - Both input arrays must have the same shape. +* - Negative indices are resolved relative to the last array dimension, with the last dimension corresponding to `-1`. +* * @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 have the same shape * @returns `y` * * @example @@ -47,7 +54,7 @@ import { ndarray } from '@stdlib/types/ndarray'; * var ybuf = y.data; * // returns [ 4.0, 2.0, -3.0, 5.0, -1.0 ] */ -declare function sswap( x: ndarray, y: ndarray ): ndarray; +declare function sswap( x: float32ndarray, y: float32ndarray, dim?: number ): float32ndarray; // EXPORTS // diff --git a/lib/node_modules/@stdlib/blas/sswap/docs/types/test.ts b/lib/node_modules/@stdlib/blas/sswap/docs/types/test.ts index 4af387f765f..8ba02f0c060 100644 --- a/lib/node_modules/@stdlib/blas/sswap/docs/types/test.ts +++ b/lib/node_modules/@stdlib/blas/sswap/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 sswap = require( './index' ); -/** -* Returns an ndarray object. -* -* @returns ndarray object -*/ -function createArray(): ndarray { - const arr: ndarray = { - 'byteLength': null, - 'BYTES_PER_ELEMENT': null, - 'data': new Float32Array( [ 1, 2, 3 ] ), - 'dtype': 'float32', - '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 an ndarray... { - sswap( createArray(), createArray() ); // $ExpectType ndarray + sswap( 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 ] ); sswap( 10, y ); // $ExpectError sswap( '10', y ); // $ExpectError @@ -74,11 +40,21 @@ function createArray(): ndarray { sswap( {}, y ); // $ExpectError sswap( [], y ); // $ExpectError sswap( ( x: number ): number => x, y ); // $ExpectError + + sswap( 10, y, -1 ); // $ExpectError + sswap( '10', y, -1 ); // $ExpectError + sswap( true, y, -1 ); // $ExpectError + sswap( false, y, -1 ); // $ExpectError + sswap( null, y, -1 ); // $ExpectError + sswap( undefined, y, -1 ); // $ExpectError + sswap( {}, y, -1 ); // $ExpectError + sswap( [], y, -1 ); // $ExpectError + sswap( ( 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 ] ); sswap( x, 10 ); // $ExpectError sswap( x, '10' ); // $ExpectError @@ -89,14 +65,38 @@ function createArray(): ndarray { sswap( x, {} ); // $ExpectError sswap( x, [] ); // $ExpectError sswap( x, ( x: number ): number => x ); // $ExpectError + + sswap( x, 10, -1 ); // $ExpectError + sswap( x, '10', -1 ); // $ExpectError + sswap( x, true, -1 ); // $ExpectError + sswap( x, false, -1 ); // $ExpectError + sswap( x, null, -1 ); // $ExpectError + sswap( x, undefined, -1 ); // $ExpectError + sswap( x, {}, -1 ); // $ExpectError + sswap( x, [], -1 ); // $ExpectError + sswap( 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 ] ); + + sswap( x, y, '10' ); // $ExpectError + sswap( x, y, true ); // $ExpectError + sswap( x, y, false ); // $ExpectError + sswap( x, y, null ); // $ExpectError + sswap( x, y, {} ); // $ExpectError + sswap( x, y, [] ); // $ExpectError + sswap( 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 ] ); sswap(); // $ExpectError sswap( x ); // $ExpectError - sswap( x, y, {} ); // $ExpectError + sswap( x, y, -1, {} ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/blas/sswap/package.json b/lib/node_modules/@stdlib/blas/sswap/package.json index 4f51dcee6d3..76c37b85ca3 100644 --- a/lib/node_modules/@stdlib/blas/sswap/package.json +++ b/lib/node_modules/@stdlib/blas/sswap/package.json @@ -14,7 +14,6 @@ } ], "main": "./lib", - "browser": "./lib/main.js", "directories": { "benchmark": "./benchmark", "doc": "./docs", From 1455bec473a828bd2a9f4291bdfc88f604386708 Mon Sep 17 00:00:00 2001 From: aman-095 Date: Fri, 13 Sep 2024 12:38:06 +0530 Subject: [PATCH 3/5] docs: update description --- lib/node_modules/@stdlib/blas/sswap/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/sswap/lib/main.js b/lib/node_modules/@stdlib/blas/sswap/lib/main.js index b33a393556b..18873dfa8ee 100644 --- a/lib/node_modules/@stdlib/blas/sswap/lib/main.js +++ b/lib/node_modules/@stdlib/blas/sswap/lib/main.js @@ -41,7 +41,7 @@ var format = require( '@stdlib/string/format' ); * * @param {ndarrayLike} x - first input array * @param {ndarrayLike} y - second input array -* @param {NegativeInteger} [dim] - dimension along which to interchange elements +* @param {NegativeInteger} [dim=-1] - dimension along which to interchange elements * @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 From e46e83849f8c5d0049c06634b220acbccc1955ad Mon Sep 17 00:00:00 2001 From: aman-095 Date: Fri, 13 Sep 2024 12:41:05 +0530 Subject: [PATCH 4/5] test: update descriptions --- lib/node_modules/@stdlib/blas/sswap/test/test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/sswap/test/test.js b/lib/node_modules/@stdlib/blas/sswap/test/test.js index ff86e569bf3..a7d13c4a342 100644 --- a/lib/node_modules/@stdlib/blas/sswap/test/test.js +++ b/lib/node_modules/@stdlib/blas/sswap/test/test.js @@ -43,7 +43,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 non-zero-dimensional ndarray containing double-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 single-precision floating-point numbers', function test( t ) { var values; var i; @@ -76,7 +76,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 first argument which is not a non-zero-dimensional ndarray containing double-precision floating-point numbers (dimension)', function test( t ) { +tape( 'the function throws an error if provided a first argument which is not a non-zero-dimensional ndarray containing single-precision floating-point numbers (dimension)', function test( t ) { var values; var i; @@ -137,7 +137,7 @@ tape( 'the function throws an error if provided a first argument which is a read } }); -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 ) { +tape( 'the function throws an error if provided a second argument which is not a non-zero-dimensional ndarray containing single-precision floating-point numbers', function test( t ) { var values; var i; @@ -170,7 +170,7 @@ tape( 'the function throws an error if provided a second argument which is not a } }); -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 ) { +tape( 'the function throws an error if provided a second argument which is not a non-zero-dimensional ndarray containing single-precision floating-point numbers (dimension)', function test( t ) { var values; var i; From c25088445a99e47eda7136db999a97ff9959bc8e Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Sat, 14 Sep 2024 03:47:35 -0700 Subject: [PATCH 5/5] chore: explicitly provide dtype, fix bench assertion, and rename file --- .../@stdlib/blas/dswap/docs/types/test.ts | 14 +++++++------- .../@stdlib/blas/sswap/benchmark/benchmark.js | 6 +++--- .../{benchmark.stack.js => benchmark.stacks.js} | 0 .../@stdlib/blas/sswap/docs/types/test.ts | 14 +++++++------- 4 files changed, 17 insertions(+), 17 deletions(-) rename lib/node_modules/@stdlib/blas/sswap/benchmark/{benchmark.stack.js => benchmark.stacks.js} (100%) diff --git a/lib/node_modules/@stdlib/blas/dswap/docs/types/test.ts b/lib/node_modules/@stdlib/blas/dswap/docs/types/test.ts index 8f39e9bc66f..06aac93bff2 100644 --- a/lib/node_modules/@stdlib/blas/dswap/docs/types/test.ts +++ b/lib/node_modules/@stdlib/blas/dswap/docs/types/test.ts @@ -24,12 +24,12 @@ import dswap = require( './index' ); // The function returns an ndarray... { - dswap( zeros( [ 10 ] ), zeros( [ 10 ] ) ); // $ExpectType float64ndarray + dswap( zeros( [ 10 ], { 'dtype': 'float64' } ), zeros( [ 10 ], { 'dtype': 'float64' } ) ); // $ExpectType float64ndarray } // The compiler throws an error if the function is provided a first argument which is not an ndarray... { - const y = zeros( [ 10 ] ); + const y = zeros( [ 10 ], { 'dtype': 'float64' } ); dswap( 10, y ); // $ExpectError dswap( '10', y ); // $ExpectError @@ -54,7 +54,7 @@ import dswap = require( './index' ); // The compiler throws an error if the function is provided a second argument which is not an ndarray... { - const x = zeros( [ 10 ] ); + const x = zeros( [ 10 ], { 'dtype': 'float64' } ); dswap( x, 10 ); // $ExpectError dswap( x, '10' ); // $ExpectError @@ -79,8 +79,8 @@ import dswap = require( './index' ); // 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 ] ); + const x = zeros( [ 10 ], { 'dtype': 'float64' } ); + const y = zeros( [ 10 ], { 'dtype': 'float64' } ); dswap( x, y, '10' ); // $ExpectError dswap( x, y, true ); // $ExpectError @@ -93,8 +93,8 @@ import dswap = require( './index' ); // The compiler throws an error if the function is provided an unsupported number of arguments... { - const x = zeros( [ 10 ] ); - const y = zeros( [ 10 ] ); + const x = zeros( [ 10 ], { 'dtype': 'float64' } ); + const y = zeros( [ 10 ], { 'dtype': 'float64' } ); dswap(); // $ExpectError dswap( x ); // $ExpectError diff --git a/lib/node_modules/@stdlib/blas/sswap/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/sswap/benchmark/benchmark.js index 2ee3a6b731f..ea80b871270 100644 --- a/lib/node_modules/@stdlib/blas/sswap/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/sswap/benchmark/benchmark.js @@ -63,12 +63,12 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { d = sswap( x, y ); - if ( isnan( d[ i%x.length ] ) ) { + if ( isnan( d.data[ i%len ] ) ) { b.fail( 'should not return NaN' ); } } b.toc(); - if ( isnan( d ) ) { + if ( isnan( d.data[ i%len ] ) ) { b.fail( 'should not return NaN' ); } b.pass( 'benchmark finished' ); @@ -97,7 +97,7 @@ function main() { for ( i = min; i <= max; i++ ) { len = pow( 10, i ); f = createBenchmark( len ); - bench( pkg+':vectors:len='+len, f ); + bench( pkg+':len='+len, f ); } } diff --git a/lib/node_modules/@stdlib/blas/sswap/benchmark/benchmark.stack.js b/lib/node_modules/@stdlib/blas/sswap/benchmark/benchmark.stacks.js similarity index 100% rename from lib/node_modules/@stdlib/blas/sswap/benchmark/benchmark.stack.js rename to lib/node_modules/@stdlib/blas/sswap/benchmark/benchmark.stacks.js diff --git a/lib/node_modules/@stdlib/blas/sswap/docs/types/test.ts b/lib/node_modules/@stdlib/blas/sswap/docs/types/test.ts index 8ba02f0c060..496e9d9ceb6 100644 --- a/lib/node_modules/@stdlib/blas/sswap/docs/types/test.ts +++ b/lib/node_modules/@stdlib/blas/sswap/docs/types/test.ts @@ -24,12 +24,12 @@ import sswap = require( './index' ); // The function returns an ndarray... { - sswap( zeros( [ 10 ] ), zeros( [ 10 ] ) ); // $ExpectType float32ndarray + sswap( zeros( [ 10 ], { 'dtype': 'float32' } ), zeros( [ 10 ], { 'dtype': 'float32' } ) ); // $ExpectType float32ndarray } // The compiler throws an error if the function is provided a first argument which is not an ndarray... { - const y = zeros( [ 10 ] ); + const y = zeros( [ 10 ], { 'dtype': 'float32' } ); sswap( 10, y ); // $ExpectError sswap( '10', y ); // $ExpectError @@ -54,7 +54,7 @@ import sswap = require( './index' ); // The compiler throws an error if the function is provided a second argument which is not an ndarray... { - const x = zeros( [ 10 ] ); + const x = zeros( [ 10 ], { 'dtype': 'float32' } ); sswap( x, 10 ); // $ExpectError sswap( x, '10' ); // $ExpectError @@ -79,8 +79,8 @@ import sswap = require( './index' ); // 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 ] ); + const x = zeros( [ 10 ], { 'dtype': 'float32' } ); + const y = zeros( [ 10 ], { 'dtype': 'float32' } ); sswap( x, y, '10' ); // $ExpectError sswap( x, y, true ); // $ExpectError @@ -93,8 +93,8 @@ import sswap = require( './index' ); // The compiler throws an error if the function is provided an unsupported number of arguments... { - const x = zeros( [ 10 ] ); - const y = zeros( [ 10 ] ); + const x = zeros( [ 10 ], { 'dtype': 'float32' } ); + const y = zeros( [ 10 ], { 'dtype': 'float32' } ); sswap(); // $ExpectError sswap( x ); // $ExpectError