diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sfill/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sfill/README.md new file mode 100644 index 000000000000..c9396aa1ab36 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sfill/README.md @@ -0,0 +1,112 @@ + + +# sfill + +> Fill a single-precision floating-point ndarray with a specified value. + +
+ +
+ + + +
+ +## Usage + +```javascript +var sfill = require( '@stdlib/blas/ext/base/ndarray/sfill' ); +``` + +#### sfill( x, alpha ) + +Fills a single-precision floating-point ndarray `x` with a specified value `alpha`. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); +var array = require( '@stdlib/ndarray/array' ); + +var x = array( new Float32Array( [ 1.0, 2.0, 3.0 ] ) ); + +var out = sfill( x, 5.0 ); +// returns [ 5.0, 5.0, 5.0 ] +``` + +The function has the following parameters: + +- **x**: input ndarray. +- **alpha**: fill value. + +
+ + + +
+ +## Notes + +- If provided an ndarray with a length of `0`, the function returns the ndarray unchanged. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var Float32Array = require( '@stdlib/array/float32' ); +var array = require( '@stdlib/ndarray/array' ); +var sfill = require( '@stdlib/blas/ext/base/ndarray/sfill' ); + +var xbuf = discreteUniform( 10, -100, 100, { + 'dtype': 'float32' +}); +var x = array( xbuf ); +console.log( x.data ); + +sfill( x, 5.0 ); +console.log( x.data ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sfill/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sfill/benchmark/benchmark.js new file mode 100644 index 000000000000..f204a03d26cb --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sfill/benchmark/benchmark.js @@ -0,0 +1,115 @@ +/** +* @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 Float32Array = require( '@stdlib/array/float32' ); +var array = require( '@stdlib/ndarray/array' ); +var isFloat32Array = require( '@stdlib/assert/is-float32array' ); +var pkg = require( './../package.json' ).name; +var sfill = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var x; + var i; + + x = array( new Float32Array( 10 ) ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + sfill( x, 5.0 ); + if ( x.data[ 0 ] !== 5.0 ) { + b.fail( 'should fill ndarray' ); + } + } + b.toc(); + if ( !isFloat32Array( x.data ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::ndarray,len=10', function benchmark( b ) { + var x; + var i; + + x = array( new Float32Array( 10 ) ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + sfill( x, 5.0 ); + if ( x.data[ 0 ] !== 5.0 ) { + b.fail( 'should fill ndarray' ); + } + } + b.toc(); + if ( !isFloat32Array( x.data ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::ndarray,len=100', function benchmark( b ) { + var x; + var i; + + x = array( new Float32Array( 100 ) ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + sfill( x, 5.0 ); + if ( x.data[ 0 ] !== 5.0 ) { + b.fail( 'should fill ndarray' ); + } + } + b.toc(); + if ( !isFloat32Array( x.data ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::ndarray,len=1000', function benchmark( b ) { + var x; + var i; + + x = array( new Float32Array( 1000 ) ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + sfill( x, 5.0 ); + if ( x.data[ 0 ] !== 5.0 ) { + b.fail( 'should fill ndarray' ); + } + } + b.toc(); + if ( !isFloat32Array( x.data ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sfill/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sfill/docs/repl.txt new file mode 100644 index 000000000000..1a92a5277ece --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sfill/docs/repl.txt @@ -0,0 +1,26 @@ + +{{alias}}( x, alpha ) + Fills a single-precision floating-point ndarray with a specified value. + + Parameters + ---------- + x: float32ndarray + Input ndarray. + + alpha: number + Fill value. + + Returns + ------- + out: float32ndarray + Input ndarray. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/array}}( new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 3.0 ] ) ); + > {{alias}}( x, 5.0 ) + [ 5.0, 5.0, 5.0 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sfill/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sfill/docs/types/index.d.ts new file mode 100644 index 000000000000..536dbce16d85 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sfill/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 { float32ndarray } from '@stdlib/types/ndarray'; + +/** +* Fills a single-precision floating-point ndarray with a specified value. +* +* @param x - input ndarray +* @param alpha - fill value +* @returns input ndarray +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( new Float32Array( [ 1.0, 2.0, 3.0 ] ) ); +* +* var out = sfill( x, 5.0 ); +* // returns [ 5.0, 5.0, 5.0 ] +*/ +declare function sfill( x: float32ndarray, alpha: number ): float32ndarray; + + +// EXPORTS // + +export = sfill; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sfill/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sfill/docs/types/test.ts new file mode 100644 index 000000000000..94346daa70b1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sfill/docs/types/test.ts @@ -0,0 +1,66 @@ +/* +* @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 sfill = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 10 ], { 'dtype': 'float32' } ); + + sfill( x, 5.0 ); // $ExpectType float32ndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + sfill( 5, 5.0 ); // $ExpectError + sfill( true, 5.0 ); // $ExpectError + sfill( false, 5.0 ); // $ExpectError + sfill( null, 5.0 ); // $ExpectError + sfill( undefined, 5.0 ); // $ExpectError + sfill( [ 1, 2, 3 ], 5.0 ); // $ExpectError + sfill( {}, 5.0 ); // $ExpectError + sfill( ( x: number ): number => x, 5.0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const x = zeros( [ 10 ], { 'dtype': 'float32' } ); + + sfill( x, '5' ); // $ExpectError + sfill( x, true ); // $ExpectError + sfill( x, false ); // $ExpectError + sfill( x, null ); // $ExpectError + sfill( x, [] ); // $ExpectError + sfill( x, {} ); // $ExpectError + sfill( x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 10 ], { 'dtype': 'float32' } ); + + sfill(); // $ExpectError + sfill( x ); // $ExpectError + sfill( x, 5.0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sfill/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sfill/examples/index.js new file mode 100644 index 000000000000..796e236968e1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sfill/examples/index.js @@ -0,0 +1,32 @@ +/** +* @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 array = require( '@stdlib/ndarray/array' ); +var sfill = require( './../lib' ); + +var xbuf = discreteUniform( 10, -100, 100, { + 'dtype': 'float32' +}); +var x = array( xbuf ); +console.log( x.data ); + +sfill( x, 5.0 ); +console.log( x.data ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sfill/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sfill/lib/index.js new file mode 100644 index 000000000000..604a9d3f60cf --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sfill/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 single-precision floating-point ndarray with a specified value. +* +* @module @stdlib/blas/ext/base/ndarray/sfill +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var array = require( '@stdlib/ndarray/array' ); +* var sfill = require( '@stdlib/blas/ext/base/ndarray/sfill' ); +* +* var x = array( new Float32Array( [ 1.0, 2.0, 3.0 ] ) ); +* +* var out = sfill( x, 5.0 ); +* // returns [ 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/sfill/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sfill/lib/main.js new file mode 100644 index 000000000000..f90e561225cc --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sfill/lib/main.js @@ -0,0 +1,62 @@ +/** +* @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/sfill' ).ndarray; + + +// MAIN // + +/** +* Fills a single-precision floating-point ndarray with a specified value. +* +* @param {float32ndarray} x - input ndarray +* @param {number} alpha - fill value +* @returns {float32ndarray} input ndarray +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( new Float32Array( [ 1.0, 2.0, 3.0 ] ) ); +* +* sfill( x, 5.0 ); +* +* var xbuf = x.data; +* // returns [ 5.0, 5.0, 5.0 ] +*/ +function sfill( x, alpha ) { + var offset = getOffset( x ); + var stride = getStride( x, 0 ); + var N = numelDimension( x, 0 ); + + strided( N, alpha, getData( x ), stride, offset ); + return x; +} + + +// EXPORTS // + +module.exports = sfill; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sfill/package.json b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sfill/package.json new file mode 100644 index 000000000000..97915f241e88 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sfill/package.json @@ -0,0 +1,69 @@ +{ + "name": "@stdlib/blas/ext/base/ndarray/sfill", + "version": "0.0.0", + "description": "Fill a single-precision floating-point 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", + "assign", + "set", + "strided", + "array", + "ndarray", + "float32", + "float32array", + "single" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sfill/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sfill/test/test.js new file mode 100644 index 000000000000..4a9fdb91d4a0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sfill/test/test.js @@ -0,0 +1,141 @@ +/** +* @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 Float32Array = require( '@stdlib/array/float32' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var array = require( '@stdlib/ndarray/array' ); +var sfill = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof sfill, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 2', function test( t ) { + t.strictEqual( sfill.length, 2, 'has expected arity' ); + t.end(); +}); + +tape( 'the function fills an ndarray with a specified value', function test( t ) { + var expected; + var x; + + x = array( new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ) ); + expected = new Float32Array( [ 5.0, 5.0, 5.0, 5.0, 5.0 ] ); + + sfill( x, 5.0 ); + + t.deepEqual( x.data, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the input ndarray', function test( t ) { + var x; + var y; + + x = array( new Float32Array( [ 1.0, 2.0, 3.0 ] ) ); + y = sfill( x, 5.0 ); + + t.strictEqual( y, x, 'returns input ndarray' ); + t.end(); +}); + +tape( 'the function supports an ndarray having a stride greater than 1', function test( t ) { + var expected; + var xbuf; + var x; + + xbuf = new Float32Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ]); + x = new ndarray( 'float32', xbuf, [ 3 ], [ 2 ], 0, 'row-major' ); + expected = new Float32Array( [ 5.0, 2.0, 5.0, 4.0, 5.0 ] ); + + sfill( x, 5.0 ); + + t.deepEqual( x.data, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an ndarray having a negative stride', function test( t ) { + var expected; + var xbuf; + var x; + + xbuf = new Float32Array([ + 1.0, // 2 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 0 + ]); + x = new ndarray( 'float32', xbuf, [ 3 ], [ -2 ], 4, 'row-major' ); + expected = new Float32Array( [ 5.0, 2.0, 5.0, 4.0, 5.0 ] ); + + sfill( x, 5.0 ); + + t.deepEqual( x.data, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an ndarray having an offset', function test( t ) { + var expected; + var xbuf; + var x; + + xbuf = new Float32Array([ + 1.0, + 2.0, // 0 + 3.0, // 1 + 4.0, // 2 + 5.0 + ]); + x = new ndarray( 'float32', xbuf, [ 3 ], [ 1 ], 1, 'row-major' ); + expected = new Float32Array( [ 1.0, 5.0, 5.0, 5.0, 5.0 ] ); + + sfill( x, 5.0 ); + + t.deepEqual( x.data, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an ndarray having a length of `0`, the function returns the ndarray unchanged', function test( t ) { + var expected; + var x; + + x = array( new Float32Array( [] ) ); + expected = new Float32Array( [] ); + + sfill( x, 5.0 ); + + t.deepEqual( x.data, expected, 'returns expected value' ); + t.end(); +});