From e9548c0770d012ad550d70e3a7f32272b1d3ed34 Mon Sep 17 00:00:00 2001 From: kaustubh Date: Wed, 3 Jun 2026 01:56:24 +0530 Subject: [PATCH 1/3] feat: add blas/base/ndarray/drot --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/blas/base/ndarray/drot/README.md | 130 +++++++++ .../base/ndarray/drot/benchmark/benchmark.js | 114 ++++++++ .../blas/base/ndarray/drot/docs/repl.txt | 39 +++ .../base/ndarray/drot/docs/types/index.d.ts | 65 +++++ .../blas/base/ndarray/drot/docs/types/test.ts | 75 +++++ .../blas/base/ndarray/drot/examples/index.js | 40 +++ .../blas/base/ndarray/drot/lib/index.js | 55 ++++ .../blas/base/ndarray/drot/lib/main.js | 80 ++++++ .../blas/base/ndarray/drot/package.json | 73 +++++ .../blas/base/ndarray/drot/test/test.js | 260 ++++++++++++++++++ 10 files changed, 931 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/drot/README.md create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/drot/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/drot/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/drot/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/drot/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/drot/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/drot/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/drot/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/drot/package.json create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/drot/test/test.js 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..5be0edc0e03e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/drot/README.md @@ -0,0 +1,130 @@ + + +# 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 ] ); +// returns [ ~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..f2f9cc78d5d9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/drot/docs/repl.txt @@ -0,0 +1,39 @@ + +{{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 ] ); + > 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..5610aa6f8644 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/drot/docs/types/index.d.ts @@ -0,0 +1,65 @@ +/* +* @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 ] ); +* // returns [ ~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..4953d6a74f45 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/drot/lib/index.js @@ -0,0 +1,55 @@ +/** +* @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 ] ); +* // returns [ ~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..6966502c6556 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/drot/lib/main.js @@ -0,0 +1,80 @@ +/** +* @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 ] ); +* // returns [ ~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..063e2ec9981b --- /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 isSameFloat64Array = require( '@stdlib/assert/is-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.3999999999999995, 5.800000000000001, 7.2, 8.6, 10.0 ] ); + t.strictEqual( v, y, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( x ), expected ), true, 'returns expected value' ); + + expected = new Float64Array( [ 4.200000000000001, 4.4, 4.6000000000000005, 4.800000000000001, 5.0 ] ); + t.strictEqual( isSameFloat64Array( getData( v ), expected ), 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( isSameFloat64Array( getData( v ), expected ), 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.3999999999999995, 2.0, 6.6000000000000005, 4.0, 8.8 ] ); // eslint-disable-line max-len + t.strictEqual( v, y, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( x ), expected ), true, 'returns expected value' ); + + expected = new Float64Array( [ 4.200000000000001, 3.8000000000000007, 3.4000000000000004, 9.0, 10.0 ] ); // eslint-disable-line max-len + t.strictEqual( isSameFloat64Array( getData( v ), expected ), 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.3999999999999995, 2.0, 6.6000000000000005, 4.0, 8.8 ] ); // eslint-disable-line max-len + t.strictEqual( v, y, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( x ), expected ), true, 'returns expected value' ); + + expected = new Float64Array( [ 4.200000000000001, 3.8000000000000007, 3.4000000000000004, 9.0, 10.0 ] ); // eslint-disable-line max-len + t.strictEqual( isSameFloat64Array( getData( v ), expected ), 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.3999999999999995, 2.0, 6.6000000000000005, 4.0, 8.8 ] ); // eslint-disable-line max-len + t.strictEqual( v, y, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( x ), expected ), true, 'returns expected value' ); + + expected = new Float64Array( [ 1.0, 2.0, 4.200000000000001, 3.8000000000000007, 3.4000000000000004, 9.0 ] ); // eslint-disable-line max-len + t.strictEqual( isSameFloat64Array( getData( v ), expected ), true, 'returns expected value' ); + t.end(); +}); From 1ed56010bab6bd77436d19285cd1e1b527e9471a Mon Sep 17 00:00:00 2001 From: kaustubh Date: Wed, 3 Jun 2026 13:38:29 +0530 Subject: [PATCH 2/3] fix: use isAlmostSameFloat64Array instead of isSameFloat64Array in test --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../blas/base/ndarray/drot/test/test.js | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) 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 index 063e2ec9981b..1e5913eff478 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/drot/test/test.js +++ b/lib/node_modules/@stdlib/blas/base/ndarray/drot/test/test.js @@ -21,7 +21,7 @@ // MODULES // var tape = require( 'tape' ); -var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +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' ); @@ -82,12 +82,12 @@ tape( 'the function applies a plane rotation', function test( t ) { v = drot( [ x, y, c, s ] ); - expected = new Float64Array( [ 4.3999999999999995, 5.800000000000001, 7.2, 8.6, 10.0 ] ); + expected = new Float64Array( [ 4.4, 5.8, 7.2, 8.6, 10.0 ] ); t.strictEqual( v, y, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( x ), expected ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameFloat64Array( getData( x ), expected, 2 ), true, 'returns expected value' ); - expected = new Float64Array( [ 4.200000000000001, 4.4, 4.6000000000000005, 4.800000000000001, 5.0 ] ); - t.strictEqual( isSameFloat64Array( getData( v ), expected ), 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(); }); @@ -117,7 +117,7 @@ tape( 'if provided empty ndarrays, the function returns the second input ndarray expected = new Float64Array( [] ); t.strictEqual( v, y, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( v ), expected ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameFloat64Array( getData( v ), expected, 2 ), true, 'returns expected value' ); t.end(); }); @@ -158,12 +158,12 @@ tape( 'the function supports one-dimensional ndarrays having non-unit strides', v = drot( [ x, y, c, s ] ); - expected = new Float64Array( [ 4.3999999999999995, 2.0, 6.6000000000000005, 4.0, 8.8 ] ); // eslint-disable-line max-len + expected = new Float64Array( [ 4.4, 2.0, 6.6, 4.0, 8.8 ] ); t.strictEqual( v, y, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( x ), expected ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameFloat64Array( getData( x ), expected, 2 ), true, 'returns expected value' ); - expected = new Float64Array( [ 4.200000000000001, 3.8000000000000007, 3.4000000000000004, 9.0, 10.0 ] ); // eslint-disable-line max-len - t.strictEqual( isSameFloat64Array( getData( v ), expected ), 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(); }); @@ -203,12 +203,12 @@ tape( 'the function supports one-dimensional ndarrays having negative strides', v = drot( [ x, y, c, s ] ); - expected = new Float64Array( [ 4.3999999999999995, 2.0, 6.6000000000000005, 4.0, 8.8 ] ); // eslint-disable-line max-len + expected = new Float64Array( [ 4.4, 2.0, 6.6, 4.0, 8.8 ] ); t.strictEqual( v, y, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( x ), expected ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameFloat64Array( getData( x ), expected, 2 ), true, 'returns expected value' ); - expected = new Float64Array( [ 4.200000000000001, 3.8000000000000007, 3.4000000000000004, 9.0, 10.0 ] ); // eslint-disable-line max-len - t.strictEqual( isSameFloat64Array( getData( v ), expected ), 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(); }); @@ -250,11 +250,11 @@ tape( 'the function supports one-dimensional ndarrays having non-zero offsets', v = drot( [ x, y, c, s ] ); - expected = new Float64Array( [ 2.0, 4.3999999999999995, 2.0, 6.6000000000000005, 4.0, 8.8 ] ); // eslint-disable-line max-len + expected = new Float64Array( [ 2.0, 4.4, 2.0, 6.6, 4.0, 8.8 ] ); t.strictEqual( v, y, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( x ), expected ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameFloat64Array( getData( x ), expected, 2 ), true, 'returns expected value' ); - expected = new Float64Array( [ 1.0, 2.0, 4.200000000000001, 3.8000000000000007, 3.4000000000000004, 9.0 ] ); // eslint-disable-line max-len - t.strictEqual( isSameFloat64Array( getData( v ), expected ), 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(); }); From 863f83e874c4290208d1cfa200eeff3ae0d8de4d Mon Sep 17 00:00:00 2001 From: kaustubh Date: Wed, 3 Jun 2026 14:03:06 +0530 Subject: [PATCH 3/3] fix: return both mutated arrays --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/blas/base/ndarray/drot/README.md | 3 ++- lib/node_modules/@stdlib/blas/base/ndarray/drot/docs/repl.txt | 4 +++- .../@stdlib/blas/base/ndarray/drot/docs/types/index.d.ts | 3 ++- lib/node_modules/@stdlib/blas/base/ndarray/drot/lib/index.js | 3 ++- lib/node_modules/@stdlib/blas/base/ndarray/drot/lib/main.js | 3 ++- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/drot/README.md b/lib/node_modules/@stdlib/blas/base/ndarray/drot/README.md index 5be0edc0e03e..908cca443199 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/drot/README.md +++ b/lib/node_modules/@stdlib/blas/base/ndarray/drot/README.md @@ -55,7 +55,8 @@ var s = scalar2ndarray( 0.6, { }); var z = drot( [ x, y, c, s ] ); -// returns [ ~4.2, 4.4, 4.6, 4.8, 5.0 ] +// 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 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 index f2f9cc78d5d9..295f72a52fc3 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/drot/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/base/ndarray/drot/docs/repl.txt @@ -31,8 +31,10 @@ > 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 ] + [ 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 index 5610aa6f8644..aec13c366c68 100644 --- 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 @@ -52,7 +52,8 @@ import { float64ndarray } from '@stdlib/types/ndarray'; * }); * * var z = drot( [ x, y, c, s ] ); -* // returns [ ~4.2, 4.4, 4.6, 4.8, 5.0 ] +* // 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 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 index 4953d6a74f45..038a83b8d272 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/drot/lib/index.js +++ b/lib/node_modules/@stdlib/blas/base/ndarray/drot/lib/index.js @@ -39,7 +39,8 @@ * }); * * var z = drot( [ x, y, c, s ] ); -* // returns [ ~4.2, 4.4, 4.6, 4.8, 5.0 ] +* // 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 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 index 6966502c6556..919bd4e5abdd 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/drot/lib/main.js +++ b/lib/node_modules/@stdlib/blas/base/ndarray/drot/lib/main.js @@ -60,7 +60,8 @@ var strided = require( '@stdlib/blas/base/drot' ).ndarray; * }); * * var z = drot( [ x, y, c, s ] ); -* // returns [ ~4.2, 4.4, 4.6, 4.8, 5.0 ] +* // 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