From 143189d2e2a1d5bc3e0ad9f117eff6399b135602 Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Wed, 17 Dec 2025 23:12:30 +0530 Subject: [PATCH 1/2] feat: add blas/ext/base/ndarray/cfill --- .../blas/ext/base/ndarray/cfill/README.md | 86 ++++++++++ .../base/ndarray/cfill/benchmark/benchmark.js | 57 +++++++ .../blas/ext/base/ndarray/cfill/docs/repl.txt | 38 +++++ .../base/ndarray/cfill/docs/types/index.d.ts | 53 ++++++ .../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 | 56 +++++++ .../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, 720 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..0cd14e8205d5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/README.md @@ -0,0 +1,86 @@ + + +# 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 ); + +cfill( x, alpha ); + +var v = x.get( 0 ); +// returns + +var re = v.re; +// returns 10.0 + +var im = v.im; +// returns 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..39037090099f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/repl.txt @@ -0,0 +1,38 @@ + +{{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 ) + + > var v = x.get( 0 ) + + > var re = v.re + 10.0 + > var im = v.im + 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..81486b549c9e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/types/index.d.ts @@ -0,0 +1,53 @@ +/* +* @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 ); +* +* cfill( x, alpha ); +* +* var v = x.get( 0 ); +* // returns +*/ +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..98836b96b2d0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/lib/index.js @@ -0,0 +1,56 @@ +/** +* @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 ); +* +* cfill( x, alpha ); +* +* var v = x.get( 0 ); +* // returns +* +* var re = v.re; +* // returns 10.0 +* +* var im = v.im; +* // returns 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..ae2e6b11b0ba --- /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 N; + var sx; + var ox; + var buf; + + 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 224ba51139e6c24746b215c6745ed557a0b7e29c Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Fri, 19 Dec 2025 17:37:18 +0530 Subject: [PATCH 2/2] docs: update return annotations to use ndarray instance notation --- .../@stdlib/blas/ext/base/ndarray/cfill/README.md | 12 ++---------- .../blas/ext/base/ndarray/cfill/docs/repl.txt | 11 ++--------- .../ext/base/ndarray/cfill/docs/types/index.d.ts | 6 ++---- .../@stdlib/blas/ext/base/ndarray/cfill/lib/index.js | 12 ++---------- 4 files changed, 8 insertions(+), 33 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 0cd14e8205d5..129eec3d7a32 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 @@ -42,16 +42,8 @@ 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 +var out = cfill( x, alpha ); +// returns [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] ``` ## Examples 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 39037090099f..7f9e749c3d69 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 @@ -22,16 +22,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 ) - + > var alpha = new {{alias:@stdlib/complex/float32/ctor}}( 10.0, 10.0 ); > {{alias}}( x, alpha ) - - > var v = x.get( 0 ) - - > var re = v.re - 10.0 - > var im = v.im - 10.0 + [ [ 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 81486b549c9e..ffd54ff9f533 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 @@ -40,10 +40,8 @@ import { Complex64 } from '@stdlib/types/complex'; * * var alpha = new Complex64( 10.0, 10.0 ); * -* cfill( x, alpha ); -* -* var v = x.get( 0 ); -* // returns +* var out = cfill( x, alpha ); +* // returns [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] */ declare function cfill( x: complex64ndarray, alpha: Complex64 ): complex64ndarray; 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 98836b96b2d0..3e8fa7c12ea6 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 @@ -34,16 +34,8 @@ * * 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 +* var out = cfill( x, alpha ); +* // returns [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] */ // MODULES //