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..80134b31ccd3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/test/test.js @@ -0,0 +1,196 @@ +/** +* @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(); +});