diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/drot/README.md b/lib/node_modules/@stdlib/blas/base/ndarray/drot/README.md new file mode 100644 index 000000000000..908cca443199 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/drot/README.md @@ -0,0 +1,131 @@ + + +# drot + +> Apply a plane rotation to two one-dimensional double-precision floating-point ndarrays. + +
+ +
+ + + +
+ +## Usage + +```javascript +var drot = require( '@stdlib/blas/base/ndarray/drot' ); +``` + +#### drot( arrays ) + +Applies a plane rotation to two one-dimensional double-precision floating-point ndarrays. + +```javascript +var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); + +var x = new Float64Vector( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +var y = new Float64Vector( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + +var c = scalar2ndarray( 0.8, { + 'dtype': 'float64' +}); +var s = scalar2ndarray( 0.6, { + 'dtype': 'float64' +}); + +var z = drot( [ x, y, c, s ] ); +// x => [ 4.4, 5.8, 7.2, 8.6, 10.0 ] +// y => [ 4.2, 4.4, 4.6, 4.8, 5.0 ] + +var bool = ( z === y ); +// returns true +``` + +The function has the following parameters: + +- **arrays**: array-like object containing the following ndarrays: + + - a one-dimensional input ndarray. + - a one-dimensional output ndarray. + - a zero-dimensional ndarray containing the cosine of the angle of rotation. + - a zero-dimensional ndarray containing the sine of the angle of rotation. + +
+ + + +
+ +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/discrete-uniform' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var drot = require( '@stdlib/blas/base/ndarray/drot' ); + +var opts = { + 'dtype': 'float64' +}; + +var x = discreteUniform( [ 10 ], 0, 100, opts ); +console.log( ndarray2array( x ) ); + +var y = discreteUniform( [ 10 ], 0, 100, opts ); +console.log( ndarray2array( y ) ); + +var c = scalar2ndarray( 0.8, opts ); +var s = scalar2ndarray( 0.6, opts ); + +var z = drot( [ x, y, c, s ] ); +console.log( ndarray2array( z ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/drot/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/ndarray/drot/benchmark/benchmark.js new file mode 100644 index 000000000000..b4888a1bd7de --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/drot/benchmark/benchmark.js @@ -0,0 +1,114 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var drot = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x; + var y; + var c; + var s; + + x = uniform( [ len ], -100.0, 100.0, options ); + y = uniform( [ len ], -100.0, 100.0, options ); + + c = scalar2ndarray( 0.8, options ); + s = scalar2ndarray( 0.6, options ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var z; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = drot( [ x, y, c, s ] ); + if ( typeof z !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( z.get( i%len ) ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/drot/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/ndarray/drot/docs/repl.txt new file mode 100644 index 000000000000..295f72a52fc3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/drot/docs/repl.txt @@ -0,0 +1,41 @@ + +{{alias}}( arrays ) + Applies a plane rotation to two one-dimensional double-precision floating- + point ndarrays. + + If provided empty input ndarrays, the function returns the second input + ndarray unchanged. + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing the following ndarrays: + + - a one-dimensional input ndarray. + - a one-dimensional output ndarray. + - a zero-dimensional ndarray containing the cosine of the angle of + rotation. + - a zero-dimensional ndarray containing the sine of the angle of + rotation. + + Returns + ------- + out: ndarray + Second input ndarray. + + Examples + -------- + > var x = new {{alias:@stdlib/ndarray/vector/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + > var y = new {{alias:@stdlib/ndarray/vector/float64}}( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + > var c = {{alias:@stdlib/ndarray/from-scalar}}( 0.8, { 'dtype': 'float64' }); + > var s = {{alias:@stdlib/ndarray/from-scalar}}( 0.6, { 'dtype': 'float64' }); + + > {{alias}}( [ x, y, c, s ] ); + > x + [ 4.4, 5.8, 7.2, 8.6, 10.0 ] + > y + [ 4.2, 4.4, 4.6, 4.8, 5.0 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/drot/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/ndarray/drot/docs/types/index.d.ts new file mode 100644 index 000000000000..aec13c366c68 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/drot/docs/types/index.d.ts @@ -0,0 +1,66 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +*/ + +// TypeScript Version: 4.1 + +/// + +import { float64ndarray } from '@stdlib/types/ndarray'; + +/** +* Applies a plane rotation to two one-dimensional double-precision floating-point ndarrays. +* +* ## Notes +* +* - The function expects the following ndarrays: +* +* - a one-dimensional input ndarray. +* - a one-dimensional output ndarray. +* - a zero-dimensional ndarray containing the cosine of the angle of rotation. +* - a zero-dimensional ndarray containing the sine of the angle of rotation. +* +* @param arrays - array-like object containing ndarrays +* @returns second input ndarray +* +* @example +* var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* +* var x = new Float64Vector( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* var y = new Float64Vector( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); +* +* var c = scalar2ndarray( 0.8, { +* 'dtype': 'float64' +* }); +* var s = scalar2ndarray( 0.6, { +* 'dtype': 'float64' +* }); +* +* var z = drot( [ x, y, c, s ] ); +* // x => [ 4.4, 5.8, 7.2, 8.6, 10.0 ] +* // y => [ 4.2, 4.4, 4.6, 4.8, 5.0 ] +* +* var bool = ( z === y ); +* // returns true +*/ +declare function drot( arrays: [ float64ndarray, float64ndarray, float64ndarray, float64ndarray ] ): float64ndarray; + + +// EXPORTS // + +export = drot; diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/drot/docs/types/test.ts b/lib/node_modules/@stdlib/blas/base/ndarray/drot/docs/types/test.ts new file mode 100644 index 000000000000..7e4778c9f634 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/drot/docs/types/test.ts @@ -0,0 +1,75 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +*/ + +/* eslint-disable space-in-parens */ + +import zeros = require( '@stdlib/ndarray/zeros' ); +import drot = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 10 ], { + 'dtype': 'float64' + }); + const y = zeros( [ 10 ], { + 'dtype': 'float64' + }); + const c = zeros( [], { + 'dtype': 'float64' + }); + const s = zeros( [], { + 'dtype': 'float64' + }); + + drot( [ x, y, c, s ] ); // $ExpectType float64ndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + drot( '10' ); // $ExpectError + drot( 10 ); // $ExpectError + drot( true ); // $ExpectError + drot( false ); // $ExpectError + drot( null ); // $ExpectError + drot( undefined ); // $ExpectError + drot( [] ); // $ExpectError + drot( {} ); // $ExpectError + drot( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 10 ], { + 'dtype': 'float64' + }); + const y = zeros( [ 10 ], { + 'dtype': 'float64' + }); + const c = zeros( [], { + 'dtype': 'float64' + }); + const s = zeros( [], { + 'dtype': 'float64' + }); + + drot(); // $ExpectError + drot( [ x, y, c, s ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/drot/examples/index.js b/lib/node_modules/@stdlib/blas/base/ndarray/drot/examples/index.js new file mode 100644 index 000000000000..917f37a0c877 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/drot/examples/index.js @@ -0,0 +1,40 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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'; + +var discreteUniform = require( '@stdlib/random/discrete-uniform' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var drot = require( './../lib' ); + +var opts = { + 'dtype': 'float64' +}; + +var x = discreteUniform( [ 10 ], 0, 100, opts ); +console.log( ndarray2array( x ) ); + +var y = discreteUniform( [ 10 ], 0, 100, opts ); +console.log( ndarray2array( y ) ); + +var c = scalar2ndarray( 0.8, opts ); +var s = scalar2ndarray( 0.6, opts ); + +var out = drot( [ x, y, c, s ] ); +console.log( ndarray2array( out ) ); diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/drot/lib/index.js b/lib/node_modules/@stdlib/blas/base/ndarray/drot/lib/index.js new file mode 100644 index 000000000000..038a83b8d272 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/drot/lib/index.js @@ -0,0 +1,56 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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'; + +/** +* BLAS level 1 routine to apply a plane rotation to two one-dimensional double-precision floating-point ndarrays. +* +* @module @stdlib/blas/base/ndarray/drot +* +* @example +* var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var drot = require( '@stdlib/blas/base/ndarray/drot' ); +* +* var x = new Float64Vector( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* var y = new Float64Vector( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); +* +* var c = scalar2ndarray( 0.8, { +* 'dtype': 'float64' +* }); +* var s = scalar2ndarray( 0.6, { +* 'dtype': 'float64' +* }); +* +* var z = drot( [ x, y, c, s ] ); +* // x => [ 4.4, 5.8, 7.2, 8.6, 10.0 ] +* // y => [ 4.2, 4.4, 4.6, 4.8, 5.0 ] +* +* var bool = ( z === y ); +* // returns true +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/drot/lib/main.js b/lib/node_modules/@stdlib/blas/base/ndarray/drot/lib/main.js new file mode 100644 index 000000000000..919bd4e5abdd --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/drot/lib/main.js @@ -0,0 +1,81 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 numelDimension = require( '@stdlib/ndarray/base/numel-dimension' ); +var getStride = require( '@stdlib/ndarray/base/stride' ); +var getOffset = require( '@stdlib/ndarray/base/offset' ); +var getData = require( '@stdlib/ndarray/base/data-buffer' ); +var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); +var strided = require( '@stdlib/blas/base/drot' ).ndarray; + + +// MAIN // + +/** +* Applies a plane rotation to two one-dimensional double-precision floating-point ndarrays. +* +* ## Notes +* +* - The function expects the following ndarrays: +* +* - a one-dimensional input ndarray. +* - a one-dimensional output ndarray. +* - a zero-dimensional ndarray containing the cosine of the angle of rotation. +* - a zero-dimensional ndarray containing the sine of the angle of rotation. +* +* @param {ArrayLikeObject} arrays - array-like object containing ndarrays +* @returns {Object} second input ndarray +* +* @example +* var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* +* var x = new Float64Vector( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* var y = new Float64Vector( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); +* +* var c = scalar2ndarray( 0.8, { +* 'dtype': 'float64' +* }); +* var s = scalar2ndarray( 0.6, { +* 'dtype': 'float64' +* }); +* +* var z = drot( [ x, y, c, s ] ); +* // x => [ 4.4, 5.8, 7.2, 8.6, 10.0 ] +* // y => [ 4.2, 4.4, 4.6, 4.8, 5.0 ] +* +* var bool = ( z === y ); +* // returns true +*/ +function drot( arrays ) { + var c = ndarraylike2scalar( arrays[ 2 ] ); + var s = ndarraylike2scalar( arrays[ 3 ] ); + var x = arrays[ 0 ]; + var y = arrays[ 1 ]; + strided( numelDimension( x, 0 ), getData( x ), getStride( x, 0 ), getOffset( x ), getData( y ), getStride( y, 0 ), getOffset( y ), c, s ); // eslint-disable-line max-len + return y; +} + + +// EXPORTS // + +module.exports = drot; diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/drot/package.json b/lib/node_modules/@stdlib/blas/base/ndarray/drot/package.json new file mode 100644 index 000000000000..89ce8dab49cb --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/drot/package.json @@ -0,0 +1,73 @@ +{ + "name": "@stdlib/blas/base/ndarray/drot", + "version": "0.0.0", + "description": "Apply a plane rotation to two one-dimensional double-precision floating-point ndarrays.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "blas", + "level 1", + "drot", + "linear", + "algebra", + "subroutines", + "rotation", + "plane", + "givens", + "vector", + "srot", + "array", + "ndarray", + "float64", + "double", + "float64array" + ] +} diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/drot/test/test.js b/lib/node_modules/@stdlib/blas/base/ndarray/drot/test/test.js new file mode 100644 index 000000000000..1e5913eff478 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/drot/test/test.js @@ -0,0 +1,260 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 tape = require( 'tape' ); +var isAlmostSameFloat64Array = require( '@stdlib/assert/is-almost-same-float64array' ); +var Float64Array = require( '@stdlib/array/float64' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var drot = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Returns a one-dimensional ndarray. +* +* @private +* @param {Collection} buffer - underlying data buffer +* @param {NonNegativeInteger} length - number of indexed elements +* @param {integer} stride - stride length +* @param {NonNegativeInteger} offset - index offset +* @returns {ndarray} one-dimensional ndarray +*/ +function vector( buffer, length, stride, offset ) { + return new ndarray( 'float64', buffer, [ length ], [ stride ], offset, 'row-major' ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof drot, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 1', function test( t ) { + t.strictEqual( drot.length, 1, 'has expected arity' ); + t.end(); +}); + +tape( 'the function applies a plane rotation', function test( t ) { + var expected; + var xbuf; + var ybuf; + var x; + var y; + var c; + var s; + var v; + + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + ybuf = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + x = vector( xbuf, 5, 1, 0 ); + y = vector( ybuf, 5, 1, 0 ); + c = scalar2ndarray( 0.8, { + 'dtype': 'float64' + }); + s = scalar2ndarray( 0.6, { + 'dtype': 'float64' + }); + + v = drot( [ x, y, c, s ] ); + + expected = new Float64Array( [ 4.4, 5.8, 7.2, 8.6, 10.0 ] ); + t.strictEqual( v, y, 'returns expected value' ); + t.strictEqual( isAlmostSameFloat64Array( getData( x ), expected, 2 ), true, 'returns expected value' ); + + expected = new Float64Array( [ 4.2, 4.4, 4.6, 4.8, 5.0 ] ); + t.strictEqual( isAlmostSameFloat64Array( getData( v ), expected, 2 ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided empty ndarrays, the function returns the second input ndarray unchanged', function test( t ) { + var expected; + var xbuf; + var ybuf; + var x; + var y; + var c; + var s; + var v; + + xbuf = new Float64Array( [] ); + ybuf = new Float64Array( [] ); + x = vector( xbuf, 0, 1, 0 ); + y = vector( ybuf, 0, 1, 0 ); + c = scalar2ndarray( 0.8, { + 'dtype': 'float64' + }); + s = scalar2ndarray( 0.6, { + 'dtype': 'float64' + }); + + v = drot( [ x, y, c, s ] ); + + expected = new Float64Array( [] ); + t.strictEqual( v, y, 'returns expected value' ); + t.strictEqual( isAlmostSameFloat64Array( getData( v ), expected, 2 ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having non-unit strides', function test( t ) { + var expected; + var xbuf; + var ybuf; + var x; + var y; + var c; + var s; + var v; + + xbuf = new Float64Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ]); + x = vector( xbuf, 3, 2, 0 ); + + ybuf = new Float64Array([ + 6.0, // 0 + 7.0, // 1 + 8.0, // 2 + 9.0, + 10.0 + ]); + y = vector( ybuf, 3, 1, 0 ); + c = scalar2ndarray( 0.8, { + 'dtype': 'float64' + }); + s = scalar2ndarray( 0.6, { + 'dtype': 'float64' + }); + + v = drot( [ x, y, c, s ] ); + + expected = new Float64Array( [ 4.4, 2.0, 6.6, 4.0, 8.8 ] ); + t.strictEqual( v, y, 'returns expected value' ); + t.strictEqual( isAlmostSameFloat64Array( getData( x ), expected, 2 ), true, 'returns expected value' ); + + expected = new Float64Array( [ 4.2, 3.8, 3.4, 9.0, 10.0 ] ); + t.strictEqual( isAlmostSameFloat64Array( getData( v ), expected, 2 ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having negative strides', function test( t ) { + var expected; + var xbuf; + var ybuf; + var x; + var y; + var c; + var s; + var v; + + xbuf = new Float64Array([ + 1.0, // 2 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 0 + ]); + x = vector( xbuf, 3, -2, 4 ); + + ybuf = new Float64Array([ + 6.0, // 2 + 7.0, // 1 + 8.0, // 0 + 9.0, + 10.0 + ]); + y = vector( ybuf, 3, -1, 2 ); + c = scalar2ndarray( 0.8, { + 'dtype': 'float64' + }); + s = scalar2ndarray( 0.6, { + 'dtype': 'float64' + }); + + v = drot( [ x, y, c, s ] ); + + expected = new Float64Array( [ 4.4, 2.0, 6.6, 4.0, 8.8 ] ); + t.strictEqual( v, y, 'returns expected value' ); + t.strictEqual( isAlmostSameFloat64Array( getData( x ), expected, 2 ), true, 'returns expected value' ); + + expected = new Float64Array( [ 4.2, 3.8, 3.4, 9.0, 10.0 ] ); + t.strictEqual( isAlmostSameFloat64Array( getData( v ), expected, 2 ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having non-zero offsets', function test( t ) { + var expected; + var xbuf; + var ybuf; + var x; + var y; + var c; + var s; + var v; + + xbuf = new Float64Array([ + 2.0, + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ]); + x = vector( xbuf, 3, 2, 1 ); + + ybuf = new Float64Array([ + 1.0, + 2.0, + 6.0, // 0 + 7.0, // 1 + 8.0, // 2 + 9.0 + ]); + y = vector( ybuf, 3, 1, 2 ); + c = scalar2ndarray( 0.8, { + 'dtype': 'float64' + }); + s = scalar2ndarray( 0.6, { + 'dtype': 'float64' + }); + + v = drot( [ x, y, c, s ] ); + + expected = new Float64Array( [ 2.0, 4.4, 2.0, 6.6, 4.0, 8.8 ] ); + t.strictEqual( v, y, 'returns expected value' ); + t.strictEqual( isAlmostSameFloat64Array( getData( x ), expected, 2 ), true, 'returns expected value' ); + + expected = new Float64Array( [ 1.0, 2.0, 4.2, 3.8, 3.4, 9.0 ] ); + t.strictEqual( isAlmostSameFloat64Array( getData( v ), expected, 2 ), true, 'returns expected value' ); + t.end(); +});