From 09198a5311398362b61bfa13d0c9603d0e7f747a Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Fri, 19 Dec 2025 17:51:39 +0530 Subject: [PATCH 1/7] feat: add cfill ndarray implementation - Add cfill function for complex64 ndarrays - Update documentation to use ndarray instance notation - Fix variable ordering lint issue --- .../blas/ext/base/ndarray/cfill/README.md | 78 +++++++++ .../base/ndarray/cfill/benchmark/benchmark.js | 57 +++++++ .../blas/ext/base/ndarray/cfill/docs/repl.txt | 31 ++++ .../base/ndarray/cfill/docs/types/index.d.ts | 51 ++++++ .../ext/base/ndarray/cfill/docs/types/test.ts | 76 +++++++++ .../ext/base/ndarray/cfill/examples/index.js | 45 +++++ .../blas/ext/base/ndarray/cfill/lib/index.js | 48 ++++++ .../blas/ext/base/ndarray/cfill/lib/main.js | 81 +++++++++ .../blas/ext/base/ndarray/cfill/package.json | 72 ++++++++ .../blas/ext/base/ndarray/cfill/test/test.js | 156 ++++++++++++++++++ 10 files changed, 695 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/test/test.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/README.md new file mode 100644 index 000000000000..129eec3d7a32 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/README.md @@ -0,0 +1,78 @@ + + +# cfill + +> Fill a complex single-precision floating-point ndarray with a specified scalar constant. + +## Usage + +```javascript +var cfill = require( '@stdlib/blas/ext/base/ndarray/cfill' ); +``` + +#### cfill( x, alpha ) + +Fills a complex single-precision floating-point ndarray `x` with a specified scalar constant `alpha`. + +```javascript +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); + +var buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +var x = new ndarray( 'complex64', buffer, [ 2 ], [ 1 ], 0, 'row-major' ); + +var alpha = new Complex64( 10.0, 10.0 ); + +var out = cfill( x, alpha ); +// returns [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] +``` + +## Examples + +```javascript +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var realf = require( '@stdlib/complex/float32/real' ); +var imagf = require( '@stdlib/complex/float32/imag' ); +var cfill = require( '@stdlib/blas/ext/base/ndarray/cfill' ); + +var buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var x = new ndarray( 'complex64', buffer, [ 3 ], [ 1 ], 0, 'row-major' ); + +var alpha = new Complex64( 10.0, 10.0 ); + +cfill( x, alpha ); + +var v = x.get( 0 ); +console.log( 'x[0] = %d + %di', realf( v ), imagf( v ) ); +// => 'x[0] = 10 + 10i' + +v = x.get( 1 ); +console.log( 'x[1] = %d + %di', realf( v ), imagf( v ) ); +// => 'x[1] = 10 + 10i' + +v = x.get( 2 ); +console.log( 'x[2] = %d + %di', realf( v ), imagf( v ) ); +// => 'x[2] = 10 + 10i' +``` + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/benchmark/benchmark.js new file mode 100644 index 000000000000..317bb5e6c942 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/benchmark/benchmark.js @@ -0,0 +1,57 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var isComplex64 = require( '@stdlib/assert/is-complex64' ); +var pkg = require( './../package.json' ).name; +var cfill = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var alpha; + var buf; + var x; + var i; + + buf = new Complex64Array( 100 ); + x = new ndarray( 'complex64', buf, [ 100 ], [ 1 ], 0, 'row-major' ); + alpha = new Complex64( 5.0, 5.0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + cfill( x, alpha ); + if ( !isComplex64( x.get( 0 ) ) ) { + b.fail( 'should return a Complex64' ); + } + } + b.toc(); + if ( !isComplex64( x.get( 0 ) ) ) { + b.fail( 'should return a Complex64' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/repl.txt new file mode 100644 index 000000000000..7f9e749c3d69 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/repl.txt @@ -0,0 +1,31 @@ + +{{alias}}( x, alpha ) + Fills a complex single-precision floating-point ndarray with a specified + scalar constant. + + Parameters + ---------- + x: ndarray + Input ndarray. + + alpha: ComplexLike + Scalar constant. + + Returns + ------- + out: ndarray + Input ndarray. + + Examples + -------- + > var buf = new {{alias:@stdlib/array/complex64}}( [ 1.0, 2.0, 3.0, 4.0 ] ) + + > var x = {{alias:@stdlib/ndarray/ctor}}( 'complex64', buf, [ 2 ], [ 1 ], 0, 'row-major' ) + + > var alpha = new {{alias:@stdlib/complex/float32/ctor}}( 10.0, 10.0 ); + > {{alias}}( x, alpha ) + [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/types/index.d.ts new file mode 100644 index 000000000000..ffd54ff9f533 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/types/index.d.ts @@ -0,0 +1,51 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 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 { complex64ndarray } from '@stdlib/types/ndarray'; +import { Complex64 } from '@stdlib/types/complex'; + +/** +* Fills a complex single-precision floating-point ndarray with a specified scalar constant. +* +* @param x - input ndarray +* @param alpha - scalar constant +* @returns input ndarray +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* var buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var x = new ndarray( 'complex64', buffer, [ 2 ], [ 1 ], 0, 'row-major' ); +* +* var alpha = new Complex64( 10.0, 10.0 ); +* +* var out = cfill( x, alpha ); +* // returns [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] +*/ +declare function cfill( x: complex64ndarray, alpha: Complex64 ): complex64ndarray; + + +// EXPORTS // + +export = cfill; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/types/test.ts new file mode 100644 index 000000000000..7f0eec8966ab --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/types/test.ts @@ -0,0 +1,76 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +import Complex64Array = require( '@stdlib/array/complex64' ); +import Complex64 = require( '@stdlib/complex/float32/ctor' ); +import ndarray = require( '@stdlib/ndarray/ctor' ); +import cfill = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + const x = new ndarray( 'complex64', buffer, [ 2 ], [ 1 ], 0, 'row-major' ); + const alpha = new Complex64( 10.0, 10.0 ); + + cfill( x, alpha ); // $ExpectType complex64ndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + const alpha = new Complex64( 10.0, 10.0 ); + + cfill( '10', alpha ); // $ExpectError + cfill( 10, alpha ); // $ExpectError + cfill( true, alpha ); // $ExpectError + cfill( false, alpha ); // $ExpectError + cfill( null, alpha ); // $ExpectError + cfill( undefined, alpha ); // $ExpectError + cfill( [], alpha ); // $ExpectError + cfill( {}, alpha ); // $ExpectError + cfill( ( x: number ): number => x, alpha ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a complex number... +{ + const buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + const x = new ndarray( 'complex64', buffer, [ 2 ], [ 1 ], 0, 'row-major' ); + + cfill( x, '10' ); // $ExpectError + cfill( x, 10 ); // $ExpectError + cfill( x, true ); // $ExpectError + cfill( x, false ); // $ExpectError + cfill( x, null ); // $ExpectError + cfill( x, undefined ); // $ExpectError + cfill( x, [] ); // $ExpectError + cfill( x, {} ); // $ExpectError + cfill( x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + const x = new ndarray( 'complex64', buffer, [ 2 ], [ 1 ], 0, 'row-major' ); + const alpha = new Complex64( 10.0, 10.0 ); + + cfill(); // $ExpectError + cfill( x ); // $ExpectError + cfill( x, alpha, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/examples/index.js new file mode 100644 index 000000000000..754541fb2f17 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/examples/index.js @@ -0,0 +1,45 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var realf = require( '@stdlib/complex/float32/real' ); +var imagf = require( '@stdlib/complex/float32/imag' ); +var cfill = require( './../lib' ); + +var buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var x = new ndarray( 'complex64', buffer, [ 3 ], [ 1 ], 0, 'row-major' ); + +var alpha = new Complex64( 10.0, 10.0 ); + +cfill( x, alpha ); + +var v = x.get( 0 ); +console.log( 'x[0] = %d + %di', realf( v ), imagf( v ) ); +// => 'x[0] = 10 + 10i' + +v = x.get( 1 ); +console.log( 'x[1] = %d + %di', realf( v ), imagf( v ) ); +// => 'x[1] = 10 + 10i' + +v = x.get( 2 ); +console.log( 'x[2] = %d + %di', realf( v ), imagf( v ) ); +// => 'x[2] = 10 + 10i' diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/lib/index.js new file mode 100644 index 000000000000..3e8fa7c12ea6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/lib/index.js @@ -0,0 +1,48 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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'; + +/** +* Fill a complex single-precision floating-point ndarray with a specified scalar constant. +* +* @module @stdlib/blas/ext/base/ndarray/cfill +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var cfill = require( '@stdlib/blas/ext/base/ndarray/cfill' ); +* +* var buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var x = new ndarray( 'complex64', buffer, [ 2 ], [ 1 ], 0, 'row-major' ); +* +* var alpha = new Complex64( 10.0, 10.0 ); +* +* var out = cfill( x, alpha ); +* // returns [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/lib/main.js new file mode 100644 index 000000000000..38963273797a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/lib/main.js @@ -0,0 +1,81 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 strided = require( '@stdlib/blas/ext/base/cfill' ).ndarray; +var getStride = require( '@stdlib/ndarray/base/stride' ); +var getOffset = require( '@stdlib/ndarray/base/offset' ); +var getData = require( '@stdlib/ndarray/base/data-buffer' ); + + +// MAIN // + +/** +* Fills a complex single-precision floating-point ndarray with a specified scalar constant. +* +* @param {complex64ndarray} x - input ndarray +* @param {ComplexLike} alpha - scalar constant +* @returns {complex64ndarray} input ndarray +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* var buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var x = new ndarray( 'complex64', buffer, [ 2 ], [ 1 ], 0, 'row-major' ); +* +* var alpha = new Complex64( 10.0, 10.0 ); +* +* cfill( x, alpha ); +* +* var v = x.get( 0 ); +* // returns +* +* var re = v.re; +* // returns 10.0 +* +* var im = v.im; +* // returns 10.0 +*/ +function cfill( x, alpha ) { + var buf; + var sx; + var ox; + var N; + + N = numelDimension( x, 0 ); + if ( N <= 0 ) { + return x; + } + buf = getData( x ); + sx = getStride( x, 0 ); + ox = getOffset( x ); + + strided( N, alpha, buf, sx, ox ); + return x; +} + + +// EXPORTS // + +module.exports = cfill; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/package.json b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/package.json new file mode 100644 index 000000000000..cf1bdcb5c8da --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/package.json @@ -0,0 +1,72 @@ +{ + "name": "@stdlib/blas/ext/base/ndarray/cfill", + "version": "0.0.0", + "description": "Fill a complex single-precision floating-point ndarray with a specified scalar constant.", + "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", + "stdtypes", + "types", + "data", + "structure", + "ndarray", + "blas", + "extend", + "extended", + "extension", + "base", + "fill", + "array", + "typed", + "complex", + "complex64", + "float", + "float32", + "single" + ] +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/test/test.js new file mode 100644 index 000000000000..caa81174919c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/test/test.js @@ -0,0 +1,156 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 Complex64Array = require( '@stdlib/array/complex64' ); +var Float32Array = require( '@stdlib/array/float32' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var realf = require( '@stdlib/complex/float32/real' ); +var imagf = require( '@stdlib/complex/float32/imag' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var cfill = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cfill, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function fills an ndarray with a specified scalar constant', function test( t ) { + var alpha; + var raw; + var buf; + var x; + var v; + + raw = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + buf = new Complex64Array( raw ); + x = new ndarray( 'complex64', buf, [ 2 ], [ 1 ], 0, 'row-major' ); + + alpha = new Complex64( 5.0, -3.0 ); + + cfill( x, alpha ); + + v = x.get( 0 ); + t.strictEqual( realf( v ), 5.0, 'returns expected real component for element 0' ); + t.strictEqual( imagf( v ), -3.0, 'returns expected imaginary component for element 0' ); + + v = x.get( 1 ); + t.strictEqual( realf( v ), 5.0, 'returns expected real component for element 1' ); + t.strictEqual( imagf( v ), -3.0, 'returns expected imaginary component for element 1' ); + + t.end(); +}); + +tape( 'the function returns the input ndarray', function test( t ) { + var alpha; + var raw; + var buf; + var out; + var x; + + raw = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + buf = new Complex64Array( raw ); + x = new ndarray( 'complex64', buf, [ 2 ], [ 1 ], 0, 'row-major' ); + + alpha = new Complex64( 10.0, 10.0 ); + + out = cfill( x, alpha ); + + t.strictEqual( out, x, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports negative strides', function test( t ) { + var alpha; + var raw; + var buf; + var x; + var v; + + raw = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + buf = new Complex64Array( raw ); + x = new ndarray( 'complex64', buf, [ 2 ], [ -1 ], 1, 'row-major' ); + + alpha = new Complex64( 7.0, 8.0 ); + + cfill( x, alpha ); + + v = x.get( 0 ); + t.strictEqual( realf( v ), 7.0, 'returns expected real component for element 0' ); + t.strictEqual( imagf( v ), 8.0, 'returns expected imaginary component for element 0' ); + + v = x.get( 1 ); + t.strictEqual( realf( v ), 7.0, 'returns expected real component for element 1' ); + t.strictEqual( imagf( v ), 8.0, 'returns expected imaginary component for element 1' ); + + t.end(); +}); + +tape( 'the function supports an offset', function test( t ) { + var alpha; + var raw; + var buf; + var x; + var v; + + raw = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + buf = new Complex64Array( raw ); + x = new ndarray( 'complex64', buf, [ 2 ], [ 1 ], 1, 'row-major' ); + + alpha = new Complex64( 9.0, -2.0 ); + + cfill( x, alpha ); + + v = buf.get( 0 ); + t.strictEqual( realf( v ), 1.0, 'element 0 unchanged (real)' ); + t.strictEqual( imagf( v ), 2.0, 'element 0 unchanged (imag)' ); + + v = x.get( 0 ); + t.strictEqual( realf( v ), 9.0, 'returns expected real component for element at offset' ); + t.strictEqual( imagf( v ), -2.0, 'returns expected imaginary component for element at offset' ); + + t.end(); +}); + +tape( 'the function handles zero-length dimensions', function test( t ) { + var alpha; + var raw; + var buf; + var x; + + raw = new Float32Array( [ 1.0, 2.0 ] ); + buf = new Complex64Array( raw ); + x = new ndarray( 'complex64', buf, [ 0 ], [ 1 ], 0, 'row-major' ); + + alpha = new Complex64( 5.0, 5.0 ); + + cfill( x, alpha ); + + t.strictEqual( realf( buf.get( 0 ) ), 1.0, 'buffer unchanged' ); + t.strictEqual( imagf( buf.get( 0 ) ), 2.0, 'buffer unchanged' ); + + t.end(); +}); From d8204d07b5f59b705fb8c6b5a48f766f7f25caf7 Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Sun, 21 Dec 2025 18:08:52 +0530 Subject: [PATCH 2/7] fix: refactor cfill to arrays API --- .../blas/ext/base/ndarray/cfill/README.md | 27 ++++++-- .../base/ndarray/cfill/benchmark/benchmark.js | 7 +- .../blas/ext/base/ndarray/cfill/docs/repl.txt | 15 ++--- .../base/ndarray/cfill/docs/types/index.d.ts | 18 ++++-- .../ext/base/ndarray/cfill/docs/types/test.ts | 64 +++++++------------ .../ext/base/ndarray/cfill/examples/index.js | 7 +- .../blas/ext/base/ndarray/cfill/lib/index.js | 27 ++++---- .../blas/ext/base/ndarray/cfill/lib/main.js | 30 +++++---- .../blas/ext/base/ndarray/cfill/package.json | 2 +- .../blas/ext/base/ndarray/cfill/test/test.js | 31 ++++++--- 10 files changed, 126 insertions(+), 102 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/README.md index 129eec3d7a32..107447232cb7 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/README.md @@ -28,29 +28,41 @@ limitations under the License. var cfill = require( '@stdlib/blas/ext/base/ndarray/cfill' ); ``` -#### cfill( x, alpha ) +#### cfill( arrays ) Fills a complex single-precision floating-point ndarray `x` with a specified scalar constant `alpha`. ```javascript var Complex64Array = require( '@stdlib/array/complex64' ); var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); var ndarray = require( '@stdlib/ndarray/ctor' ); var buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); var x = new ndarray( 'complex64', buffer, [ 2 ], [ 1 ], 0, 'row-major' ); -var alpha = new Complex64( 10.0, 10.0 ); +var alpha = scalar2ndarray( new Complex64( 10.0, 10.0 ), { + 'dtype': 'complex64' +}); -var out = cfill( x, alpha ); -// returns [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] +var out = cfill( [ x, alpha ] ); +// returns + +var arr = ndarray2array( out ); +// returns [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] ``` +The function has the following parameters: + +- **arrays**: array-like object containing a single one-dimensional input ndarray and a zero-dimensional ndarray containing a scalar constant. + ## Examples ```javascript var Complex64Array = require( '@stdlib/array/complex64' ); var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); var ndarray = require( '@stdlib/ndarray/ctor' ); var realf = require( '@stdlib/complex/float32/real' ); var imagf = require( '@stdlib/complex/float32/imag' ); @@ -59,9 +71,11 @@ var cfill = require( '@stdlib/blas/ext/base/ndarray/cfill' ); var buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); var x = new ndarray( 'complex64', buffer, [ 3 ], [ 1 ], 0, 'row-major' ); -var alpha = new Complex64( 10.0, 10.0 ); +var alpha = scalar2ndarray( new Complex64( 10.0, 10.0 ), { + 'dtype': 'complex64' +}); -cfill( x, alpha ); +cfill( [ x, alpha ] ); var v = x.get( 0 ); console.log( 'x[0] = %d + %di', realf( v ), imagf( v ) ); @@ -75,4 +89,3 @@ v = x.get( 2 ); console.log( 'x[2] = %d + %di', realf( v ), imagf( v ) ); // => 'x[2] = 10 + 10i' ``` - diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/benchmark/benchmark.js index 317bb5e6c942..22865be0b2c3 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/benchmark/benchmark.js @@ -23,6 +23,7 @@ var bench = require( '@stdlib/bench' ); var Complex64Array = require( '@stdlib/array/complex64' ); var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); var ndarray = require( '@stdlib/ndarray/ctor' ); var isComplex64 = require( '@stdlib/assert/is-complex64' ); var pkg = require( './../package.json' ).name; @@ -39,11 +40,13 @@ bench( pkg, function benchmark( b ) { buf = new Complex64Array( 100 ); x = new ndarray( 'complex64', buf, [ 100 ], [ 1 ], 0, 'row-major' ); - alpha = new Complex64( 5.0, 5.0 ); + alpha = scalar2ndarray( new Complex64( 5.0, 5.0 ), { + 'dtype': 'complex64' + }); b.tic(); for ( i = 0; i < b.iterations; i++ ) { - cfill( x, alpha ); + cfill( [ x, alpha ] ); if ( !isComplex64( x.get( 0 ) ) ) { b.fail( 'should return a Complex64' ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/repl.txt index 7f9e749c3d69..a5672f603c1e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/repl.txt @@ -1,15 +1,13 @@ -{{alias}}( x, alpha ) +{{alias}}( arrays ) Fills a complex single-precision floating-point ndarray with a specified scalar constant. Parameters ---------- - x: ndarray - Input ndarray. - - alpha: ComplexLike - Scalar constant. + arrays: ArrayLikeObject + Array-like object containing a single one-dimensional input ndarray + and a zero-dimensional ndarray containing a scalar constant. Returns ------- @@ -22,10 +20,9 @@ > var x = {{alias:@stdlib/ndarray/ctor}}( 'complex64', buf, [ 2 ], [ 1 ], 0, 'row-major' ) - > var alpha = new {{alias:@stdlib/complex/float32/ctor}}( 10.0, 10.0 ); - > {{alias}}( x, alpha ) + > var alpha = {{alias:@stdlib/ndarray/from-scalar}}( new {{alias:@stdlib/complex/float32/ctor}}( 10.0, 10.0 ), { 'dtype': 'complex64' } ) + > {{alias}}( [ x, alpha ] ) [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] See Also -------- - diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/types/index.d.ts index ffd54ff9f533..e8eaa42aeeb4 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/types/index.d.ts @@ -26,24 +26,30 @@ import { Complex64 } from '@stdlib/types/complex'; /** * Fills a complex single-precision floating-point ndarray with a specified scalar constant. * -* @param x - input ndarray -* @param alpha - scalar constant +* @param arrays - array-like object containing a single one-dimensional input ndarray and a zero-dimensional ndarray containing a scalar constant * @returns input ndarray * * @example * var Complex64Array = require( '@stdlib/array/complex64' ); * var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); * var ndarray = require( '@stdlib/ndarray/ctor' ); * * var buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); * var x = new ndarray( 'complex64', buffer, [ 2 ], [ 1 ], 0, 'row-major' ); * -* var alpha = new Complex64( 10.0, 10.0 ); +* var alpha = scalar2ndarray( new Complex64( 10.0, 10.0 ), { +* 'dtype': 'complex64' +* }); * -* var out = cfill( x, alpha ); -* // returns [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] +* var out = cfill( [ x, alpha ] ); +* // returns +* +* var arr = ndarray2array( out ); +* // returns [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] */ -declare function cfill( x: complex64ndarray, alpha: Complex64 ): complex64ndarray; +declare function cfill( arrays: [ complex64ndarray, complex64ndarray ] ): complex64ndarray; // EXPORTS // diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/types/test.ts index 7f0eec8966ab..b6907fe73a9d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/types/test.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/types/test.ts @@ -16,9 +16,9 @@ * limitations under the License. */ -import Complex64Array = require( '@stdlib/array/complex64' ); +import zeros = require( '@stdlib/ndarray/base/zeros' ); +import scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); import Complex64 = require( '@stdlib/complex/float32/ctor' ); -import ndarray = require( '@stdlib/ndarray/ctor' ); import cfill = require( './index' ); @@ -26,51 +26,35 @@ import cfill = require( './index' ); // The function returns an ndarray... { - const buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - const x = new ndarray( 'complex64', buffer, [ 2 ], [ 1 ], 0, 'row-major' ); - const alpha = new Complex64( 10.0, 10.0 ); - - cfill( x, alpha ); // $ExpectType complex64ndarray + const x = zeros( 'complex64', [ 10 ], 'row-major' ); + const alpha = scalar2ndarray( new Complex64( 10.0, 10.0 ), { + 'dtype': 'complex64' + }); + cfill( [ x, alpha ] ); // $ExpectType complex64ndarray } -// The compiler throws an error if the function is provided a first argument which is not an ndarray... +// The compiler throws an error if the function is provided a first argument which is not an array-like object... { - const alpha = new Complex64( 10.0, 10.0 ); - - cfill( '10', alpha ); // $ExpectError - cfill( 10, alpha ); // $ExpectError - cfill( true, alpha ); // $ExpectError - cfill( false, alpha ); // $ExpectError - cfill( null, alpha ); // $ExpectError - cfill( undefined, alpha ); // $ExpectError - cfill( [], alpha ); // $ExpectError - cfill( {}, alpha ); // $ExpectError - cfill( ( x: number ): number => x, alpha ); // $ExpectError + cfill( 'abc' ); // $ExpectError + cfill( 5 ); // $ExpectError + cfill( true ); // $ExpectError + cfill( false ); // $ExpectError + cfill( null ); // $ExpectError + cfill( undefined ); // $ExpectError + cfill( {} ); // $ExpectError + cfill( ( x: number ): number => x ); // $ExpectError } -// The compiler throws an error if the function is provided a second argument which is not a complex number... +// The compiler throws an error if the function is provided an insufficient number of arguments... { - const buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - const x = new ndarray( 'complex64', buffer, [ 2 ], [ 1 ], 0, 'row-major' ); - - cfill( x, '10' ); // $ExpectError - cfill( x, 10 ); // $ExpectError - cfill( x, true ); // $ExpectError - cfill( x, false ); // $ExpectError - cfill( x, null ); // $ExpectError - cfill( x, undefined ); // $ExpectError - cfill( x, [] ); // $ExpectError - cfill( x, {} ); // $ExpectError - cfill( x, ( x: number ): number => x ); // $ExpectError + cfill(); // $ExpectError } -// The compiler throws an error if the function is provided an unsupported number of arguments... +// The compiler throws an error if the function is provided too many arguments... { - const buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - const x = new ndarray( 'complex64', buffer, [ 2 ], [ 1 ], 0, 'row-major' ); - const alpha = new Complex64( 10.0, 10.0 ); - - cfill(); // $ExpectError - cfill( x ); // $ExpectError - cfill( x, alpha, 10 ); // $ExpectError + const x = zeros( 'complex64', [ 10 ], 'row-major' ); + const alpha = scalar2ndarray( new Complex64( 10.0, 10.0 ), { + 'dtype': 'complex64' + }); + cfill( [ x, alpha ], 10 ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/examples/index.js index 754541fb2f17..1152b71b9165 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/examples/index.js @@ -20,6 +20,7 @@ var Complex64Array = require( '@stdlib/array/complex64' ); var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); var ndarray = require( '@stdlib/ndarray/ctor' ); var realf = require( '@stdlib/complex/float32/real' ); var imagf = require( '@stdlib/complex/float32/imag' ); @@ -28,9 +29,11 @@ var cfill = require( './../lib' ); var buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); var x = new ndarray( 'complex64', buffer, [ 3 ], [ 1 ], 0, 'row-major' ); -var alpha = new Complex64( 10.0, 10.0 ); +var alpha = scalar2ndarray( new Complex64( 10.0, 10.0 ), { + 'dtype': 'complex64' +}); -cfill( x, alpha ); +cfill( [ x, alpha ] ); var v = x.get( 0 ); console.log( 'x[0] = %d + %di', realf( v ), imagf( v ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/lib/index.js index 3e8fa7c12ea6..069558c559d3 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/lib/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/lib/index.js @@ -24,18 +24,21 @@ * @module @stdlib/blas/ext/base/ndarray/cfill * * @example -* var Complex64Array = require( '@stdlib/array/complex64' ); -* var Complex64 = require( '@stdlib/complex/float32/ctor' ); -* var ndarray = require( '@stdlib/ndarray/ctor' ); -* var cfill = require( '@stdlib/blas/ext/base/ndarray/cfill' ); -* -* var buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); -* var x = new ndarray( 'complex64', buffer, [ 2 ], [ 1 ], 0, 'row-major' ); -* -* var alpha = new Complex64( 10.0, 10.0 ); -* -* var out = cfill( x, alpha ); -* // returns [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] + * var Complex64Array = require( '@stdlib/array/complex64' ); + * var Complex64 = require( '@stdlib/complex/float32/ctor' ); + * var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); + * var ndarray = require( '@stdlib/ndarray/ctor' ); + * var cfill = require( '@stdlib/blas/ext/base/ndarray/cfill' ); + * + * var buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + * var x = new ndarray( 'complex64', buffer, [ 2 ], [ 1 ], 0, 'row-major' ); + * + * var alpha = scalar2ndarray( new Complex64( 10.0, 10.0 ), { + * 'dtype': 'complex64' + * }); + * + * var out = cfill( [ x, alpha ] ); + * // returns [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] */ // MODULES // diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/lib/main.js index 38963273797a..4b97021ce582 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/lib/main.js @@ -21,6 +21,7 @@ // MODULES // var numelDimension = require( '@stdlib/ndarray/base/numel-dimension' ); +var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); var strided = require( '@stdlib/blas/ext/base/cfill' ).ndarray; var getStride = require( '@stdlib/ndarray/base/stride' ); var getOffset = require( '@stdlib/ndarray/base/offset' ); @@ -32,37 +33,40 @@ var getData = require( '@stdlib/ndarray/base/data-buffer' ); /** * Fills a complex single-precision floating-point ndarray with a specified scalar constant. * -* @param {complex64ndarray} x - input ndarray -* @param {ComplexLike} alpha - scalar constant +* @param {ArrayLikeObject} arrays - array-like object containing a single one-dimensional input ndarray and a zero-dimensional ndarray containing a scalar constant * @returns {complex64ndarray} input ndarray * * @example * var Complex64Array = require( '@stdlib/array/complex64' ); * var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); * var ndarray = require( '@stdlib/ndarray/ctor' ); * * var buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); * var x = new ndarray( 'complex64', buffer, [ 2 ], [ 1 ], 0, 'row-major' ); * -* var alpha = new Complex64( 10.0, 10.0 ); +* var alpha = scalar2ndarray( new Complex64( 10.0, 10.0 ), { +* 'dtype': 'complex64' +* }); * -* cfill( x, alpha ); +* var out = cfill( [ x, alpha ] ); +* // returns * -* var v = x.get( 0 ); -* // returns -* -* var re = v.re; -* // returns 10.0 -* -* var im = v.im; -* // returns 10.0 +* var arr = ndarray2array( out ); +* // returns [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] */ -function cfill( x, alpha ) { +function cfill( arrays ) { + var alpha; var buf; var sx; var ox; + var x; var N; + x = arrays[ 0 ]; + alpha = ndarraylike2scalar( arrays[ 1 ] ); + N = numelDimension( x, 0 ); if ( N <= 0 ) { return x; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/package.json b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/package.json index cf1bdcb5c8da..5c36f2f3da78 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/package.json +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/blas/ext/base/ndarray/cfill", "version": "0.0.0", - "description": "Fill a complex single-precision floating-point ndarray with a specified scalar constant.", + "description": "Fill a one-dimensional complex single-precision floating-point ndarray with a specified scalar constant.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/test/test.js index caa81174919c..fe6b25a2f288 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/test/test.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/test/test.js @@ -24,6 +24,7 @@ var tape = require( 'tape' ); var Complex64Array = require( '@stdlib/array/complex64' ); var Float32Array = require( '@stdlib/array/float32' ); var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); var realf = require( '@stdlib/complex/float32/real' ); var imagf = require( '@stdlib/complex/float32/imag' ); var ndarray = require( '@stdlib/ndarray/ctor' ); @@ -49,9 +50,11 @@ tape( 'the function fills an ndarray with a specified scalar constant', function buf = new Complex64Array( raw ); x = new ndarray( 'complex64', buf, [ 2 ], [ 1 ], 0, 'row-major' ); - alpha = new Complex64( 5.0, -3.0 ); + alpha = scalar2ndarray( new Complex64( 5.0, -3.0 ), { + 'dtype': 'complex64' + }); - cfill( x, alpha ); + cfill( [ x, alpha ] ); v = x.get( 0 ); t.strictEqual( realf( v ), 5.0, 'returns expected real component for element 0' ); @@ -75,9 +78,11 @@ tape( 'the function returns the input ndarray', function test( t ) { buf = new Complex64Array( raw ); x = new ndarray( 'complex64', buf, [ 2 ], [ 1 ], 0, 'row-major' ); - alpha = new Complex64( 10.0, 10.0 ); + alpha = scalar2ndarray( new Complex64( 10.0, 10.0 ), { + 'dtype': 'complex64' + }); - out = cfill( x, alpha ); + out = cfill( [ x, alpha ] ); t.strictEqual( out, x, 'returns expected value' ); t.end(); @@ -94,9 +99,11 @@ tape( 'the function supports negative strides', function test( t ) { buf = new Complex64Array( raw ); x = new ndarray( 'complex64', buf, [ 2 ], [ -1 ], 1, 'row-major' ); - alpha = new Complex64( 7.0, 8.0 ); + alpha = scalar2ndarray( new Complex64( 7.0, 8.0 ), { + 'dtype': 'complex64' + }); - cfill( x, alpha ); + cfill( [ x, alpha ] ); v = x.get( 0 ); t.strictEqual( realf( v ), 7.0, 'returns expected real component for element 0' ); @@ -120,9 +127,11 @@ tape( 'the function supports an offset', function test( t ) { buf = new Complex64Array( raw ); x = new ndarray( 'complex64', buf, [ 2 ], [ 1 ], 1, 'row-major' ); - alpha = new Complex64( 9.0, -2.0 ); + alpha = scalar2ndarray( new Complex64( 9.0, -2.0 ), { + 'dtype': 'complex64' + }); - cfill( x, alpha ); + cfill( [ x, alpha ] ); v = buf.get( 0 ); t.strictEqual( realf( v ), 1.0, 'element 0 unchanged (real)' ); @@ -145,9 +154,11 @@ tape( 'the function handles zero-length dimensions', function test( t ) { buf = new Complex64Array( raw ); x = new ndarray( 'complex64', buf, [ 0 ], [ 1 ], 0, 'row-major' ); - alpha = new Complex64( 5.0, 5.0 ); + alpha = scalar2ndarray( new Complex64( 5.0, 5.0 ), { + 'dtype': 'complex64' + }); - cfill( x, alpha ); + cfill( [ x, alpha ] ); t.strictEqual( realf( buf.get( 0 ) ), 1.0, 'buffer unchanged' ); t.strictEqual( imagf( buf.get( 0 ) ), 2.0, 'buffer unchanged' ); From d17a55a1b9d38088484a718858f79fb61330c788 Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Sun, 21 Dec 2025 18:14:12 +0530 Subject: [PATCH 3/7] fix: cfill CI errors --- .../blas/ext/base/ndarray/cfill/README.md | 20 +++++++++++++++++++ .../blas/ext/base/ndarray/cfill/docs/repl.txt | 10 +++++----- .../base/ndarray/cfill/docs/types/index.d.ts | 1 - 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/README.md index 107447232cb7..d3662a29fb94 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/README.md @@ -89,3 +89,23 @@ v = x.get( 2 ); console.log( 'x[2] = %d + %di', realf( v ), imagf( v ) ); // => 'x[2] = 10 + 10i' ``` + + + + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/repl.txt index a5672f603c1e..df7c923a41a9 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/repl.txt @@ -16,11 +16,11 @@ Examples -------- - > var buf = new {{alias:@stdlib/array/complex64}}( [ 1.0, 2.0, 3.0, 4.0 ] ) - - > var x = {{alias:@stdlib/ndarray/ctor}}( 'complex64', buf, [ 2 ], [ 1 ], 0, 'row-major' ) - - > var alpha = {{alias:@stdlib/ndarray/from-scalar}}( new {{alias:@stdlib/complex/float32/ctor}}( 10.0, 10.0 ), { 'dtype': 'complex64' } ) + > var buf = new {{alias:@stdlib/array/complex64}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > var x = {{alias:@stdlib/ndarray/ctor}}( 'complex64', buf, [ 2 ], [ 1 ], 0, 'row-major' ); + > var C64 = {{alias:@stdlib/complex/float32/ctor}}; + > var s2n = {{alias:@stdlib/ndarray/from-scalar}}; + > var alpha = s2n( new C64( 10.0, 10.0 ), { 'dtype': 'complex64' } ); > {{alias}}( [ x, alpha ] ) [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/types/index.d.ts index e8eaa42aeeb4..e9b135a0fd3a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/types/index.d.ts @@ -21,7 +21,6 @@ /// import { complex64ndarray } from '@stdlib/types/ndarray'; -import { Complex64 } from '@stdlib/types/complex'; /** * Fills a complex single-precision floating-point ndarray with a specified scalar constant. From 9b3a78441526ea0abf960ca23e29c8c953e7f6d5 Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Sun, 21 Dec 2025 18:17:39 +0530 Subject: [PATCH 4/7] fix: refactor cfill to arrays API --- .../@stdlib/blas/ext/base/ndarray/cfill/README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/README.md index d3662a29fb94..a250fb6e784b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/README.md @@ -28,6 +28,14 @@ limitations under the License. var cfill = require( '@stdlib/blas/ext/base/ndarray/cfill' ); ``` +
+ +## Usage + +```javascript +var cfill = require( '@stdlib/blas/ext/base/ndarray/cfill' ); +``` + #### cfill( arrays ) Fills a complex single-precision floating-point ndarray `x` with a specified scalar constant `alpha`. @@ -57,6 +65,12 @@ The function has the following parameters: - **arrays**: array-like object containing a single one-dimensional input ndarray and a zero-dimensional ndarray containing a scalar constant. +
+ + + +
+ ## Examples ```javascript From 30cc55ecbd0ee334a0bdd7c49753fed3c73b3c09 Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Sun, 21 Dec 2025 18:22:48 +0530 Subject: [PATCH 5/7] fix: cfill - remove duplicate Usage heading --- .../@stdlib/blas/ext/base/ndarray/cfill/README.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/README.md index a250fb6e784b..b99b9e263381 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/README.md @@ -22,12 +22,6 @@ limitations under the License. > Fill a complex single-precision floating-point ndarray with a specified scalar constant. -## Usage - -```javascript -var cfill = require( '@stdlib/blas/ext/base/ndarray/cfill' ); -``` -
## Usage From c60d2b8b59cffefa4ebaee4e4c12d3872a4073d1 Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Sun, 21 Dec 2025 18:54:29 +0530 Subject: [PATCH 6/7] Updation for the benchmark --- .../base/ndarray/cfill/benchmark/benchmark.js | 89 +++++++++++++++---- 1 file changed, 70 insertions(+), 19 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/benchmark/benchmark.js index 22865be0b2c3..5aff10842c07 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/benchmark/benchmark.js @@ -21,40 +21,91 @@ // MODULES // var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var pow = require( '@stdlib/math/base/special/pow' ); var Complex64Array = require( '@stdlib/array/complex64' ); var Complex64 = require( '@stdlib/complex/float32/ctor' ); var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); var ndarray = require( '@stdlib/ndarray/ctor' ); -var isComplex64 = require( '@stdlib/assert/is-complex64' ); var pkg = require( './../package.json' ).name; var cfill = require( './../lib' ); -// MAIN // +// VARIABLES // + +var options = { + 'dtype': 'complex64' +}; + -bench( pkg, function benchmark( b ) { +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { var alpha; + var xbuf; var buf; var x; - var i; - buf = new Complex64Array( 100 ); - x = new ndarray( 'complex64', buf, [ 100 ], [ 1 ], 0, 'row-major' ); - alpha = scalar2ndarray( new Complex64( 5.0, 5.0 ), { - 'dtype': 'complex64' + buf = uniform( len*2, 0.0, 100.0, { + 'dtype': 'float32' }); + xbuf = new Complex64Array( buf.buffer ); + x = new ndarray( options.dtype, xbuf, [ len ], [ 1 ], 0, 'row-major' ); + + alpha = scalar2ndarray( new Complex64( 5.0, 5.0 ), options ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cfill( [ x, alpha ] ); - if ( !isComplex64( x.get( 0 ) ) ) { - b.fail( 'should return a Complex64' ); + return benchmark; + + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = cfill( [ x, alpha ] ); + if ( out !== out ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( out !== out ) { + b.fail( 'should not return NaN' ); } + b.pass( 'benchmark finished' ); + b.end(); } - b.toc(); - if ( !isComplex64( x.get( 0 ) ) ) { - b.fail( 'should return a Complex64' ); +} + + +// 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( pkg+':len='+len, f ); } - b.pass( 'benchmark finished' ); - b.end(); -}); +} + +main(); From 678e108ab57c8a9105119e14847fe5da75f570eb Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Mon, 22 Dec 2025 07:52:34 +0530 Subject: [PATCH 7/7] fix: cfill benchmark - use @stdlib/string/format per RFC #8647 --- .../@stdlib/blas/ext/base/ndarray/cfill/benchmark/benchmark.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/benchmark/benchmark.js index 5aff10842c07..0d8b6ab57a87 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/benchmark/benchmark.js @@ -26,6 +26,7 @@ var pow = require( '@stdlib/math/base/special/pow' ); var Complex64Array = require( '@stdlib/array/complex64' ); var Complex64 = require( '@stdlib/complex/float32/ctor' ); var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var format = require( '@stdlib/string/format' ); var ndarray = require( '@stdlib/ndarray/ctor' ); var pkg = require( './../package.json' ).name; var cfill = require( './../lib' ); @@ -104,7 +105,7 @@ function main() { for ( i = min; i <= max; i++ ) { len = pow( 10, i ); f = createBenchmark( len ); - bench( pkg+':len='+len, f ); + bench( format( '%s:len=%d', pkg, len ), f ); } }