From 5e264b44162fa31dba7611172e2c45aff1e4578a Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Tue, 16 Dec 2025 10:52:10 +0530 Subject: [PATCH 1/6] feat: add @stdlib/blas/ext/base/ndarray/gfill Implements generic fill function for one-dimensional ndarrays. - Fills ndarray with any JavaScript value (numbers, objects, etc.) - Wraps existing strided gfill.ndarray implementation - Supports non-unit strides, negative strides, and offsets - Includes comprehensive tests, examples, benchmarks, and TypeScript definitions Signature: gfill( x, alpha ) returns x (transformation operation) --- .../blas/ext/base/ndarray/gfill/README.md | 107 ++++++++++ .../base/ndarray/gfill/benchmark/benchmark.js | 100 +++++++++ .../blas/ext/base/ndarray/gfill/docs/repl.txt | 34 +++ .../base/ndarray/gfill/docs/types/index.d.ts | 46 +++++ .../ext/base/ndarray/gfill/docs/types/test.ts | 67 ++++++ .../ext/base/ndarray/gfill/examples/index.js | 33 +++ .../blas/ext/base/ndarray/gfill/lib/index.js | 44 ++++ .../blas/ext/base/ndarray/gfill/lib/main.js | 56 +++++ .../blas/ext/base/ndarray/gfill/package.json | 64 ++++++ .../blas/ext/base/ndarray/gfill/test/test.js | 194 ++++++++++++++++++ 10 files changed, 745 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/test/test.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/README.md new file mode 100644 index 000000000000..57248cffeb3f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/README.md @@ -0,0 +1,107 @@ + + +# gfill + +> Fill a one-dimensional ndarray with a specified value. + +
+ +## Usage + +```javascript +var gfill = require( '@stdlib/blas/ext/base/ndarray/gfill' ); +``` + +#### gfill( x, alpha ) + +Fills a one-dimensional ndarray with a specified value. + +```javascript +var ndarray = require( '@stdlib/ndarray/base/ctor' ); + +var xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; +var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + +gfill( x, 5.0 ); +// xbuf => [ 5.0, 5.0, 5.0, 5.0 ] +``` + +The function has the following parameters: + +- **x**: input ndarray. +- **alpha**: fill value. + +
+ + + +
+ +## Notes + +- The function modifies the input ndarray in-place. +- The function supports ndarrays having non-unit strides and non-zero offsets. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var gfill = require( '@stdlib/blas/ext/base/ndarray/gfill' ); + +var xbuf = discreteUniform( 10, -50, 50, { + 'dtype': 'generic' +}); +var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +gfill( x, 5.0 ); +console.log( ndarray2array( x ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/benchmark/benchmark.js new file mode 100644 index 000000000000..b2bdc51ff518 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/benchmark/benchmark.js @@ -0,0 +1,100 @@ +/** +* @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 uniform = require( '@stdlib/random/array/uniform' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var pkg = require( './../package.json' ).name; +var gfill = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var xbuf; + var x; + + xbuf = uniform( len, -10.0, 10.0, options ); + x = new ndarray( options.dtype, xbuf, [ len ], [ 1 ], 0, 'row-major' ); + + return benchmark; + + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + gfill( x, 5.0 ); + if ( xbuf[ 0 ] !== 5.0 ) { + b.fail( 'unexpected result' ); + } + } + b.toc(); + if ( xbuf[ 0 ] !== 5.0 ) { + b.fail( 'unexpected result' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/docs/repl.txt new file mode 100644 index 000000000000..7e30f23439e3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/docs/repl.txt @@ -0,0 +1,34 @@ + +{{alias}}( x, alpha ) + Fills a one-dimensional ndarray with a specified value. + + Parameters + ---------- + x: ndarray + Input ndarray. + + alpha: any + Fill value. + + Returns + ------- + out: ndarray + Input ndarray. + + Examples + -------- + > var xbuf = [ 1.0, 2.0, 3.0 ]; + > var dt = 'generic'; + > var sh = [ xbuf.length ]; + > var sx = [ 1 ]; + > var ox = 0; + > var ord = 'row-major'; + > var x = new {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, sx, ox, ord ); + > {{alias}}( x, 5.0 ) + + > xbuf + [ 5.0, 5.0, 5.0 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/docs/types/index.d.ts new file mode 100644 index 000000000000..8f12747251c5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/docs/types/index.d.ts @@ -0,0 +1,46 @@ +/* +* @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 { typedndarray } from '@stdlib/types/ndarray'; + +/** +* Fills a one-dimensional ndarray with a specified value. +* +* @param x - input ndarray +* @param alpha - fill value +* @returns input ndarray +* +* @example +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* +* var xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; +* var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* gfill( x, 5.0 ); +* // xbuf => [ 5.0, 5.0, 5.0, 5.0 ] +*/ +declare function gfill( x: typedndarray, alpha: T ): typedndarray; + + +// EXPORTS // + +export = gfill; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/docs/types/test.ts new file mode 100644 index 000000000000..367466443b9b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/docs/types/test.ts @@ -0,0 +1,67 @@ +/* +* @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. +*/ + +/* eslint-disable space-in-parens */ + +import zeros = require( '@stdlib/ndarray/zeros' ); +import gfill = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 10 ], { + 'dtype': 'float64' + }); + + gfill( x, 5.0 ); // $ExpectType typedndarray +} + +// The function works with generic values... +{ + const x = zeros( [ 10 ], { + 'dtype': 'generic' + }); + + gfill( x, { 'value': 42 } ); // $ExpectType typedndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + gfill( '10', 5.0 ); // $ExpectError + gfill( 10, 5.0 ); // $ExpectError + gfill( true, 5.0 ); // $ExpectError + gfill( false, 5.0 ); // $ExpectError + gfill( null, 5.0 ); // $ExpectError + gfill( undefined, 5.0 ); // $ExpectError + gfill( [], 5.0 ); // $ExpectError + gfill( {}, 5.0 ); // $ExpectError + gfill( ( x: number ): number => x, 5.0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 10 ], { + 'dtype': 'float64' + }); + + gfill(); // $ExpectError + gfill( x ); // $ExpectError + gfill( x, 5.0, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/examples/index.js new file mode 100644 index 000000000000..7141594940cf --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/examples/index.js @@ -0,0 +1,33 @@ +/** +* @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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var gfill = require( './../lib' ); + +var xbuf = discreteUniform( 10, -50, 50, { + 'dtype': 'generic' +}); +var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +gfill( x, 5.0 ); +console.log( ndarray2array( x ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/lib/index.js new file mode 100644 index 000000000000..db013d0e36de --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/lib/index.js @@ -0,0 +1,44 @@ +/** +* @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 one-dimensional ndarray with a specified value. +* +* @module @stdlib/blas/ext/base/ndarray/gfill +* +* @example +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var gfill = require( '@stdlib/blas/ext/base/ndarray/gfill' ); +* +* var xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; +* var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* gfill( x, 5.0 ); +* // xbuf => [ 5.0, 5.0, 5.0, 5.0 ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/lib/main.js new file mode 100644 index 000000000000..58837fbdc3a9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/lib/main.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'; + +// 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 strided = require( '@stdlib/blas/ext/base/gfill' ).ndarray; + + +// MAIN // + +/** +* Fills a one-dimensional ndarray with a specified value. +* +* @param {ndarray} x - input ndarray +* @param {*} alpha - fill value +* @returns {ndarray} input ndarray +* +* @example +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* +* var xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; +* var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* gfill( x, 5.0 ); +* // xbuf => [ 5.0, 5.0, 5.0, 5.0 ] +*/ +function gfill( x, alpha ) { + strided( numelDimension( x, 0 ), alpha, getData( x ), getStride( x, 0 ), getOffset( x ) ); // eslint-disable-line max-len + return x; +} + + +// EXPORTS // + +module.exports = gfill; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/package.json b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/package.json new file mode 100644 index 000000000000..2a603b943324 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/package.json @@ -0,0 +1,64 @@ +{ + "name": "@stdlib/blas/ext/base/ndarray/gfill", + "version": "0.0.0", + "description": "Fill a one-dimensional ndarray with a specified value.", + "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", + "extended", + "fill", + "ndarray", + "set", + "assign" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/test/test.js new file mode 100644 index 000000000000..b83af112e02c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/test/test.js @@ -0,0 +1,194 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var gfill = 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( 'generic', buffer, [ length ], [ stride ], offset, 'row-major' ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gfill, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 2', function test( t ) { + t.strictEqual( gfill.length, 2, 'has expected arity' ); + t.end(); +}); + +tape( 'the function fills a one-dimensional ndarray with a specified value', function test( t ) { + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = vector( xbuf, 4, 1, 0 ); + + gfill( x, 5.0 ); + t.deepEqual( xbuf, [ 5.0, 5.0, 5.0, 5.0 ], 'returns expected value' ); + + xbuf = [ -1.0, -2.0, -3.0 ]; + x = vector( xbuf, 3, 1, 0 ); + + gfill( x, 0.0 ); + t.deepEqual( xbuf, [ 0.0, 0.0, 0.0 ], 'returns expected value' ); + + t.end(); +}); + +tape( 'the function fills a Float64Array-backed ndarray', function test( t ) { + var xbuf; + var x; + + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + + gfill( x, 7.0 ); + t.deepEqual( xbuf, new Float64Array( [ 7.0, 7.0, 7.0, 7.0 ] ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the function fills an ndarray with object values', function test( t ) { + var xbuf; + var obj; + var x; + + obj = { 'value': 42 }; + xbuf = [ 1, 2, 3, 4 ]; + x = vector( xbuf, 4, 1, 0 ); + + gfill( x, obj ); + t.strictEqual( xbuf[ 0 ], obj, 'first element is filled' ); + t.strictEqual( xbuf[ 1 ], obj, 'second element is filled' ); + t.strictEqual( xbuf[ 2 ], obj, 'third element is filled' ); + t.strictEqual( xbuf[ 3 ], obj, 'fourth element is filled' ); + + t.end(); +}); + +tape( 'the function supports ndarrays having non-unit strides', function test( t ) { + var xbuf; + var x; + + xbuf = [ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0, // 2 + 6.0 + ]; + x = vector( xbuf, 3, 2, 0 ); + + gfill( x, 9.0 ); + t.deepEqual( xbuf, [ 9.0, 2.0, 9.0, 4.0, 9.0, 6.0 ], 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports ndarrays having negative strides', function test( t ) { + var xbuf; + var x; + + xbuf = [ + 1.0, // 2 + 2.0, + 3.0, // 1 + 4.0, + 5.0, // 0 + 6.0 + ]; + x = vector( xbuf, 3, -2, 4 ); + + gfill( x, 8.0 ); + t.deepEqual( xbuf, [ 8.0, 2.0, 8.0, 4.0, 8.0, 6.0 ], 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports ndarrays having non-zero offsets', function test( t ) { + var xbuf; + var x; + + xbuf = [ + 1.0, + 2.0, + 3.0, // 0 + 4.0, // 1 + 5.0, // 2 + 6.0 + ]; + x = vector( xbuf, 3, 1, 2 ); + + gfill( x, 10.0 ); + t.deepEqual( xbuf, [ 1.0, 2.0, 10.0, 10.0, 10.0, 6.0 ], 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the input ndarray', function test( t ) { + var xbuf; + var out; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = vector( xbuf, 4, 1, 0 ); + + out = gfill( x, 5.0 ); + t.strictEqual( out, x, 'returns input ndarray' ); + + t.end(); +}); + +tape( 'if provided an ndarray having zero elements, the function returns the input ndarray unchanged', function test( t ) { + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0 ]; + x = vector( xbuf, 0, 1, 0 ); + + gfill( x, 5.0 ); + t.deepEqual( xbuf, [ 1.0, 2.0, 3.0 ], 'returns expected value' ); + + t.end(); +}); From 75f03bc43c19d5b1913df0fea627736453f8a55c Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Tue, 16 Dec 2025 10:59:15 +0530 Subject: [PATCH 2/6] fix: correct object literal formatting in gfill test - Fix ESLint object-curly-newline error on line 96 - Object literals must use multi-line format per stdlib style guide --- .../@stdlib/blas/ext/base/ndarray/gfill/test/test.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/test/test.js index b83af112e02c..80134b31ccd3 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/test/test.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/test/test.js @@ -93,7 +93,9 @@ tape( 'the function fills an ndarray with object values', function test( t ) { var obj; var x; - obj = { 'value': 42 }; + obj = { + 'value': 42 + }; xbuf = [ 1, 2, 3, 4 ]; x = vector( xbuf, 4, 1, 0 ); From 1c6cb318e2d70919f207d74b4b52724c686fccf6 Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Fri, 19 Dec 2025 18:31:07 +0530 Subject: [PATCH 3/6] docs: update return annotations to use ndarray instance notation --- .../@stdlib/blas/ext/base/ndarray/gfill/README.md | 4 ++-- .../@stdlib/blas/ext/base/ndarray/gfill/docs/repl.txt | 4 +--- .../@stdlib/blas/ext/base/ndarray/gfill/docs/types/index.d.ts | 4 ++-- .../@stdlib/blas/ext/base/ndarray/gfill/lib/index.js | 4 ++-- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/README.md index 57248cffeb3f..bb815a8a9830 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/README.md @@ -40,8 +40,8 @@ var ndarray = require( '@stdlib/ndarray/base/ctor' ); var xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); -gfill( x, 5.0 ); -// xbuf => [ 5.0, 5.0, 5.0, 5.0 ] +var out = gfill( x, 5.0 ); +// returns [ 5.0, 5.0, 5.0, 5.0 ] ``` The function has the following parameters: diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/docs/repl.txt index 7e30f23439e3..495270046805 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/docs/repl.txt @@ -25,9 +25,7 @@ > var ord = 'row-major'; > var x = new {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, sx, ox, ord ); > {{alias}}( x, 5.0 ) - - > xbuf - [ 5.0, 5.0, 5.0 ] + [ 5.0, 5.0, 5.0 ] See Also -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/docs/types/index.d.ts index 8f12747251c5..114adb3eadcc 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/docs/types/index.d.ts @@ -35,8 +35,8 @@ import { typedndarray } from '@stdlib/types/ndarray'; * var xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; * var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); * -* gfill( x, 5.0 ); -* // xbuf => [ 5.0, 5.0, 5.0, 5.0 ] +* var out = gfill( x, 5.0 ); +* // returns [ 5.0, 5.0, 5.0, 5.0 ] */ declare function gfill( x: typedndarray, alpha: T ): typedndarray; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/lib/index.js index db013d0e36de..a8ff47188b87 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/lib/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/lib/index.js @@ -30,8 +30,8 @@ * var xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; * var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); * -* gfill( x, 5.0 ); -* // xbuf => [ 5.0, 5.0, 5.0, 5.0 ] +* var out = gfill( x, 5.0 ); +* // returns [ 5.0, 5.0, 5.0, 5.0 ] */ // MODULES // From 71144b2bf86e5f7f554925faaf7454f72a6c3482 Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Sun, 21 Dec 2025 18:50:17 +0530 Subject: [PATCH 4/6] fix: refactor gfill to arrays API with dsorthp benchmark pattern --- .../blas/ext/base/ndarray/gfill/README.md | 46 ++++++++-------- .../base/ndarray/gfill/benchmark/benchmark.js | 17 +++--- .../blas/ext/base/ndarray/gfill/docs/repl.txt | 26 ++++------ .../base/ndarray/gfill/docs/types/index.d.ts | 20 ++++--- .../ext/base/ndarray/gfill/docs/types/test.ts | 52 ++++++++----------- .../ext/base/ndarray/gfill/examples/index.js | 13 ++++- .../blas/ext/base/ndarray/gfill/lib/index.js | 7 ++- .../blas/ext/base/ndarray/gfill/lib/main.js | 25 +++++++-- .../blas/ext/base/ndarray/gfill/test/test.js | 41 ++++++++++----- 9 files changed, 146 insertions(+), 101 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/README.md index bb815a8a9830..7cb4eec24b28 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/README.md @@ -30,59 +30,63 @@ limitations under the License. var gfill = require( '@stdlib/blas/ext/base/ndarray/gfill' ); ``` -#### gfill( x, alpha ) +#### gfill( arrays ) -Fills a one-dimensional ndarray with a specified value. +Fills a one-dimensional ndarray `x` with a specified value `alpha`. ```javascript +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); var ndarray = require( '@stdlib/ndarray/base/ctor' ); var xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); -var out = gfill( x, 5.0 ); -// returns [ 5.0, 5.0, 5.0, 5.0 ] +var alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' +}); + +var out = gfill( [ x, alpha ] ); +// returns + +var arr = ndarray2array( out ); +// returns [ 5.0, 5.0, 5.0, 5.0 ] ``` The function has the following parameters: -- **x**: input ndarray. -- **alpha**: fill value. +- **arrays**: array-like object containing a single one-dimensional input ndarray and a zero-dimensional ndarray containing a scalar constant. -
- -## Notes - -- The function modifies the input ndarray in-place. -- The function supports ndarrays having non-unit strides and non-zero offsets. - -
- - -
## Examples - - ```javascript var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); -var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); var gfill = require( '@stdlib/blas/ext/base/ndarray/gfill' ); var xbuf = discreteUniform( 10, -50, 50, { 'dtype': 'generic' }); var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); + +console.log( 'Before:' ); console.log( ndarray2array( x ) ); -gfill( x, 5.0 ); +var alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' +}); + +gfill( [ x, alpha ] ); + +console.log( 'After:' ); console.log( ndarray2array( x ) ); ``` diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/benchmark/benchmark.js index b2bdc51ff518..2b67ffc5a462 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/benchmark/benchmark.js @@ -24,6 +24,7 @@ var bench = require( '@stdlib/bench' ); var uniform = require( '@stdlib/random/array/uniform' ); var pow = require( '@stdlib/math/base/special/pow' ); var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); var pkg = require( './../package.json' ).name; var gfill = require( './../lib' ); @@ -45,27 +46,31 @@ var options = { * @returns {Function} benchmark function */ function createBenchmark( len ) { + var alpha; var xbuf; var x; - xbuf = uniform( len, -10.0, 10.0, options ); + xbuf = uniform( len, 0.0, 100.0, options ); x = new ndarray( options.dtype, xbuf, [ len ], [ 1 ], 0, 'row-major' ); + alpha = scalar2ndarray( 5.0, options ); + return benchmark; function benchmark( b ) { + var out; var i; b.tic(); for ( i = 0; i < b.iterations; i++ ) { - gfill( x, 5.0 ); - if ( xbuf[ 0 ] !== 5.0 ) { - b.fail( 'unexpected result' ); + out = gfill( [ x, alpha ] ); + if ( out !== out ) { + b.fail( 'should not return NaN' ); } } b.toc(); - if ( xbuf[ 0 ] !== 5.0 ) { - b.fail( 'unexpected result' ); + if ( out !== out ) { + b.fail( 'should not return NaN' ); } b.pass( 'benchmark finished' ); b.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/docs/repl.txt index 495270046805..780952e1f835 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/docs/repl.txt @@ -1,14 +1,12 @@ -{{alias}}( x, alpha ) +{{alias}}( arrays ) Fills a one-dimensional ndarray with a specified value. Parameters ---------- - x: ndarray - Input ndarray. - - alpha: any - Fill value. + arrays: ArrayLikeObject + Array-like object containing a single one-dimensional input ndarray + and a zero-dimensional ndarray containing a scalar constant. Returns ------- @@ -17,16 +15,12 @@ Examples -------- - > var xbuf = [ 1.0, 2.0, 3.0 ]; - > var dt = 'generic'; - > var sh = [ xbuf.length ]; - > var sx = [ 1 ]; - > var ox = 0; - > var ord = 'row-major'; - > var x = new {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, sx, ox, ord ); - > {{alias}}( x, 5.0 ) - [ 5.0, 5.0, 5.0 ] + > var xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + > var x = {{alias:@stdlib/ndarray/base/ctor}}( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + > var s2n = {{alias:@stdlib/ndarray/from-scalar}}; + > var alpha = s2n( 5.0, { 'dtype': 'generic' } ); + > {{alias}}( [ x, alpha ] ) + [ 5.0, 5.0, 5.0, 5.0 ] See Also -------- - diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/docs/types/index.d.ts index 114adb3eadcc..04370c34a7c2 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/docs/types/index.d.ts @@ -20,25 +20,33 @@ /// -import { typedndarray } from '@stdlib/types/ndarray'; +import { ndarray } from '@stdlib/types/ndarray'; /** * Fills a one-dimensional ndarray with a specified value. * -* @param x - input ndarray -* @param alpha - fill value +* @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 scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); * var ndarray = require( '@stdlib/ndarray/base/ctor' ); * * var xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; * var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); * -* var out = gfill( x, 5.0 ); -* // returns [ 5.0, 5.0, 5.0, 5.0 ] +* var alpha = scalar2ndarray( 5.0, { +* 'dtype': 'generic' +* }); +* +* var out = gfill( [ x, alpha ] ); +* // returns +* +* var arr = ndarray2array( out ); +* // returns [ 5.0, 5.0, 5.0, 5.0 ] */ -declare function gfill( x: typedndarray, alpha: T ): typedndarray; +declare function gfill( arrays: [ ndarray, ndarray ] ): ndarray; // EXPORTS // diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/docs/types/test.ts index 367466443b9b..95427aabbcf8 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/docs/types/test.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/docs/types/test.ts @@ -16,9 +16,8 @@ * limitations under the License. */ -/* eslint-disable space-in-parens */ - -import zeros = require( '@stdlib/ndarray/zeros' ); +import zeros = require( '@stdlib/ndarray/base/zeros' ); +import scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); import gfill = require( './index' ); @@ -26,42 +25,35 @@ import gfill = require( './index' ); // The function returns an ndarray... { - const x = zeros( [ 10 ], { - 'dtype': 'float64' + const x = zeros( 'generic', [ 10 ], 'row-major' ); + const alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' }); - - gfill( x, 5.0 ); // $ExpectType typedndarray + gfill( [ x, alpha ] ); // $ExpectType ndarray } -// The function works with generic values... +// The compiler throws an error if the function is provided a first argument which is not an array-like object... { - const x = zeros( [ 10 ], { - 'dtype': 'generic' - }); - - gfill( x, { 'value': 42 } ); // $ExpectType typedndarray + gfill( 'abc' ); // $ExpectError + gfill( 5 ); // $ExpectError + gfill( true ); // $ExpectError + gfill( false ); // $ExpectError + gfill( null ); // $ExpectError + gfill( undefined ); // $ExpectError + gfill( {} ); // $ExpectError + gfill( ( x: number ): number => x ); // $ExpectError } -// 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 an insufficient number of arguments... { - gfill( '10', 5.0 ); // $ExpectError - gfill( 10, 5.0 ); // $ExpectError - gfill( true, 5.0 ); // $ExpectError - gfill( false, 5.0 ); // $ExpectError - gfill( null, 5.0 ); // $ExpectError - gfill( undefined, 5.0 ); // $ExpectError - gfill( [], 5.0 ); // $ExpectError - gfill( {}, 5.0 ); // $ExpectError - gfill( ( x: number ): number => x, 5.0 ); // $ExpectError + gfill(); // $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 x = zeros( [ 10 ], { - 'dtype': 'float64' + const x = zeros( 'generic', [ 10 ], 'row-major' ); + const alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' }); - - gfill(); // $ExpectError - gfill( x ); // $ExpectError - gfill( x, 5.0, {} ); // $ExpectError + gfill( [ x, alpha ], 10 ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/examples/index.js index 7141594940cf..658565fd22bf 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/examples/index.js @@ -19,15 +19,24 @@ 'use strict'; var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); -var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); var gfill = require( './../lib' ); var xbuf = discreteUniform( 10, -50, 50, { 'dtype': 'generic' }); var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); + +console.log( 'Before:' ); console.log( ndarray2array( x ) ); -gfill( x, 5.0 ); +var alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' +}); + +gfill( [ x, alpha ] ); + +console.log( 'After:' ); console.log( ndarray2array( x ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/lib/index.js index a8ff47188b87..a1c2c7a034c6 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/lib/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/lib/index.js @@ -24,13 +24,18 @@ * @module @stdlib/blas/ext/base/ndarray/gfill * * @example +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); * var ndarray = require( '@stdlib/ndarray/base/ctor' ); * var gfill = require( '@stdlib/blas/ext/base/ndarray/gfill' ); * * var xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; * var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); * -* var out = gfill( x, 5.0 ); +* var alpha = scalar2ndarray( 5.0, { +* 'dtype': 'generic' +* }); +* +* var out = gfill( [ x, alpha ] ); * // returns [ 5.0, 5.0, 5.0, 5.0 ] */ diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/lib/main.js index 58837fbdc3a9..08dfd1ce1513 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/lib/main.js @@ -21,6 +21,7 @@ // MODULES // var numelDimension = require( '@stdlib/ndarray/base/numel-dimension' ); +var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); var getStride = require( '@stdlib/ndarray/base/stride' ); var getOffset = require( '@stdlib/ndarray/base/offset' ); var getData = require( '@stdlib/ndarray/base/data-buffer' ); @@ -32,20 +33,34 @@ var strided = require( '@stdlib/blas/ext/base/gfill' ).ndarray; /** * Fills a one-dimensional ndarray with a specified value. * -* @param {ndarray} x - input ndarray -* @param {*} alpha - fill value +* @param {ArrayLikeObject} arrays - array-like object containing a single one-dimensional input ndarray and a zero-dimensional ndarray containing a scalar constant * @returns {ndarray} input ndarray * * @example +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); * var ndarray = require( '@stdlib/ndarray/base/ctor' ); * * var xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; * var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); * -* gfill( x, 5.0 ); -* // xbuf => [ 5.0, 5.0, 5.0, 5.0 ] +* var alpha = scalar2ndarray( 5.0, { +* 'dtype': 'generic' +* }); +* +* var out = gfill( [ x, alpha ] ); +* // returns +* +* var arr = ndarray2array( out ); +* // returns [ 5.0, 5.0, 5.0, 5.0 ] */ -function gfill( x, alpha ) { +function gfill( arrays ) { + var alpha; + var x; + + x = arrays[ 0 ]; + alpha = ndarraylike2scalar( arrays[ 1 ] ); + strided( numelDimension( x, 0 ), alpha, getData( x ), getStride( x, 0 ), getOffset( x ) ); // eslint-disable-line max-len return x; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/test/test.js index 80134b31ccd3..67978e4395c9 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/test/test.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/test/test.js @@ -22,6 +22,7 @@ var tape = require( 'tape' ); var Float64Array = require( '@stdlib/array/float64' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); var ndarray = require( '@stdlib/ndarray/base/ctor' ); var gfill = require( './../lib' ); @@ -51,44 +52,45 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -tape( 'the function has an arity of 2', function test( t ) { - t.strictEqual( gfill.length, 2, 'has expected arity' ); - t.end(); -}); - tape( 'the function fills a one-dimensional ndarray with a specified value', function test( t ) { + var alpha; var xbuf; var x; xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; x = vector( xbuf, 4, 1, 0 ); + alpha = scalar2ndarray( 5.0, { 'dtype': 'generic' }); - gfill( x, 5.0 ); + gfill( [ x, alpha ] ); t.deepEqual( xbuf, [ 5.0, 5.0, 5.0, 5.0 ], 'returns expected value' ); xbuf = [ -1.0, -2.0, -3.0 ]; x = vector( xbuf, 3, 1, 0 ); + alpha = scalar2ndarray( 0.0, { 'dtype': 'generic' }); - gfill( x, 0.0 ); + gfill( [ x, alpha ] ); t.deepEqual( xbuf, [ 0.0, 0.0, 0.0 ], 'returns expected value' ); t.end(); }); tape( 'the function fills a Float64Array-backed ndarray', function test( t ) { + var alpha; var xbuf; var x; xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + alpha = scalar2ndarray( 7.0, { 'dtype': 'float64' }); - gfill( x, 7.0 ); + gfill( [ x, alpha ] ); t.deepEqual( xbuf, new Float64Array( [ 7.0, 7.0, 7.0, 7.0 ] ), 'returns expected value' ); t.end(); }); tape( 'the function fills an ndarray with object values', function test( t ) { + var alpha; var xbuf; var obj; var x; @@ -98,8 +100,9 @@ tape( 'the function fills an ndarray with object values', function test( t ) { }; xbuf = [ 1, 2, 3, 4 ]; x = vector( xbuf, 4, 1, 0 ); + alpha = scalar2ndarray( obj, { 'dtype': 'generic' }); - gfill( x, obj ); + gfill( [ x, alpha ] ); t.strictEqual( xbuf[ 0 ], obj, 'first element is filled' ); t.strictEqual( xbuf[ 1 ], obj, 'second element is filled' ); t.strictEqual( xbuf[ 2 ], obj, 'third element is filled' ); @@ -109,6 +112,7 @@ tape( 'the function fills an ndarray with object values', function test( t ) { }); tape( 'the function supports ndarrays having non-unit strides', function test( t ) { + var alpha; var xbuf; var x; @@ -121,14 +125,16 @@ tape( 'the function supports ndarrays having non-unit strides', function test( t 6.0 ]; x = vector( xbuf, 3, 2, 0 ); + alpha = scalar2ndarray( 9.0, { 'dtype': 'generic' }); - gfill( x, 9.0 ); + gfill( [ x, alpha ] ); t.deepEqual( xbuf, [ 9.0, 2.0, 9.0, 4.0, 9.0, 6.0 ], 'returns expected value' ); t.end(); }); tape( 'the function supports ndarrays having negative strides', function test( t ) { + var alpha; var xbuf; var x; @@ -141,14 +147,16 @@ tape( 'the function supports ndarrays having negative strides', function test( t 6.0 ]; x = vector( xbuf, 3, -2, 4 ); + alpha = scalar2ndarray( 8.0, { 'dtype': 'generic' }); - gfill( x, 8.0 ); + gfill( [ x, alpha ] ); t.deepEqual( xbuf, [ 8.0, 2.0, 8.0, 4.0, 8.0, 6.0 ], 'returns expected value' ); t.end(); }); tape( 'the function supports ndarrays having non-zero offsets', function test( t ) { + var alpha; var xbuf; var x; @@ -161,35 +169,40 @@ tape( 'the function supports ndarrays having non-zero offsets', function test( t 6.0 ]; x = vector( xbuf, 3, 1, 2 ); + alpha = scalar2ndarray( 10.0, { 'dtype': 'generic' }); - gfill( x, 10.0 ); + gfill( [ x, alpha ] ); t.deepEqual( xbuf, [ 1.0, 2.0, 10.0, 10.0, 10.0, 6.0 ], 'returns expected value' ); t.end(); }); tape( 'the function returns the input ndarray', function test( t ) { + var alpha; var xbuf; var out; var x; xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; x = vector( xbuf, 4, 1, 0 ); + alpha = scalar2ndarray( 5.0, { 'dtype': 'generic' }); - out = gfill( x, 5.0 ); + out = gfill( [ x, alpha ] ); t.strictEqual( out, x, 'returns input ndarray' ); t.end(); }); tape( 'if provided an ndarray having zero elements, the function returns the input ndarray unchanged', function test( t ) { + var alpha; var xbuf; var x; xbuf = [ 1.0, 2.0, 3.0 ]; x = vector( xbuf, 0, 1, 0 ); + alpha = scalar2ndarray( 5.0, { 'dtype': 'generic' }); - gfill( x, 5.0 ); + gfill( [ x, alpha ] ); t.deepEqual( xbuf, [ 1.0, 2.0, 3.0 ], 'returns expected value' ); t.end(); From fe9c234d52fb026239fc1669d35e19c8e6a5c9fe Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Sun, 21 Dec 2025 18:58:59 +0530 Subject: [PATCH 5/6] fix: gfill ESLint object-curly-newline errors --- .../blas/ext/base/ndarray/gfill/test/test.js | 36 ++++++++++++++----- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/test/test.js index 67978e4395c9..25e515f57ce4 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/test/test.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/test/test.js @@ -59,14 +59,18 @@ tape( 'the function fills a one-dimensional ndarray with a specified value', fun xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; x = vector( xbuf, 4, 1, 0 ); - alpha = scalar2ndarray( 5.0, { 'dtype': 'generic' }); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); gfill( [ x, alpha ] ); t.deepEqual( xbuf, [ 5.0, 5.0, 5.0, 5.0 ], 'returns expected value' ); xbuf = [ -1.0, -2.0, -3.0 ]; x = vector( xbuf, 3, 1, 0 ); - alpha = scalar2ndarray( 0.0, { 'dtype': 'generic' }); + alpha = scalar2ndarray( 0.0, { + 'dtype': 'generic' + }); gfill( [ x, alpha ] ); t.deepEqual( xbuf, [ 0.0, 0.0, 0.0 ], 'returns expected value' ); @@ -81,7 +85,9 @@ tape( 'the function fills a Float64Array-backed ndarray', function test( t ) { xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - alpha = scalar2ndarray( 7.0, { 'dtype': 'float64' }); + alpha = scalar2ndarray( 7.0, { + 'dtype': 'float64' + }); gfill( [ x, alpha ] ); t.deepEqual( xbuf, new Float64Array( [ 7.0, 7.0, 7.0, 7.0 ] ), 'returns expected value' ); @@ -100,7 +106,9 @@ tape( 'the function fills an ndarray with object values', function test( t ) { }; xbuf = [ 1, 2, 3, 4 ]; x = vector( xbuf, 4, 1, 0 ); - alpha = scalar2ndarray( obj, { 'dtype': 'generic' }); + alpha = scalar2ndarray( obj, { + 'dtype': 'generic' + }); gfill( [ x, alpha ] ); t.strictEqual( xbuf[ 0 ], obj, 'first element is filled' ); @@ -125,7 +133,9 @@ tape( 'the function supports ndarrays having non-unit strides', function test( t 6.0 ]; x = vector( xbuf, 3, 2, 0 ); - alpha = scalar2ndarray( 9.0, { 'dtype': 'generic' }); + alpha = scalar2ndarray( 9.0, { + 'dtype': 'generic' + }); gfill( [ x, alpha ] ); t.deepEqual( xbuf, [ 9.0, 2.0, 9.0, 4.0, 9.0, 6.0 ], 'returns expected value' ); @@ -147,7 +157,9 @@ tape( 'the function supports ndarrays having negative strides', function test( t 6.0 ]; x = vector( xbuf, 3, -2, 4 ); - alpha = scalar2ndarray( 8.0, { 'dtype': 'generic' }); + alpha = scalar2ndarray( 8.0, { + 'dtype': 'generic' + }); gfill( [ x, alpha ] ); t.deepEqual( xbuf, [ 8.0, 2.0, 8.0, 4.0, 8.0, 6.0 ], 'returns expected value' ); @@ -169,7 +181,9 @@ tape( 'the function supports ndarrays having non-zero offsets', function test( t 6.0 ]; x = vector( xbuf, 3, 1, 2 ); - alpha = scalar2ndarray( 10.0, { 'dtype': 'generic' }); + alpha = scalar2ndarray( 10.0, { + 'dtype': 'generic' + }); gfill( [ x, alpha ] ); t.deepEqual( xbuf, [ 1.0, 2.0, 10.0, 10.0, 10.0, 6.0 ], 'returns expected value' ); @@ -185,7 +199,9 @@ tape( 'the function returns the input ndarray', function test( t ) { xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; x = vector( xbuf, 4, 1, 0 ); - alpha = scalar2ndarray( 5.0, { 'dtype': 'generic' }); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); out = gfill( [ x, alpha ] ); t.strictEqual( out, x, 'returns input ndarray' ); @@ -200,7 +216,9 @@ tape( 'if provided an ndarray having zero elements, the function returns the inp xbuf = [ 1.0, 2.0, 3.0 ]; x = vector( xbuf, 0, 1, 0 ); - alpha = scalar2ndarray( 5.0, { 'dtype': 'generic' }); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); gfill( [ x, alpha ] ); t.deepEqual( xbuf, [ 1.0, 2.0, 3.0 ], 'returns expected value' ); From 4b48da2ac72b4150a228d33941c250603ac91d31 Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Mon, 22 Dec 2025 07:48:48 +0530 Subject: [PATCH 6/6] fix: gfill benchmark - use @stdlib/string/format per RFC #8647 --- .../@stdlib/blas/ext/base/ndarray/gfill/benchmark/benchmark.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/benchmark/benchmark.js index 2b67ffc5a462..532b4d724a3c 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/benchmark/benchmark.js @@ -25,6 +25,7 @@ var uniform = require( '@stdlib/random/array/uniform' ); var pow = require( '@stdlib/math/base/special/pow' ); var ndarray = require( '@stdlib/ndarray/base/ctor' ); var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var format = require( '@stdlib/string/format' ); var pkg = require( './../package.json' ).name; var gfill = require( './../lib' ); @@ -98,7 +99,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 ); } }