From b1ebe7e2e4d02f98a370827e151eb14afbd83e99 Mon Sep 17 00:00:00 2001 From: kaustubh Date: Mon, 8 Jun 2026 12:51:12 +0530 Subject: [PATCH 1/3] feat: add blas/base/ndarray/sger --- 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/sger/README.md | 130 ++++++++ .../base/ndarray/sger/benchmark/benchmark.js | 114 +++++++ .../blas/base/ndarray/sger/docs/repl.txt | 38 +++ .../base/ndarray/sger/docs/types/index.d.ts | 65 ++++ .../blas/base/ndarray/sger/docs/types/test.ts | 75 +++++ .../blas/base/ndarray/sger/examples/index.js | 40 +++ .../blas/base/ndarray/sger/lib/index.js | 55 ++++ .../blas/base/ndarray/sger/lib/main.js | 80 +++++ .../blas/base/ndarray/sger/package.json | 72 +++++ .../blas/base/ndarray/sger/test/test.js | 291 ++++++++++++++++++ 10 files changed, 960 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/sger/README.md create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/sger/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/sger/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/sger/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/sger/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/sger/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/sger/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/sger/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/sger/package.json create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/sger/test/test.js diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/sger/README.md b/lib/node_modules/@stdlib/blas/base/ndarray/sger/README.md new file mode 100644 index 000000000000..7fcbb1e4acf9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/sger/README.md @@ -0,0 +1,130 @@ + + +# sger + +> Perform the rank 1 operation `A = alpha*x*y^T + A`. + +
+ +
+ + + +
+ +## Usage + +```javascript +var sger = require( '@stdlib/blas/base/ndarray/sger' ); +``` + +#### sger( arrays ) + +Performs the rank 1 operation `A = alpha*x*y^T + A`, where `alpha` is a scalar, `x` is an `M` element vector, `y` is an `N` element vector, and `A` is an `M` by `N` matrix. + +```javascript +var Float32Vector = require( '@stdlib/ndarray/vector/float32' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var Float32Array = require( '@stdlib/array/float32' ); + +var x = new Float32Vector( [ 1.0, 2.0 ] ); +var y = new Float32Vector( [ 3.0, 4.0, 5.0 ] ); +var A = new ndarray( 'float32', new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ), [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + +var alpha = scalar2ndarray( 2.0, { + 'dtype': 'float32' +}); + +var out = sger( [ x, y, A, alpha ] ); +// returns [ [ 7.0, 10.0, 13.0 ], [ 16.0, 21.0, 26.0 ] ] + +var bool = ( out === A ); +// returns true +``` + +The function has the following parameters: + +- **arrays**: array-like object containing the following ndarrays: + + - first one-dimensional input ndarray. + - second one-dimensional input ndarray. + - a two-dimensional input ndarray. + - a zero-dimensional ndarray containing a scalar constant. + +
+ + + +
+ +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var Float32Array = require( '@stdlib/array/float32' ); +var Float32Vector = require( '@stdlib/ndarray/vector/float32' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var sger = require( '@stdlib/blas/base/ndarray/sger' ); + +var opts = { + 'dtype': 'float32' +}; + +var x = new Float32Vector( discreteUniform( 3, 0, 10, opts ) ); +var y = new Float32Vector( discreteUniform( 4, 0, 10, opts ) ); +var A = new ndarray( 'float32', new Float32Array( discreteUniform( 12, 0, 10, opts ) ), [ 3, 4 ], [ 4, 1 ], 0, 'row-major' ); + +var alpha = scalar2ndarray( 1.0, opts ); + +var out = sger( [ x, y, A, alpha ] ); +console.log( ndarray2array( out ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/sger/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/ndarray/sger/benchmark/benchmark.js new file mode 100644 index 000000000000..5b817e2194a6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/sger/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 isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +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 sger = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var alpha; + var x; + var y; + var A; + + x = uniform( [ len ], -100.0, 100.0, options ); + y = uniform( [ len ], -100.0, 100.0, options ); + A = uniform( [ len, len ], -100.0, 100.0, options ); + + alpha = scalar2ndarray( 1.0, 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 = sger( [ x, y, A, alpha ] ); + if ( typeof z !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnanf( z.get( 0, 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 = 3; // 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/sger/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/ndarray/sger/docs/repl.txt new file mode 100644 index 000000000000..471498d223cb --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/sger/docs/repl.txt @@ -0,0 +1,38 @@ + +{{alias}}( arrays ) + Performs the rank 1 operation `A = alpha*x*y^T + A`, where `alpha` is a + scalar, `x` is an `M` element vector, `y` is an `N` element vector, and + `A` is an `M` by `N` matrix. + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing the following ndarrays: + + - first one-dimensional input ndarray. + - second one-dimensional input ndarray. + - a two-dimensional input ndarray. + - a zero-dimensional ndarray containing a scalar constant. + + Returns + ------- + out: ndarray + Output ndarray. + + Examples + -------- + > var x = new {{alias:@stdlib/ndarray/vector/float32}}( [ 1.0, 2.0 ] ); + > var y = new {{alias:@stdlib/ndarray/vector/float32}}( [ 3.0, 4.0, 5.0 ] ); + > var buf = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + > var sh = [ 2, 3 ]; + > var st = [ 3, 1 ]; + > var A = new {{alias:@stdlib/ndarray/base/ctor}}( 'float32', buf, sh, st, 0, 'row-major' ); + > var alpha = {{alias:@stdlib/ndarray/from-scalar}}( 2.0, { 'dtype': 'float32' }); + + > {{alias}}( [ x, y, A, alpha ] ); + > A + [ [ 7.0, 10.0, 13.0 ], [ 16.0, 21.0, 26.0 ] ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/sger/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/ndarray/sger/docs/types/index.d.ts new file mode 100644 index 000000000000..d6cd790ea5e0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/sger/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 { float32ndarray } from '@stdlib/types/ndarray'; + +/** +* Performs the rank 1 operation `A = alpha*x*y^T + A`, where `alpha` is a scalar, `x` is an `M` element vector, `y` is an `N` element vector, and `A` is an `M` by `N` matrix. +* +* ## Notes +* +* - The function expects the following ndarrays: +* +* - first one-dimensional input ndarray. +* - second one-dimensional input ndarray. +* - a two-dimensional input ndarray. +* - a zero-dimensional ndarray containing a scalar constant. +* +* @param arrays - array-like object containing ndarrays +* @returns output ndarray +* +* @example +* var Float32Vector = require( '@stdlib/ndarray/vector/float32' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var x = new Float32Vector( [ 1.0, 2.0 ] ); +* var y = new Float32Vector( [ 3.0, 4.0, 5.0 ] ); +* var A = new ndarray( 'float32', new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ), [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); +* +* var alpha = scalar2ndarray( 2.0, { +* 'dtype': 'float32' +* }); +* +* var z = sger( [ x, y, A, alpha ] ); +* // returns [ [ 7.0, 10.0, 13.0 ], [ 16.0, 21.0, 26.0 ] ] +* +* var bool = ( z === A ); +* // returns true +*/ +declare function sger( arrays: [ float32ndarray, float32ndarray, float32ndarray, float32ndarray ] ): float32ndarray; + + +// EXPORTS // + +export = sger; diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/sger/docs/types/test.ts b/lib/node_modules/@stdlib/blas/base/ndarray/sger/docs/types/test.ts new file mode 100644 index 000000000000..0bdeaf608342 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/sger/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 sger = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 2 ], { + 'dtype': 'float32' + }); + const y = zeros( [ 3 ], { + 'dtype': 'float32' + }); + const A = zeros( [ 2, 3 ], { + 'dtype': 'float32' + }); + const alpha = zeros( [], { + 'dtype': 'float32' + }); + + sger( [ x, y, A, alpha ] ); // $ExpectType float32ndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + sger( '10' ); // $ExpectError + sger( 10 ); // $ExpectError + sger( true ); // $ExpectError + sger( false ); // $ExpectError + sger( null ); // $ExpectError + sger( undefined ); // $ExpectError + sger( [] ); // $ExpectError + sger( {} ); // $ExpectError + sger( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 2 ], { + 'dtype': 'float32' + }); + const y = zeros( [ 3 ], { + 'dtype': 'float32' + }); + const A = zeros( [ 2, 3 ], { + 'dtype': 'float32' + }); + const alpha = zeros( [], { + 'dtype': 'float32' + }); + + sger(); // $ExpectError + sger( [ x, y, A, alpha ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/sger/examples/index.js b/lib/node_modules/@stdlib/blas/base/ndarray/sger/examples/index.js new file mode 100644 index 000000000000..874387b4989d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/sger/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/array/discrete-uniform' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var Float32Array = require( '@stdlib/array/float32' ); +var Float32Vector = require( '@stdlib/ndarray/vector/float32' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var sger = require( './../lib' ); + +var opts = { + 'dtype': 'float32' +}; + +var x = new Float32Vector( discreteUniform( 3, 0, 10, opts ) ); +var y = new Float32Vector( discreteUniform( 4, 0, 10, opts ) ); +var A = new ndarray( 'float32', new Float32Array( discreteUniform( 12, 0, 10, opts ) ), [ 3, 4 ], [ 4, 1 ], 0, 'row-major' ); + +var alpha = scalar2ndarray( 2.0, opts ); + +var out = sger( [ x, y, A, alpha ] ); +console.log( ndarray2array( out ) ); diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/sger/lib/index.js b/lib/node_modules/@stdlib/blas/base/ndarray/sger/lib/index.js new file mode 100644 index 000000000000..7617f66fae94 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/sger/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 2 routine to perform the rank 1 operation `A = alpha*x*y^T + A`. +* +* @module @stdlib/blas/base/ndarray/sger +* +* @example +* var Float32Vector = require( '@stdlib/ndarray/vector/float32' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var Float32Array = require( '@stdlib/array/float32' ); +* var sger = require( '@stdlib/blas/base/ndarray/sger' ); +* +* var x = new Float32Vector( [ 1.0, 2.0 ] ); +* var y = new Float32Vector( [ 3.0, 4.0, 5.0 ] ); +* var A = new ndarray( 'float32', new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ), [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); +* +* var alpha = scalar2ndarray( 2.0, { +* 'dtype': 'float32' +* }); +* +* var out = sger( [ x, y, A, alpha ] ); +* // returns [ [ 7.0, 10.0, 13.0 ], [ 16.0, 21.0, 26.0 ] ] +* +* var bool = ( out === A ); +* // returns true +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/sger/lib/main.js b/lib/node_modules/@stdlib/blas/base/ndarray/sger/lib/main.js new file mode 100644 index 000000000000..e1c5e5dc7d7e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/sger/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/sger' ).ndarray; + + +// MAIN // + +/** +* Performs the rank 1 operation `A = alpha*x*y^T + A`, where `alpha` is a scalar, `x` is an `M` element vector, `y` is an `N` element vector, and `A` is an `M` by `N` matrix. +* +* ## Notes +* +* - The function expects the following ndarrays: +* +* - first one-dimensional input ndarray. +* - second one-dimensional input ndarray. +* - a two-dimensional input ndarray. +* - a zero-dimensional ndarray containing a scalar constant. +* +* @param {ArrayLikeObject} arrays - array-like object containing ndarrays +* @returns {Object} output ndarray +* +* @example +* var Float32Vector = require( '@stdlib/ndarray/vector/float32' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var x = new Float32Vector( [ 1.0, 2.0 ] ); +* var y = new Float32Vector( [ 3.0, 4.0, 5.0 ] ); +* var A = new ndarray( 'float32', new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ), [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); +* +* var alpha = scalar2ndarray( 2.0, { +* 'dtype': 'float32' +* }); +* +* var z = sger( [ x, y, A, alpha ] ); +* // returns [ [ 7.0, 10.0, 13.0 ], [ 16.0, 21.0, 26.0 ] ] +* +* var bool = ( z === A ); +* // returns true +*/ +function sger( arrays ) { + var alpha = ndarraylike2scalar( arrays[ 3 ] ); + var x = arrays[ 0 ]; + var y = arrays[ 1 ]; + var A = arrays[ 2 ]; + strided( numelDimension( A, 0 ), numelDimension( A, 1 ), alpha, getData( x ), getStride( x, 0 ), getOffset( x ), getData( y ), getStride( y, 0 ), getOffset( y ), getData( A ), getStride( A, 0 ), getStride( A, 1 ), getOffset( A ) ); // eslint-disable-line max-len + return A; +} + + +// EXPORTS // + +module.exports = sger; diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/sger/package.json b/lib/node_modules/@stdlib/blas/base/ndarray/sger/package.json new file mode 100644 index 000000000000..7384175240ca --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/sger/package.json @@ -0,0 +1,72 @@ +{ + "name": "@stdlib/blas/base/ndarray/sger", + "version": "0.0.0", + "description": "Perform the rank 1 operation `A = alpha*x*y^T + A`.", + "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 2", + "sger", + "linear", + "algebra", + "subroutines", + "rank-1", + "update", + "vector", + "matrix", + "array", + "ndarray", + "float32", + "single", + "float32array" + ] +} diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/sger/test/test.js b/lib/node_modules/@stdlib/blas/base/ndarray/sger/test/test.js new file mode 100644 index 000000000000..fad15c920a6c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/sger/test/test.js @@ -0,0 +1,291 @@ +/** +* @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 isSameFloat32Array = require( '@stdlib/assert/is-same-float32array' ); +var Float32Array = require( '@stdlib/array/float32' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var sger = 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( 'float32', buffer, [ length ], [ stride ], offset, 'row-major' ); +} + +/** +* Returns a two-dimensional ndarray. +* +* @private +* @param {Collection} buffer - underlying data buffer +* @param {NonNegativeInteger} M - number of rows +* @param {NonNegativeInteger} N - number of columns +* @param {integer} stride0 - stride of the first dimension +* @param {integer} stride1 - stride of the second dimension +* @param {NonNegativeInteger} offset - index offset +* @returns {ndarray} two-dimensional ndarray +*/ +function matrix( buffer, M, N, stride0, stride1, offset ) { + return new ndarray( 'float32', buffer, [ M, N ], [ stride0, stride1 ], offset, 'row-major' ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof sger, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 1', function test( t ) { + t.strictEqual( sger.length, 1, 'has expected arity' ); + t.end(); +}); + +tape( 'the function performs the rank 1 operation `A = alpha*x*y^T + A`', function test( t ) { + var expected; + var alpha; + var xbuf; + var ybuf; + var Abuf; + var x; + var y; + var A; + var v; + + xbuf = new Float32Array( [ 1.0, 2.0 ] ); + ybuf = new Float32Array( [ 1.0, 2.0, 3.0 ] ); + Abuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + x = vector( xbuf, 2, 1, 0 ); + y = vector( ybuf, 3, 1, 0 ); + A = matrix( Abuf, 2, 3, 3, 1, 0 ); + alpha = scalar2ndarray( 2.0, { + 'dtype': 'float32' + }); + + v = sger( [ x, y, A, alpha ] ); + + expected = new Float32Array( [ 3.0, 6.0, 9.0, 8.0, 13.0, 18.0 ] ); + t.strictEqual( v, A, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( getData( v ), expected ), true, 'returns expected value' ); + + xbuf = new Float32Array( [ 1.0, 1.0 ] ); + ybuf = new Float32Array( [ 1.0, 1.0, 1.0 ] ); + Abuf = new Float32Array( [ 1.0, 4.0, 2.0, 5.0, 3.0, 6.0 ] ); + x = vector( xbuf, 2, 1, 0 ); + y = vector( ybuf, 3, 1, 0 ); + A = matrix( Abuf, 2, 3, 1, 2, 0 ); + alpha = scalar2ndarray( 2.0, { + 'dtype': 'float32' + }); + + v = sger( [ x, y, A, alpha ] ); + + expected = new Float32Array( [ 3.0, 6.0, 4.0, 7.0, 5.0, 8.0 ] ); + t.strictEqual( v, A, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( getData( v ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `alpha` is `0`, the function returns `A` unchanged', function test( t ) { + var expected; + var alpha; + var xbuf; + var ybuf; + var Abuf; + var x; + var y; + var A; + var v; + + xbuf = new Float32Array( [ 1.0, 2.0 ] ); + ybuf = new Float32Array( [ 3.0, 4.0, 5.0 ] ); + Abuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + x = vector( xbuf, 2, 1, 0 ); + y = vector( ybuf, 3, 1, 0 ); + A = matrix( Abuf, 2, 3, 3, 1, 0 ); + alpha = scalar2ndarray( 0.0, { + 'dtype': 'float32' + }); + + v = sger( [ x, y, A, alpha ] ); + + expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + t.strictEqual( v, A, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( getData( v ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports ndarrays having non-unit strides', function test( t ) { + var expected; + var alpha; + var xbuf; + var ybuf; + var Abuf; + var x; + var y; + var A; + var v; + + xbuf = new Float32Array([ + 1.0, // 0 + 0.0, + 2.0 // 1 + ]); + x = vector( xbuf, 2, 2, 0 ); + + ybuf = new Float32Array([ + 1.0, // 0 + 0.0, + 2.0, // 1 + 0.0, + 3.0 // 2 + ]); + y = vector( ybuf, 3, 2, 0 ); + + Abuf = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + A = matrix( Abuf, 2, 3, 3, 1, 0 ); + alpha = scalar2ndarray( 2.0, { + 'dtype': 'float32' + }); + + v = sger( [ x, y, A, alpha ] ); + + expected = new Float32Array( [ 2.0, 4.0, 6.0, 4.0, 8.0, 12.0 ] ); + t.strictEqual( v, A, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( getData( v ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports ndarrays having negative strides', function test( t ) { + var expected; + var alpha; + var xbuf; + var ybuf; + var Abuf; + var x; + var y; + var A; + var v; + + xbuf = new Float32Array([ + 2.0, // 1 + 1.0 // 0 + ]); + x = vector( xbuf, 2, -1, 1 ); + + ybuf = new Float32Array([ + 3.0, // 2 + 2.0, // 1 + 1.0 // 0 + ]); + y = vector( ybuf, 3, -1, 2 ); + + Abuf = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + A = matrix( Abuf, 2, 3, 3, 1, 0 ); + alpha = scalar2ndarray( 2.0, { + 'dtype': 'float32' + }); + + v = sger( [ x, y, A, alpha ] ); + + expected = new Float32Array( [ 2.0, 4.0, 6.0, 4.0, 8.0, 12.0 ] ); + t.strictEqual( v, A, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( getData( v ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports ndarrays having non-zero offsets', function test( t ) { + var expected; + var alpha; + var xbuf; + var ybuf; + var Abuf; + var x; + var y; + var A; + var v; + + xbuf = new Float32Array([ + 0.0, + 1.0, // 0 + 0.0, + 2.0 // 1 + ]); + x = vector( xbuf, 2, 2, 1 ); + + ybuf = new Float32Array([ + 0.0, + 0.0, + 1.0, // 0 + 2.0, // 1 + 3.0 // 2 + ]); + y = vector( ybuf, 3, 1, 2 ); + + Abuf = new Float32Array([ + 999.0, + 999.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]); + A = matrix( Abuf, 2, 3, 3, 1, 2 ); + alpha = scalar2ndarray( 2.0, { + 'dtype': 'float32' + }); + + v = sger( [ x, y, A, alpha ] ); + + expected = new Float32Array([ + 999.0, + 999.0, + 2.0, + 4.0, + 6.0, + 4.0, + 8.0, + 12.0 + ]); + t.strictEqual( v, A, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( getData( v ), expected ), true, 'returns expected value' ); + t.end(); +}); From bdaa3669b4192dcbe42d100b5f224ad00f937a7c Mon Sep 17 00:00:00 2001 From: Kaustubh Patange Date: Tue, 9 Jun 2026 23:45:56 +0530 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Kaustubh Patange Signed-off-by: Kaustubh Patange --- .../@stdlib/blas/base/ndarray/sger/benchmark/benchmark.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/sger/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/ndarray/sger/benchmark/benchmark.js index 5b817e2194a6..b59ddb82c2d4 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/sger/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/base/ndarray/sger/benchmark/benchmark.js @@ -52,9 +52,9 @@ function createBenchmark( len ) { var y; var A; + A = uniform( [ len, len ], -100.0, 100.0, options ); x = uniform( [ len ], -100.0, 100.0, options ); y = uniform( [ len ], -100.0, 100.0, options ); - A = uniform( [ len, len ], -100.0, 100.0, options ); alpha = scalar2ndarray( 1.0, options ); From e814e2afb1535b01a1a3e7b76a972370d3211bae Mon Sep 17 00:00:00 2001 From: kaustubh Date: Wed, 10 Jun 2026 00:13:19 +0530 Subject: [PATCH 3/3] fix: resolve lint errors --- 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: na - 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: na - task: lint_license_headers status: passed --- --- .../@stdlib/blas/base/ndarray/sger/benchmark/benchmark.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/sger/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/ndarray/sger/benchmark/benchmark.js index b59ddb82c2d4..5b817e2194a6 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/sger/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/base/ndarray/sger/benchmark/benchmark.js @@ -52,9 +52,9 @@ function createBenchmark( len ) { var y; var A; - A = uniform( [ len, len ], -100.0, 100.0, options ); x = uniform( [ len ], -100.0, 100.0, options ); y = uniform( [ len ], -100.0, 100.0, options ); + A = uniform( [ len, len ], -100.0, 100.0, options ); alpha = scalar2ndarray( 1.0, options );