From b085e78140d7c0b265996ed170634ae55744657c Mon Sep 17 00:00:00 2001 From: kaustubh Date: Sat, 13 Jun 2026 00:19:59 +0530 Subject: [PATCH 1/4] feat: add blas/base/ndarray/dsyr --- 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/dsyr/README.md | 127 +++++++++ .../base/ndarray/dsyr/benchmark/benchmark.js | 112 ++++++++ .../blas/base/ndarray/dsyr/docs/repl.txt | 36 +++ .../base/ndarray/dsyr/docs/types/index.d.ts | 63 +++++ .../blas/base/ndarray/dsyr/docs/types/test.ts | 69 +++++ .../blas/base/ndarray/dsyr/examples/index.js | 39 +++ .../blas/base/ndarray/dsyr/lib/index.js | 54 ++++ .../blas/base/ndarray/dsyr/lib/main.js | 77 ++++++ .../blas/base/ndarray/dsyr/package.json | 73 +++++ .../blas/base/ndarray/dsyr/test/test.js | 260 ++++++++++++++++++ 10 files changed, 910 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/dsyr/README.md create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/dsyr/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/dsyr/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/dsyr/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/dsyr/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/dsyr/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/dsyr/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/dsyr/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/dsyr/package.json create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/dsyr/test/test.js diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/README.md b/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/README.md new file mode 100644 index 000000000000..21d4ea7fd2ea --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/README.md @@ -0,0 +1,127 @@ + + +# dsyr + +> Perform the symmetric rank 1 operation `A = alpha*x*x^T + A`. + +
+ +
+ + + +
+ +## Usage + +```javascript +var dsyr = require( '@stdlib/blas/base/ndarray/dsyr' ); +``` + +#### dsyr( arrays ) + +Performs the symmetric rank 1 operation `A = alpha*x*x^T + A`, where `alpha` is a scalar, `x` is an `N` element ndarray, and `A` is an `N` by `N` symmetric matrix. + +```javascript +var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Vector( [ 1.0, 2.0, 3.0 ] ); +var A = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0 ] ), [ 3, 3 ], [ 3, 1 ], 0, 'row-major' ); + +var alpha = scalar2ndarray( 2.0, { + 'dtype': 'float64' +}); + +var out = dsyr( [ x, A, alpha ] ); +// returns [ [ 3.0, 6.0, 9.0 ], [ 2.0, 9.0, 14.0 ], [ 3.0, 2.0, 19.0 ] ] + +var bool = ( out === A ); +// returns true +``` + +The function has the following parameters: + +- **arrays**: array-like object containing the following ndarrays: + + - a one-dimensional input ndarray. + - a two-dimensional input/output 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 Float64Array = require( '@stdlib/array/float64' ); +var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var dsyr = require( '@stdlib/blas/base/ndarray/dsyr' ); + +var opts = { + 'dtype': 'float64' +}; + +var x = new Float64Vector( discreteUniform( 3, 0, 10, opts ) ); +var A = new ndarray( 'float64', new Float64Array( discreteUniform( 9, 0, 10, opts ) ), [ 3, 3 ], [ 3, 1 ], 0, 'row-major' ); + +var alpha = scalar2ndarray( 1.0, opts ); + +var out = dsyr( [ x, A, alpha ] ); +console.log( ndarray2array( out ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/benchmark/benchmark.js new file mode 100644 index 000000000000..c9e64d514b56 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/benchmark/benchmark.js @@ -0,0 +1,112 @@ +/** +* @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 dsyr = 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 alpha; + var x; + var A; + + x = 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 = dsyr( [ x, A, alpha ] ); + if ( typeof z !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( 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/dsyr/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/docs/repl.txt new file mode 100644 index 000000000000..80839cac8ea6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/docs/repl.txt @@ -0,0 +1,36 @@ + +{{alias}}( arrays ) + Performs the symmetric rank 1 operation `A = alpha*x*x^T + A`, where + `alpha` is a scalar, `x` is an `N` element ndarray, and `A` is an + `N` by `N` symmetric matrix. + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing the following ndarrays: + + - a one-dimensional input ndarray. + - a two-dimensional input/output ndarray. + - a zero-dimensional ndarray containing a scalar constant. + + Returns + ------- + out: ndarray + Output ndarray. + + Examples + -------- + > var x = new {{alias:@stdlib/ndarray/vector/float64}}( [ 1.0, 2.0 ] ); + > var buf = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 2.0, 1.0 ] ); + > var sh = [ 2, 2 ]; + > var st = [ 2, 1 ]; + > var A = new {{alias:@stdlib/ndarray/base/ctor}}( 'float64', buf, sh, st, 0, 'row-major' ); + > var alpha = {{alias:@stdlib/ndarray/from-scalar}}( 2.0, { 'dtype': 'float64' }); + + > {{alias}}( [ x, A, alpha ] ); + > A + [ [ 3.0, 6.0 ], [ 2.0, 9.0 ] ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/docs/types/index.d.ts new file mode 100644 index 000000000000..27444ede09d6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/docs/types/index.d.ts @@ -0,0 +1,63 @@ +/* +* @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'; + +/** +* Performs the symmetric rank 1 operation `A = alpha*x*x^T + A`, where `alpha` is a scalar, `x` is an `N` element ndarray, and `A` is an `N` by `N` symmetric matrix. +* +* ## Notes +* +* - The function expects the following ndarrays: +* +* - a one-dimensional input ndarray. +* - a two-dimensional input/output ndarray. +* - a zero-dimensional ndarray containing a scalar constant. +* +* @param arrays - array-like object containing ndarrays +* @returns output ndarray +* +* @example +* var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Vector( [ 1.0, 2.0, 3.0 ] ); +* var A = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0 ] ), [ 3, 3 ], [ 3, 1 ], 0, 'row-major' ); +* +* var alpha = scalar2ndarray( 2.0, { +* 'dtype': 'float64' +* }); +* +* var out = dsyr( [ x, A, alpha ] ); +* // returns [ [ 3.0, 6.0, 9.0 ], [ 2.0, 9.0, 14.0 ], [ 3.0, 2.0, 19.0 ] ] +* +* var bool = ( out === A ); +* // returns true +*/ +declare function dsyr( arrays: [ float64ndarray, float64ndarray, float64ndarray ] ): float64ndarray; + + +// EXPORTS // + +export = dsyr; diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/docs/types/test.ts b/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/docs/types/test.ts new file mode 100644 index 000000000000..cdf38ba48ea1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/docs/types/test.ts @@ -0,0 +1,69 @@ +/* +* @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 dsyr = require( '@stdlib/blas/base/ndarray/dsyr' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 3 ], { + 'dtype': 'float64' + }); + const A = zeros( [ 3, 3 ], { + 'dtype': 'float64' + }); + const alpha = zeros( [], { + 'dtype': 'float64' + }); + + dsyr( [ x, A, alpha ] ); // $ExpectType float64ndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + dsyr( '10' ); // $ExpectError + dsyr( 10 ); // $ExpectError + dsyr( true ); // $ExpectError + dsyr( false ); // $ExpectError + dsyr( null ); // $ExpectError + dsyr( undefined ); // $ExpectError + dsyr( [] ); // $ExpectError + dsyr( {} ); // $ExpectError + dsyr( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 3 ], { + 'dtype': 'float64' + }); + const A = zeros( [ 3, 3 ], { + 'dtype': 'float64' + }); + const alpha = zeros( [], { + 'dtype': 'float64' + }); + + dsyr(); // $ExpectError + dsyr( [ x, A, alpha ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/examples/index.js b/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/examples/index.js new file mode 100644 index 000000000000..bed1104fe0ac --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/examples/index.js @@ -0,0 +1,39 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var dsyr = require( './../lib' ); + +var opts = { + 'dtype': 'float64' +}; + +var x = new Float64Vector( discreteUniform( 3, 0, 10, opts ) ); +var A = new ndarray( 'float64', new Float64Array( discreteUniform( 9, 0, 10, opts ) ), [ 3, 3 ], [ 3, 1 ], 0, 'row-major' ); + +var alpha = scalar2ndarray( 1.0, opts ); + +var out = dsyr( [ x, A, alpha ] ); +console.log( ndarray2array( out ) ); diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/lib/index.js b/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/lib/index.js new file mode 100644 index 000000000000..b624280cb5bf --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/lib/index.js @@ -0,0 +1,54 @@ +/** +* @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 symmetric rank 1 operation `A = alpha*x*x^T + A`. +* +* @module @stdlib/blas/base/ndarray/dsyr +* +* @example +* var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var Float64Array = require( '@stdlib/array/float64' ); +* var dsyr = require( '@stdlib/blas/base/ndarray/dsyr' ); +* +* var x = new Float64Vector( [ 1.0, 2.0, 3.0 ] ); +* var A = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0 ] ), [ 3, 3 ], [ 3, 1 ], 0, 'row-major' ); +* +* var alpha = scalar2ndarray( 2.0, { +* 'dtype': 'float64' +* }); +* +* var out = dsyr( [ x, A, alpha ] ); +* // returns [ [ 3.0, 6.0, 9.0 ], [ 2.0, 9.0, 14.0 ], [ 3.0, 2.0, 19.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/dsyr/lib/main.js b/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/lib/main.js new file mode 100644 index 000000000000..ba85e747d0fd --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/lib/main.js @@ -0,0 +1,77 @@ +/** +* @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/dsyr' ).ndarray; + + +// MAIN // + +/** +* Performs the symmetric rank 1 operation `A = alpha*x*x^T + A`, where `alpha` is a scalar, `x` is an `N` element ndarray, and `A` is an `N` by `N` symmetric matrix. +* +* ## Notes +* +* - The function expects the following ndarrays: +* +* - a one-dimensional input ndarray. +* - a two-dimensional input/output ndarray. +* - a zero-dimensional ndarray containing a scalar constant. +* +* @param {ArrayLikeObject} arrays - array-like object containing ndarrays +* @returns {Object} output ndarray +* +* @example +* var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Vector( [ 1.0, 2.0, 3.0 ] ); +* var A = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0 ] ), [ 3, 3 ], [ 3, 1 ], 0, 'row-major' ); +* +* var alpha = scalar2ndarray( 2.0, { +* 'dtype': 'float64' +* }); +* +* var out = dsyr( [ x, A, alpha ] ); +* // returns [ [ 3.0, 6.0, 9.0 ], [ 2.0, 9.0, 14.0 ], [ 3.0, 2.0, 19.0 ] ] +* +* var bool = ( out === A ); +* // returns true +*/ +function dsyr( arrays ) { + var alpha = ndarraylike2scalar( arrays[ 2 ] ); + var x = arrays[ 0 ]; + var A = arrays[ 1 ]; + strided( 'upper', numelDimension( A, 0 ), alpha, getData( x ), getStride( x, 0 ), getOffset( x ), getData( A ), getStride( A, 0 ), getStride( A, 1 ), getOffset( A ) ); + return A; +} + + +// EXPORTS // + +module.exports = dsyr; diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/package.json b/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/package.json new file mode 100644 index 000000000000..14159875174b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/package.json @@ -0,0 +1,73 @@ +{ + "name": "@stdlib/blas/base/ndarray/dsyr", + "version": "0.0.0", + "description": "Perform the symmetric rank 1 operation `A = alpha*x*x^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", + "dsyr", + "linear", + "algebra", + "subroutines", + "symmetric", + "rank-1", + "update", + "vector", + "matrix", + "array", + "ndarray", + "float64", + "double", + "float64array" + ] +} diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/test/test.js b/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/test/test.js new file mode 100644 index 000000000000..d77389c468d1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/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 dsyr = 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' ); +} + +/** +* Returns a two-dimensional ndarray. +* +* @private +* @param {Collection} buffer - underlying data buffer +* @param {NonNegativeInteger} N - number of rows and 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, N, stride0, stride1, offset ) { + return new ndarray( 'float64', buffer, [ N, N ], [ stride0, stride1 ], offset, 'row-major' ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dsyr, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 1', function test( t ) { + t.strictEqual( dsyr.length, 1, 'has expected arity' ); + t.end(); +}); + +tape( 'the function performs the symmetric rank 1 operation `A = alpha*x*x^T + A`', function test( t ) { + var expected; + var alpha; + var xbuf; + var Abuf; + var x; + var A; + var v; + + xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + Abuf = new Float64Array( [ 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0 ] ); + x = vector( xbuf, 3, 1, 0 ); + A = matrix( Abuf, 3, 3, 1, 0 ); + alpha = scalar2ndarray( 2.0, { + 'dtype': 'float64' + }); + + v = dsyr( [ x, A, alpha ] ); + + expected = new Float64Array( [ 3.0, 6.0, 9.0, 2.0, 9.0, 14.0, 3.0, 2.0, 19.0 ] ); + t.strictEqual( v, A, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( v ), expected ), true, 'returns expected value' ); + + xbuf = new Float64Array( [ 1.0, 1.0, 1.0 ] ); + Abuf = new Float64Array( [ 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0 ] ); + x = vector( xbuf, 3, 1, 0 ); + A = matrix( Abuf, 3, 1, 3, 0 ); + alpha = scalar2ndarray( 2.0, { + 'dtype': 'float64' + }); + + v = dsyr( [ x, A, alpha ] ); + + expected = new Float64Array( [ 3.0, 2.0, 3.0, 4.0, 3.0, 2.0, 5.0, 4.0, 3.0 ] ); + t.strictEqual( v, A, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( 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 Abuf; + var x; + var A; + var v; + + xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + Abuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); + x = vector( xbuf, 3, 1, 0 ); + A = matrix( Abuf, 3, 3, 1, 0 ); + alpha = scalar2ndarray( 0.0, { + 'dtype': 'float64' + }); + + v = dsyr( [ x, A, alpha ] ); + + expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); + t.strictEqual( v, A, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( 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 Abuf; + var x; + var A; + var v; + + xbuf = new Float64Array([ + 1.0, // 0 + 0.0, + 2.0, // 1 + 0.0, + 3.0 // 2 + ]); + x = vector( xbuf, 3, 2, 0 ); + + Abuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + A = matrix( Abuf, 3, 3, 1, 0 ); + alpha = scalar2ndarray( 2.0, { + 'dtype': 'float64' + }); + + v = dsyr( [ x, A, alpha ] ); + + expected = new Float64Array( [ 2.0, 4.0, 6.0, 0.0, 8.0, 12.0, 0.0, 0.0, 18.0 ] ); + t.strictEqual( v, A, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( 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 Abuf; + var x; + var A; + var v; + + xbuf = new Float64Array([ + 3.0, // 2 + 2.0, // 1 + 1.0 // 0 + ]); + x = vector( xbuf, 3, -1, 2 ); + + Abuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + A = matrix( Abuf, 3, 3, 1, 0 ); + alpha = scalar2ndarray( 2.0, { + 'dtype': 'float64' + }); + + v = dsyr( [ x, A, alpha ] ); + + expected = new Float64Array( [ 2.0, 4.0, 6.0, 0.0, 8.0, 12.0, 0.0, 0.0, 18.0 ] ); + t.strictEqual( v, A, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( 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 Abuf; + var x; + var A; + var v; + + xbuf = new Float64Array([ + 0.0, + 1.0, // 0 + 0.0, + 2.0, // 1 + 0.0, + 3.0 // 2 + ]); + x = vector( xbuf, 3, 2, 1 ); + + Abuf = new Float64Array([ + 999.0, + 999.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]); + A = matrix( Abuf, 3, 3, 1, 2 ); + alpha = scalar2ndarray( 2.0, { + 'dtype': 'float64' + }); + + v = dsyr( [ x, A, alpha ] ); + + expected = new Float64Array([ + 999.0, + 999.0, + 2.0, + 4.0, + 6.0, + 0.0, + 8.0, + 12.0, + 0.0, + 0.0, + 18.0 + ]); + t.strictEqual( v, A, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( v ), expected ), true, 'returns expected value' ); + t.end(); +}); From 6edabcebe0c2d122503adde1ee6a13335416e525 Mon Sep 17 00:00:00 2001 From: kaustubh Date: Fri, 10 Jul 2026 11:07:12 +0530 Subject: [PATCH 2/4] feat: add Float64Matrix and cleanup --- 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: 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/dsyr/README.md | 39 ++++-- .../base/ndarray/dsyr/benchmark/benchmark.js | 7 +- .../blas/base/ndarray/dsyr/docs/repl.txt | 33 +++-- .../base/ndarray/dsyr/docs/types/index.d.ts | 30 ++-- .../blas/base/ndarray/dsyr/docs/types/test.ts | 10 +- .../blas/base/ndarray/dsyr/examples/index.js | 11 +- .../blas/base/ndarray/dsyr/lib/index.js | 17 ++- .../blas/base/ndarray/dsyr/lib/main.js | 52 ++++--- .../blas/base/ndarray/dsyr/test/test.js | 131 +++++++++++++----- 9 files changed, 224 insertions(+), 106 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/README.md b/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/README.md index 21d4ea7fd2ea..75a145b26a1d 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/README.md +++ b/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/README.md @@ -38,25 +38,29 @@ var dsyr = require( '@stdlib/blas/base/ndarray/dsyr' ); #### dsyr( arrays ) -Performs the symmetric rank 1 operation `A = alpha*x*x^T + A`, where `alpha` is a scalar, `x` is an `N` element ndarray, and `A` is an `N` by `N` symmetric matrix. +Performs the symmetric rank 1 operation `A = alpha*x*x^T + A`, where `alpha` is a scalar, `x` is a one-dimensional ndarray, and `A` is an `N` by `N` symmetric matrix. ```javascript +/* eslint-disable max-len */ +var Float64Matrix = require( '@stdlib/ndarray/matrix/float64' ); var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); -var ndarray = require( '@stdlib/ndarray/base/ctor' ); -var Float64Array = require( '@stdlib/array/float64' ); +var resolveEnum = require( '@stdlib/blas/base/matrix-triangle-resolve-enum' ); var x = new Float64Vector( [ 1.0, 2.0, 3.0 ] ); -var A = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0 ] ), [ 3, 3 ], [ 3, 1 ], 0, 'row-major' ); +var A = new Float64Matrix( [ [ 1.0, 2.0, 3.0 ], [ 2.0, 1.0, 2.0 ], [ 3.0, 2.0, 1.0 ] ] ); -var alpha = scalar2ndarray( 2.0, { +var uplo = scalar2ndarray( resolveEnum( 'upper' ), { + 'dtype': 'int8' +}); +var alpha = scalar2ndarray( 1.0, { 'dtype': 'float64' }); -var out = dsyr( [ x, A, alpha ] ); -// returns [ [ 3.0, 6.0, 9.0 ], [ 2.0, 9.0, 14.0 ], [ 3.0, 2.0, 19.0 ] ] +var y = dsyr( [ x, A, uplo, alpha ] ); +// returns [ [ 2.0, 4.0, 6.0 ], [ 2.0, 5.0, 8.0 ], [ 3.0, 2.0, 10.0 ] ] -var bool = ( out === A ); +var bool = ( y === A ); // returns true ``` @@ -64,9 +68,10 @@ The function has the following parameters: - **arrays**: array-like object containing the following ndarrays: - - a one-dimensional input ndarray. - - a two-dimensional input/output ndarray. - - a zero-dimensional ndarray containing a scalar constant. + - a one-dimensional input ndarray corresponding to `x`. + - a two-dimensional input/output ndarray corresponding to `A`. + - a zero-dimensional ndarray specifying whether the upper or lower triangular part of `A` should be referenced. + - a zero-dimensional ndarray containing a scalar constant corresponding to `alpha`. @@ -85,11 +90,12 @@ The function has the following parameters: ```javascript +/* eslint-disable max-len */ var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); -var ndarray = require( '@stdlib/ndarray/base/ctor' ); -var Float64Array = require( '@stdlib/array/float64' ); +var Float64Matrix = require( '@stdlib/ndarray/matrix/float64' ); var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var resolveEnum = require( '@stdlib/blas/base/matrix-triangle-resolve-enum' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); var dsyr = require( '@stdlib/blas/base/ndarray/dsyr' ); @@ -98,11 +104,14 @@ var opts = { }; var x = new Float64Vector( discreteUniform( 3, 0, 10, opts ) ); -var A = new ndarray( 'float64', new Float64Array( discreteUniform( 9, 0, 10, opts ) ), [ 3, 3 ], [ 3, 1 ], 0, 'row-major' ); +var A = new Float64Matrix( discreteUniform( 9, 0, 10, opts ).buffer, 0, [ 3, 3 ] ); +var uplo = scalar2ndarray( resolveEnum( 'upper' ), { + 'dtype': 'int8' +}); var alpha = scalar2ndarray( 1.0, opts ); -var out = dsyr( [ x, A, alpha ] ); +var out = dsyr( [ x, A, uplo, alpha ] ); console.log( ndarray2array( out ) ); ``` diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/benchmark/benchmark.js index c9e64d514b56..d23f6ac32f59 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/benchmark/benchmark.js @@ -25,6 +25,7 @@ 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 resolveEnum = require( '@stdlib/blas/base/matrix-triangle-resolve-enum' ); var format = require( '@stdlib/string/format' ); var pkg = require( './../package.json' ).name; var dsyr = require( './../lib' ); @@ -48,6 +49,7 @@ var options = { */ function createBenchmark( len ) { var alpha; + var uplo; var x; var A; @@ -55,6 +57,9 @@ function createBenchmark( len ) { A = uniform( [ len, len ], -100.0, 100.0, options ); alpha = scalar2ndarray( 1.0, options ); + uplo = scalar2ndarray( resolveEnum( 'upper' ), { + 'dtype': 'int8' + }); return benchmark; @@ -70,7 +75,7 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - z = dsyr( [ x, A, alpha ] ); + z = dsyr( [ x, A, uplo, alpha ] ); if ( typeof z !== 'object' ) { b.fail( 'should return an ndarray' ); } diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/docs/repl.txt index 80839cac8ea6..508f50c28739 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}( arrays ) Performs the symmetric rank 1 operation `A = alpha*x*x^T + A`, where - `alpha` is a scalar, `x` is an `N` element ndarray, and `A` is an + `alpha` is a scalar, `x` is a one-dimensional ndarray, and `A` is an `N` by `N` symmetric matrix. Parameters @@ -9,9 +9,12 @@ arrays: ArrayLikeObject Array-like object containing the following ndarrays: - - a one-dimensional input ndarray. - - a two-dimensional input/output ndarray. - - a zero-dimensional ndarray containing a scalar constant. + - a one-dimensional input ndarray corresponding to `x`. + - a two-dimensional input/output ndarray corresponding to `A`. + - a zero-dimensional ndarray specifying whether the upper or lower + triangular part of `A` should be referenced. + - a zero-dimensional ndarray containing a scalar constant corresponding + to `alpha`. Returns ------- @@ -20,16 +23,20 @@ Examples -------- - > var x = new {{alias:@stdlib/ndarray/vector/float64}}( [ 1.0, 2.0 ] ); - > var buf = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 2.0, 1.0 ] ); - > var sh = [ 2, 2 ]; - > var st = [ 2, 1 ]; - > var A = new {{alias:@stdlib/ndarray/base/ctor}}( 'float64', buf, sh, st, 0, 'row-major' ); - > var alpha = {{alias:@stdlib/ndarray/from-scalar}}( 2.0, { 'dtype': 'float64' }); - - > {{alias}}( [ x, A, alpha ] ); + > var xbuf = [ 1.0, 2.0, 3.0 ]; + > var x = new {{alias:@stdlib/ndarray/vector/float64}}( xbuf ); + + > var abuf = [ [ 1.0, 2.0, 3.0 ], [ 2.0, 1.0, 2.0 ], [ 3.0, 2.0, 1.0 ] ]; + > var A = new {{alias:@stdlib/ndarray/matrix/float64}}( abuf ); + + > var opts = { 'dtype': 'float64' }; + > var alpha = {{alias:@stdlib/ndarray/from-scalar}}( 1.0, opts ); + + > var uplo = {{alias:@stdlib/ndarray/from-scalar}}( 'upper' ); + + > {{alias}}( [ x, A, uplo, alpha ] ); > A - [ [ 3.0, 6.0 ], [ 2.0, 9.0 ] ] + [ [ 2.0, 4.0, 6.0 ], [ 2.0, 5.0, 8.0 ], [ 3.0, 2.0, 10.0 ] ] See Also -------- diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/docs/types/index.d.ts index 27444ede09d6..704e3e5fd12b 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/docs/types/index.d.ts @@ -20,42 +20,46 @@ /// -import { float64ndarray } from '@stdlib/types/ndarray'; +import { float64ndarray, ndarray } from '@stdlib/types/ndarray'; /** -* Performs the symmetric rank 1 operation `A = alpha*x*x^T + A`, where `alpha` is a scalar, `x` is an `N` element ndarray, and `A` is an `N` by `N` symmetric matrix. +* Performs the symmetric rank 1 operation `A = alpha*x*x^T + A`, where `alpha` is a scalar, `x` is a one-dimensional ndarray, and `A` is an `N` by `N` symmetric matrix. * * ## Notes * * - The function expects the following ndarrays: * -* - a one-dimensional input ndarray. -* - a two-dimensional input/output ndarray. -* - a zero-dimensional ndarray containing a scalar constant. +* - a one-dimensional input ndarray corresponding to `x`. +* - a two-dimensional input/output ndarray corresponding to `A`. +* - a zero-dimensional ndarray specifying whether the upper or lower triangular part of `A` should be referenced. +* - a zero-dimensional ndarray containing a scalar constant corresponding to `alpha`. * * @param arrays - array-like object containing ndarrays * @returns output ndarray * * @example +* var Float64Matrix = require( '@stdlib/ndarray/matrix/float64' ); * var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); * var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); -* var ndarray = require( '@stdlib/ndarray/base/ctor' ); -* var Float64Array = require( '@stdlib/array/float64' ); +* var resolveEnum = require( '@stdlib/blas/base/matrix-triangle-resolve-enum' ); * * var x = new Float64Vector( [ 1.0, 2.0, 3.0 ] ); -* var A = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0 ] ), [ 3, 3 ], [ 3, 1 ], 0, 'row-major' ); +* var A = new Float64Matrix( [ [ 1.0, 2.0, 3.0 ], [ 2.0, 1.0, 2.0 ], [ 3.0, 2.0, 1.0 ] ] ); * -* var alpha = scalar2ndarray( 2.0, { +* var uplo = scalar2ndarray( resolveEnum( 'upper' ), { +* 'dtype': 'int8' +* }); +* var alpha = scalar2ndarray( 1.0, { * 'dtype': 'float64' * }); * -* var out = dsyr( [ x, A, alpha ] ); -* // returns [ [ 3.0, 6.0, 9.0 ], [ 2.0, 9.0, 14.0 ], [ 3.0, 2.0, 19.0 ] ] +* var y = dsyr( [ x, A, uplo, alpha ] ); +* // returns [ [ 2.0, 4.0, 6.0 ], [ 2.0, 5.0, 8.0 ], [ 3.0, 2.0, 10.0 ] ] * -* var bool = ( out === A ); +* var bool = ( y === A ); * // returns true */ -declare function dsyr( arrays: [ float64ndarray, float64ndarray, float64ndarray ] ): float64ndarray; +declare function dsyr( arrays: [ float64ndarray, float64ndarray, ndarray, float64ndarray ] ): float64ndarray; // EXPORTS // diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/docs/types/test.ts b/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/docs/types/test.ts index cdf38ba48ea1..80de4ebc4612 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/docs/types/test.ts +++ b/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/docs/types/test.ts @@ -32,11 +32,14 @@ import dsyr = require( '@stdlib/blas/base/ndarray/dsyr' ); const A = zeros( [ 3, 3 ], { 'dtype': 'float64' }); + const uplo = zeros( [], { + 'dtype': 'int8' + }); const alpha = zeros( [], { 'dtype': 'float64' }); - dsyr( [ x, A, alpha ] ); // $ExpectType float64ndarray + dsyr( [ x, A, uplo, alpha ] ); // $ExpectType float64ndarray } // The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... @@ -60,10 +63,13 @@ import dsyr = require( '@stdlib/blas/base/ndarray/dsyr' ); const A = zeros( [ 3, 3 ], { 'dtype': 'float64' }); + const uplo = zeros( [], { + 'dtype': 'int8' + }); const alpha = zeros( [], { 'dtype': 'float64' }); dsyr(); // $ExpectError - dsyr( [ x, A, alpha ], {} ); // $ExpectError + dsyr( [ x, A, uplo, alpha ], {} ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/examples/index.js b/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/examples/index.js index bed1104fe0ac..4b240dbb57a7 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/examples/index.js +++ b/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/examples/index.js @@ -19,10 +19,10 @@ 'use strict'; var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); -var ndarray = require( '@stdlib/ndarray/base/ctor' ); -var Float64Array = require( '@stdlib/array/float64' ); +var Float64Matrix = require( '@stdlib/ndarray/matrix/float64' ); var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var resolveEnum = require( '@stdlib/blas/base/matrix-triangle-resolve-enum' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); var dsyr = require( './../lib' ); @@ -31,9 +31,12 @@ var opts = { }; var x = new Float64Vector( discreteUniform( 3, 0, 10, opts ) ); -var A = new ndarray( 'float64', new Float64Array( discreteUniform( 9, 0, 10, opts ) ), [ 3, 3 ], [ 3, 1 ], 0, 'row-major' ); +var A = new Float64Matrix( discreteUniform( 9, 0, 10, opts ).buffer, 0, [ 3, 3 ] ); +var uplo = scalar2ndarray( resolveEnum( 'upper' ), { + 'dtype': 'int8' +}); var alpha = scalar2ndarray( 1.0, opts ); -var out = dsyr( [ x, A, alpha ] ); +var out = dsyr( [ x, A, uplo, alpha ] ); console.log( ndarray2array( out ) ); diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/lib/index.js b/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/lib/index.js index b624280cb5bf..c91fee16e1cd 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/lib/index.js +++ b/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/lib/index.js @@ -24,23 +24,26 @@ * @module @stdlib/blas/base/ndarray/dsyr * * @example +* var Float64Matrix = require( '@stdlib/ndarray/matrix/float64' ); * var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); * var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); -* var ndarray = require( '@stdlib/ndarray/base/ctor' ); -* var Float64Array = require( '@stdlib/array/float64' ); +* var resolveEnum = require( '@stdlib/blas/base/matrix-triangle-resolve-enum' ); * var dsyr = require( '@stdlib/blas/base/ndarray/dsyr' ); * * var x = new Float64Vector( [ 1.0, 2.0, 3.0 ] ); -* var A = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0 ] ), [ 3, 3 ], [ 3, 1 ], 0, 'row-major' ); +* var A = new Float64Matrix( [ [ 1.0, 2.0, 3.0 ], [ 2.0, 1.0, 2.0 ], [ 3.0, 2.0, 1.0 ] ] ); * -* var alpha = scalar2ndarray( 2.0, { +* var uplo = scalar2ndarray( resolveEnum( 'upper' ), { +* 'dtype': 'int8' +* }); +* var alpha = scalar2ndarray( 1.0, { * 'dtype': 'float64' * }); * -* var out = dsyr( [ x, A, alpha ] ); -* // returns [ [ 3.0, 6.0, 9.0 ], [ 2.0, 9.0, 14.0 ], [ 3.0, 2.0, 19.0 ] ] +* var y = dsyr( [ x, A, uplo, alpha ] ); +* // returns [ [ 2.0, 4.0, 6.0 ], [ 2.0, 5.0, 8.0 ], [ 3.0, 2.0, 10.0 ] ] * -* var bool = ( out === A ); +* var bool = ( y === A ); * // returns true */ diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/lib/main.js b/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/lib/main.js index ba85e747d0fd..75da3afb7ac8 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/lib/main.js +++ b/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/lib/main.js @@ -20,54 +20,74 @@ // MODULES // -var numelDimension = require( '@stdlib/ndarray/base/numel-dimension' ); +var getShape = require( '@stdlib/ndarray/base/shape' ); +var getStrides = require( '@stdlib/ndarray/base/strides' ); 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 resolveStr = require( '@stdlib/blas/base/matrix-triangle-resolve-str' ); var strided = require( '@stdlib/blas/base/dsyr' ).ndarray; // MAIN // /** -* Performs the symmetric rank 1 operation `A = alpha*x*x^T + A`, where `alpha` is a scalar, `x` is an `N` element ndarray, and `A` is an `N` by `N` symmetric matrix. +* Performs the symmetric rank 1 operation `A = alpha*x*x^T + A`, where `alpha` is a scalar, `x` is a one-dimensional ndarray, and `A` is an `N` by `N` symmetric matrix. * * ## Notes * * - The function expects the following ndarrays: * -* - a one-dimensional input ndarray. -* - a two-dimensional input/output ndarray. -* - a zero-dimensional ndarray containing a scalar constant. +* - a one-dimensional input ndarray corresponding to `x`. +* - a two-dimensional input/output ndarray corresponding to `A`. +* - a zero-dimensional ndarray specifying whether the upper or lower triangular part of `A` should be referenced. +* - a zero-dimensional ndarray containing a scalar constant corresponding to `alpha`. * * @param {ArrayLikeObject} arrays - array-like object containing ndarrays * @returns {Object} output ndarray * * @example +* var Float64Matrix = require( '@stdlib/ndarray/matrix/float64' ); * var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); * var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); -* var ndarray = require( '@stdlib/ndarray/base/ctor' ); -* var Float64Array = require( '@stdlib/array/float64' ); +* var resolveEnum = require( '@stdlib/blas/base/matrix-triangle-resolve-enum' ); * * var x = new Float64Vector( [ 1.0, 2.0, 3.0 ] ); -* var A = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0 ] ), [ 3, 3 ], [ 3, 1 ], 0, 'row-major' ); +* var A = new Float64Matrix( [ [ 1.0, 2.0, 3.0 ], [ 2.0, 1.0, 2.0 ], [ 3.0, 2.0, 1.0 ] ] ); * -* var alpha = scalar2ndarray( 2.0, { +* var uplo = scalar2ndarray( resolveEnum( 'upper' ), { +* 'dtype': 'int8' +* }); +* var alpha = scalar2ndarray( 1.0, { * 'dtype': 'float64' * }); * -* var out = dsyr( [ x, A, alpha ] ); -* // returns [ [ 3.0, 6.0, 9.0 ], [ 2.0, 9.0, 14.0 ], [ 3.0, 2.0, 19.0 ] ] +* var y = dsyr( [ x, A, uplo, alpha ] ); +* // returns [ [ 2.0, 4.0, 6.0 ], [ 2.0, 5.0, 8.0 ], [ 3.0, 2.0, 10.0 ] ] * -* var bool = ( out === A ); +* var bool = ( y === A ); * // returns true */ function dsyr( arrays ) { - var alpha = ndarraylike2scalar( arrays[ 2 ] ); - var x = arrays[ 0 ]; - var A = arrays[ 1 ]; - strided( 'upper', numelDimension( A, 0 ), alpha, getData( x ), getStride( x, 0 ), getOffset( x ), getData( A ), getStride( A, 0 ), getStride( A, 1 ), getOffset( A ) ); + var alpha; + var uplo; + var sh; + var st; + var x; + var A; + + x = arrays[ 0 ]; + A = arrays[ 1 ]; + + uplo = resolveStr( ndarraylike2scalar( arrays[ 2 ] ) ); + alpha = ndarraylike2scalar( arrays[ 3 ] ); + + sh = getShape( A, false ); + st = getStrides( A, false ); + + strided( uplo, sh[ 0 ], alpha, getData( x ), getStride( x, 0 ), getOffset( x ), getData( A ), st[ 0 ], st[ 1 ], getOffset( A ) ); + return A; } diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/test/test.js b/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/test/test.js index d77389c468d1..7c2a088ce89f 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/test/test.js +++ b/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/test/test.js @@ -24,6 +24,7 @@ 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 resolveEnum = require( '@stdlib/blas/base/matrix-triangle-resolve-enum' ); var ndarray = require( '@stdlib/ndarray/base/ctor' ); var getData = require( '@stdlib/ndarray/data-buffer' ); var dsyr = require( './../lib' ); @@ -74,11 +75,12 @@ tape( 'the function has an arity of 1', function test( t ) { t.end(); }); -tape( 'the function performs the symmetric rank 1 operation `A = alpha*x*x^T + A`', function test( t ) { +tape( 'the function performs the symmetric rank 1 operation `A = alpha*x*x^T + A` (upper)', function test( t ) { var expected; var alpha; var xbuf; var Abuf; + var uplo; var x; var A; var v; @@ -87,13 +89,17 @@ tape( 'the function performs the symmetric rank 1 operation `A = alpha*x*x^T + A Abuf = new Float64Array( [ 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0 ] ); x = vector( xbuf, 3, 1, 0 ); A = matrix( Abuf, 3, 3, 1, 0 ); - alpha = scalar2ndarray( 2.0, { + alpha = scalar2ndarray( 1.0, { 'dtype': 'float64' }); - v = dsyr( [ x, A, alpha ] ); + uplo = scalar2ndarray( resolveEnum( 'upper' ), { + 'dtype': 'int8' + }); + + v = dsyr( [ x, A, uplo, alpha ] ); - expected = new Float64Array( [ 3.0, 6.0, 9.0, 2.0, 9.0, 14.0, 3.0, 2.0, 19.0 ] ); + expected = new Float64Array( [ 2.0, 4.0, 6.0, 2.0, 5.0, 8.0, 3.0, 2.0, 10.0 ] ); t.strictEqual( v, A, 'returns expected value' ); t.strictEqual( isSameFloat64Array( getData( v ), expected ), true, 'returns expected value' ); @@ -101,13 +107,48 @@ tape( 'the function performs the symmetric rank 1 operation `A = alpha*x*x^T + A Abuf = new Float64Array( [ 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0 ] ); x = vector( xbuf, 3, 1, 0 ); A = matrix( Abuf, 3, 1, 3, 0 ); - alpha = scalar2ndarray( 2.0, { + alpha = scalar2ndarray( 1.0, { 'dtype': 'float64' }); - v = dsyr( [ x, A, alpha ] ); + uplo = scalar2ndarray( resolveEnum( 'upper' ), { + 'dtype': 'int8' + }); + + v = dsyr( [ x, A, uplo, alpha ] ); + + expected = new Float64Array( [ 2.0, 2.0, 3.0, 3.0, 2.0, 2.0, 4.0, 3.0, 2.0 ] ); + t.strictEqual( v, A, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( v ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs the symmetric rank 1 operation `A = alpha*x*x^T + A` (lower)', function test( t ) { + var expected; + var alpha; + var xbuf; + var Abuf; + var uplo; + var x; + var A; + var v; + + xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + Abuf = new Float64Array( [ 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0 ] ); + x = vector( xbuf, 3, 1, 0 ); + A = matrix( Abuf, 3, 3, 1, 0 ); + alpha = scalar2ndarray( 1.0, { + 'dtype': 'float64' + }); + + uplo = scalar2ndarray( resolveEnum( 'lower' ), { + 'dtype': 'int8' + }); + + v = dsyr( [ x, A, uplo, alpha ] ); - expected = new Float64Array( [ 3.0, 2.0, 3.0, 4.0, 3.0, 2.0, 5.0, 4.0, 3.0 ] ); + expected = new Float64Array( [ 2.0, 2.0, 3.0, 4.0, 5.0, 2.0, 6.0, 8.0, 10.0 ] ); t.strictEqual( v, A, 'returns expected value' ); t.strictEqual( isSameFloat64Array( getData( v ), expected ), true, 'returns expected value' ); @@ -119,6 +160,7 @@ tape( 'if `alpha` is `0`, the function returns `A` unchanged', function test( t var alpha; var xbuf; var Abuf; + var uplo; var x; var A; var v; @@ -131,7 +173,11 @@ tape( 'if `alpha` is `0`, the function returns `A` unchanged', function test( t 'dtype': 'float64' }); - v = dsyr( [ x, A, alpha ] ); + uplo = scalar2ndarray( resolveEnum( 'upper' ), { + 'dtype': 'int8' + }); + + v = dsyr( [ x, A, uplo, alpha ] ); expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); t.strictEqual( v, A, 'returns expected value' ); @@ -145,6 +191,7 @@ tape( 'the function supports ndarrays having non-unit strides', function test( t var alpha; var xbuf; var Abuf; + var uplo; var x; var A; var v; @@ -160,13 +207,17 @@ tape( 'the function supports ndarrays having non-unit strides', function test( t Abuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); A = matrix( Abuf, 3, 3, 1, 0 ); - alpha = scalar2ndarray( 2.0, { + alpha = scalar2ndarray( 1.0, { 'dtype': 'float64' }); - v = dsyr( [ x, A, alpha ] ); + uplo = scalar2ndarray( resolveEnum( 'upper' ), { + 'dtype': 'int8' + }); + + v = dsyr( [ x, A, uplo, alpha ] ); - expected = new Float64Array( [ 2.0, 4.0, 6.0, 0.0, 8.0, 12.0, 0.0, 0.0, 18.0 ] ); + expected = new Float64Array( [ 1.0, 2.0, 3.0, 0.0, 4.0, 6.0, 0.0, 0.0, 9.0 ] ); t.strictEqual( v, A, 'returns expected value' ); t.strictEqual( isSameFloat64Array( getData( v ), expected ), true, 'returns expected value' ); t.end(); @@ -177,6 +228,7 @@ tape( 'the function supports ndarrays having negative strides', function test( t var alpha; var xbuf; var Abuf; + var uplo; var x; var A; var v; @@ -190,13 +242,17 @@ tape( 'the function supports ndarrays having negative strides', function test( t Abuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); A = matrix( Abuf, 3, 3, 1, 0 ); - alpha = scalar2ndarray( 2.0, { + alpha = scalar2ndarray( 1.0, { 'dtype': 'float64' }); - v = dsyr( [ x, A, alpha ] ); + uplo = scalar2ndarray( resolveEnum( 'upper' ), { + 'dtype': 'int8' + }); - expected = new Float64Array( [ 2.0, 4.0, 6.0, 0.0, 8.0, 12.0, 0.0, 0.0, 18.0 ] ); + v = dsyr( [ x, A, uplo, alpha ] ); + + expected = new Float64Array( [ 1.0, 2.0, 3.0, 0.0, 4.0, 6.0, 0.0, 0.0, 9.0 ] ); t.strictEqual( v, A, 'returns expected value' ); t.strictEqual( isSameFloat64Array( getData( v ), expected ), true, 'returns expected value' ); t.end(); @@ -207,6 +263,7 @@ tape( 'the function supports ndarrays having non-zero offsets', function test( t var alpha; var xbuf; var Abuf; + var uplo; var x; var A; var v; @@ -222,37 +279,41 @@ tape( 'the function supports ndarrays having non-zero offsets', function test( t x = vector( xbuf, 3, 2, 1 ); Abuf = new Float64Array([ - 999.0, - 999.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0 + 1.0, + 2.0, + 3.0, + 4.0, + 5.0, + 6.0, + 7.0, + 8.0, + 9.0, + 10.0, + 11.0 ]); A = matrix( Abuf, 3, 3, 1, 2 ); alpha = scalar2ndarray( 2.0, { 'dtype': 'float64' }); - v = dsyr( [ x, A, alpha ] ); + uplo = scalar2ndarray( resolveEnum( 'upper' ), { + 'dtype': 'int8' + }); + + v = dsyr( [ x, A, uplo, alpha ] ); expected = new Float64Array([ - 999.0, - 999.0, + 1.0, 2.0, - 4.0, - 6.0, - 0.0, + 5.0, 8.0, - 12.0, - 0.0, - 0.0, - 18.0 + 11.0, + 6.0, + 15.0, + 20.0, + 9.0, + 10.0, + 29.0 ]); t.strictEqual( v, A, 'returns expected value' ); t.strictEqual( isSameFloat64Array( getData( v ), expected ), true, 'returns expected value' ); From 5bd3ef4042419dd050da07a578f82a47bdad129e Mon Sep 17 00:00:00 2001 From: Kaustubh Patange Date: Fri, 10 Jul 2026 11:20:13 +0530 Subject: [PATCH 3/4] Update lib/node_modules/@stdlib/blas/base/ndarray/dsyr/lib/main.js Signed-off-by: Kaustubh Patange --- lib/node_modules/@stdlib/blas/base/ndarray/dsyr/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/lib/main.js b/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/lib/main.js index 75da3afb7ac8..9f4d7145abbc 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/lib/main.js +++ b/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/lib/main.js @@ -80,7 +80,7 @@ function dsyr( arrays ) { x = arrays[ 0 ]; A = arrays[ 1 ]; - uplo = resolveStr( ndarraylike2scalar( arrays[ 2 ] ) ); + uplo = ndarraylike2scalar( arrays[ 2 ] ); alpha = ndarraylike2scalar( arrays[ 3 ] ); sh = getShape( A, false ); From 770def1490ef266d2fdf87228859e3eabe693c7f Mon Sep 17 00:00:00 2001 From: Kaustubh Patange Date: Fri, 10 Jul 2026 11:38:14 +0530 Subject: [PATCH 4/4] Apply suggestion from @MeKaustubh07 Signed-off-by: Kaustubh Patange --- lib/node_modules/@stdlib/blas/base/ndarray/dsyr/lib/main.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/lib/main.js b/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/lib/main.js index 9f4d7145abbc..126c4b634a83 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/lib/main.js +++ b/lib/node_modules/@stdlib/blas/base/ndarray/dsyr/lib/main.js @@ -26,7 +26,6 @@ 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 resolveStr = require( '@stdlib/blas/base/matrix-triangle-resolve-str' ); var strided = require( '@stdlib/blas/base/dsyr' ).ndarray;