From bd10587b787bc1f2c95db7f97ad34ed11f2e1595 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sun, 19 Jul 2026 23:16:36 +0500 Subject: [PATCH] feat: add blas/ext/base/ndarray/gfill-equal --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../ext/base/ndarray/gfill-equal/README.md | 132 ++++++++ .../gfill-equal/benchmark/benchmark.js | 116 +++++++ .../base/ndarray/gfill-equal/docs/repl.txt | 38 +++ .../ndarray/gfill-equal/docs/types/index.d.ts | 63 ++++ .../ndarray/gfill-equal/docs/types/test.ts | 70 ++++ .../ndarray/gfill-equal/examples/index.js | 41 +++ .../ext/base/ndarray/gfill-equal/lib/index.js | 52 +++ .../ext/base/ndarray/gfill-equal/lib/main.js | 81 +++++ .../ext/base/ndarray/gfill-equal/package.json | 70 ++++ .../ext/base/ndarray/gfill-equal/test/test.js | 298 ++++++++++++++++++ 10 files changed, 961 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-equal/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-equal/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-equal/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-equal/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-equal/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-equal/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-equal/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-equal/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-equal/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-equal/test/test.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-equal/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-equal/README.md new file mode 100644 index 000000000000..c27031a8f5ec --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-equal/README.md @@ -0,0 +1,132 @@ + + +# gfillEqual + +> Replace elements in a one-dimensional ndarray equal to a provided search element with a specified scalar constant. + +
+ +
+ + + +
+ +## Usage + +```javascript +var gfillEqual = require( '@stdlib/blas/ext/base/ndarray/gfill-equal' ); +``` + +#### gfillEqual( arrays ) + +Replaces elements in a one-dimensional ndarray equal to a provided search element with a specified scalar constant. + +```javascript +var vector = require( '@stdlib/ndarray/vector/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); + +var x = vector( [ 0.0, -2.0, 3.0, 0.0, 4.0, -6.0 ], 'generic' ); + +var searchElement = scalar2ndarray( 0.0, { + 'dtype': 'generic' +}); + +var alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' +}); + +gfillEqual( [ x, searchElement, alpha ] ); +// x => [ 5.0, -2.0, 3.0, 5.0, 4.0, -6.0 ] +``` + +The function has the following parameters: + +- **arrays**: array-like object containing the following ndarrays: + + - a one-dimensional input ndarray. + - a zero-dimensional ndarray containing the search element. + - a zero-dimensional ndarray containing the scalar constant. + +
+ + + +
+ +## Notes + +- The input ndarray is modified **in-place** (i.e., the input ndarray is **mutated**). +- When comparing elements, the function checks for equality using the strict equality operator `===`. As a consequence, `NaN` values are considered distinct, and `-0` and `+0` are considered the same. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/discrete-uniform' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarraylike2scalar = require( '@stdlib/ndarray/ndarraylike2scalar' ); +var gfillEqual = require( '@stdlib/blas/ext/base/ndarray/gfill-equal' ); + +var opts = { + 'dtype': 'generic' +}; + +var x = discreteUniform( [ 10 ], 0, 3, opts ); +console.log( ndarray2array( x ) ); + +var searchElement = scalar2ndarray( 1, opts ); +console.log( 'Search Element: %d', ndarraylike2scalar( searchElement ) ); + +var alpha = scalar2ndarray( 5, opts ); +console.log( 'Alpha: %d', ndarraylike2scalar( alpha ) ); + +gfillEqual( [ x, searchElement, alpha ] ); +console.log( ndarray2array( x ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-equal/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-equal/benchmark/benchmark.js new file mode 100644 index 000000000000..5448ec3c4709 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-equal/benchmark/benchmark.js @@ -0,0 +1,116 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 vector = require( '@stdlib/ndarray/vector/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gfillEqual = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var searchElement; + var alpha; + var xbuf; + var x; + var i; + + xbuf = uniform( len, -100.0, 100.0, options ); + for ( i = 0; i < len; i += 3 ) { + xbuf[ i ] = 0.0; + } + x = vector( xbuf, options.dtype ); + searchElement = scalar2ndarray( 0.0, options ); + alpha = scalar2ndarray( 5.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = gfillEqual( [ x, searchElement, alpha ] ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( typeof out !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + 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( format( '%s:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-equal/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-equal/docs/repl.txt new file mode 100644 index 000000000000..0557ba58b0f2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-equal/docs/repl.txt @@ -0,0 +1,38 @@ + +{{alias}}( arrays ) + Replaces elements in a one-dimensional ndarray equal to a provided search + element with a specified scalar constant. + + The input ndarray is modified *in-place* (i.e., the input ndarray is + *mutated*). + + When comparing elements, the function checks for equality using the strict + equality operator `===`. As a consequence, `NaN` values are considered + distinct, and `-0` and `+0` are considered the same. + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing the following ndarrays: + + - a one-dimensional input ndarray. + - a zero-dimensional ndarray containing the search element. + - a zero-dimensional ndarray containing the scalar constant. + + Returns + ------- + out: ndarray + Input ndarray. + + Examples + -------- + > var buf = [ 0.0, -2.0, 3.0, 0.0, 4.0, -6.0 ]; + > var x = {{alias:@stdlib/ndarray/vector/ctor}}( buf, 'generic' ); + > var opts = { 'dtype': 'generic' }; + > var v = {{alias:@stdlib/ndarray/from-scalar}}( 0.0, opts ); + > var alpha = {{alias:@stdlib/ndarray/from-scalar}}( 5.0, opts ); + > {{alias}}( [ x, v, alpha ] ) + [ 5.0, -2.0, 3.0, 5.0, 4.0, -6.0 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-equal/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-equal/docs/types/index.d.ts new file mode 100644 index 000000000000..37e96efd59db --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-equal/docs/types/index.d.ts @@ -0,0 +1,63 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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'; + +/** +* Replaces elements in a one-dimensional ndarray equal to a provided search element with a specified scalar constant. +* +* ## Notes +* +* - The function expects the following ndarrays: +* +* - a one-dimensional input ndarray. +* - a zero-dimensional ndarray containing the search element. +* - a zero-dimensional ndarray containing the scalar constant. +* +* - When comparing elements, the function checks for equality using the strict equality operator `===`. As a consequence, `NaN` values are considered distinct, and `-0` and `+0` are considered the same. +* +* @param arrays - array-like object containing ndarrays +* @returns input ndarray +* +* @example +* var vector = require( '@stdlib/ndarray/vector/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* +* var x = vector( [ 0.0, -2.0, 3.0, 0.0, 4.0, -6.0 ], 'generic' ); +* +* var searchElement = scalar2ndarray( 0.0, { +* 'dtype': 'generic' +* }); +* +* var alpha = scalar2ndarray( 5.0, { +* 'dtype': 'generic' +* }); +* +* var out = gfillEqual( [ x, searchElement, alpha ] ); +* // returns [ 5.0, -2.0, 3.0, 5.0, 4.0, -6.0 ] +*/ +declare function gfillEqual = typedndarray>( arrays: [ T, typedndarray, typedndarray ] ): T; + + +// EXPORTS // + +export = gfillEqual; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-equal/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-equal/docs/types/test.ts new file mode 100644 index 000000000000..3843a417908d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-equal/docs/types/test.ts @@ -0,0 +1,70 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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 scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +import gfillEqual = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 10 ], { + 'dtype': 'generic' + }); + const searchElement = scalar2ndarray( 0.0, { + 'dtype': 'generic' + }); + const alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); + + gfillEqual( [ x, searchElement, alpha ] ); // $ExpectType genericndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + gfillEqual( '10' ); // $ExpectError + gfillEqual( 5 ); // $ExpectError + gfillEqual( true ); // $ExpectError + gfillEqual( false ); // $ExpectError + gfillEqual( null ); // $ExpectError + gfillEqual( undefined ); // $ExpectError + gfillEqual( [] ); // $ExpectError + gfillEqual( {} ); // $ExpectError + gfillEqual( ( 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': 'generic' + }); + const searchElement = scalar2ndarray( 0.0, { + 'dtype': 'generic' + }); + const alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); + + gfillEqual(); // $ExpectError + gfillEqual( [ x, searchElement, alpha ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-equal/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-equal/examples/index.js new file mode 100644 index 000000000000..7736f2f26f0d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-equal/examples/index.js @@ -0,0 +1,41 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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/discrete-uniform' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarraylike2scalar = require( '@stdlib/ndarray/ndarraylike2scalar' ); +var gfillEqual = require( './../lib' ); + +var opts = { + 'dtype': 'generic' +}; + +var x = discreteUniform( [ 10 ], 0, 3, opts ); +console.log( ndarray2array( x ) ); + +var searchElement = scalar2ndarray( 1, opts ); +console.log( 'Search Element: %d', ndarraylike2scalar( searchElement ) ); + +var alpha = scalar2ndarray( 5, opts ); +console.log( 'Alpha: %d', ndarraylike2scalar( alpha ) ); + +gfillEqual( [ x, searchElement, alpha ] ); +console.log( ndarray2array( x ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-equal/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-equal/lib/index.js new file mode 100644 index 000000000000..71f744bbdfdc --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-equal/lib/index.js @@ -0,0 +1,52 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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'; + +/** +* Replace elements in a one-dimensional ndarray equal to a provided search element with a specified scalar constant. +* +* @module @stdlib/blas/ext/base/ndarray/gfill-equal +* +* @example +* var vector = require( '@stdlib/ndarray/vector/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var gfillEqual = require( '@stdlib/blas/ext/base/ndarray/gfill-equal' ); +* +* var x = vector( [ 0.0, -2.0, 3.0, 0.0, 4.0, -6.0 ], 'generic' ); +* +* var searchElement = scalar2ndarray( 0.0, { +* 'dtype': 'generic' +* }); +* +* var alpha = scalar2ndarray( 5.0, { +* 'dtype': 'generic' +* }); +* +* var out = gfillEqual( [ x, searchElement, alpha ] ); +* // returns [ 5.0, -2.0, 3.0, 5.0, 4.0, -6.0 ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-equal/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-equal/lib/main.js new file mode 100644 index 000000000000..1851af13a766 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-equal/lib/main.js @@ -0,0 +1,81 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-equal' ).ndarray; +var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); + + +// MAIN // + +/** +* Replaces elements in a one-dimensional ndarray equal to a provided search element with a specified scalar constant. +* +* ## Notes +* +* - The function expects the following ndarrays: +* +* - a one-dimensional input ndarray. +* - a zero-dimensional ndarray containing the search element. +* - a zero-dimensional ndarray containing the scalar constant. +* +* - When comparing elements, the function checks for equality using the strict equality operator `===`. As a consequence, `NaN` values are considered distinct, and `-0` and `+0` are considered the same. +* +* @param {ArrayLikeObject} arrays - array-like object containing ndarrays +* @returns {ndarray} input ndarray +* +* @example +* var vector = require( '@stdlib/ndarray/vector/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* +* var x = vector( [ 0.0, -2.0, 3.0, 0.0, 4.0, -6.0 ], 'generic' ); +* +* var searchElement = scalar2ndarray( 0.0, { +* 'dtype': 'generic' +* }); +* +* var alpha = scalar2ndarray( 5.0, { +* 'dtype': 'generic' +* }); +* +* var out = gfillEqual( [ x, searchElement, alpha ] ); +* // returns [ 5.0, -2.0, 3.0, 5.0, 4.0, -6.0 ] +*/ +function gfillEqual( arrays ) { + var searchElement; + var alpha; + var x; + + x = arrays[ 0 ]; + searchElement = ndarraylike2scalar( arrays[ 1 ] ); + alpha = ndarraylike2scalar( arrays[ 2 ] ); + strided( numelDimension( x, 0 ), searchElement, alpha, getData( x ), getStride( x, 0 ), getOffset( x ) ); // eslint-disable-line max-len + return x; +} + + +// EXPORTS // + +module.exports = gfillEqual; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-equal/package.json b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-equal/package.json new file mode 100644 index 000000000000..02fd0cf98902 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-equal/package.json @@ -0,0 +1,70 @@ +{ + "name": "@stdlib/blas/ext/base/ndarray/gfill-equal", + "version": "0.0.0", + "description": "Replace elements in a one-dimensional ndarray equal to a provided search element 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", + "stdmath", + "mathematics", + "math", + "blas", + "extended", + "ext", + "fill", + "equal", + "replace", + "assign", + "set", + "strided", + "array", + "ndarray", + "generic" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-equal/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-equal/test/test.js new file mode 100644 index 000000000000..66f5d8244118 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-equal/test/test.js @@ -0,0 +1,298 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var gfillEqual = 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 gfillEqual, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function replaces elements equal to a provided search element', function test( t ) { + var searchElement; + var expected; + var actual; + var alpha; + var xbuf; + var x; + + xbuf = [ 0.0, -2.0, 3.0, 0.0, 4.0, -6.0 ]; + x = vector( xbuf, 6, 1, 0 ); + searchElement = scalar2ndarray( 0.0, { + 'dtype': 'generic' + }); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); + + actual = gfillEqual( [ x, searchElement, alpha ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = [ 5.0, -2.0, 3.0, 5.0, 4.0, -6.0 ]; + t.deepEqual( xbuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an input ndarray having a non-unit stride', function test( t ) { + var searchElement; + var expected; + var actual; + var alpha; + var xbuf; + var x; + + xbuf = [ 0.0, -2.0, 3.0, 0.0, 4.0, -6.0 ]; + x = vector( xbuf, 3, 2, 0 ); + searchElement = scalar2ndarray( 0.0, { + 'dtype': 'generic' + }); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); + + actual = gfillEqual( [ x, searchElement, alpha ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = [ 5.0, -2.0, 3.0, 0.0, 4.0, -6.0 ]; + t.deepEqual( xbuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an input ndarray having a negative stride', function test( t ) { + var searchElement; + var expected; + var actual; + var alpha; + var xbuf; + var x; + + xbuf = [ 0.0, -2.0, 3.0, 0.0, 4.0, -6.0 ]; + x = vector( xbuf, 3, -2, 4 ); + searchElement = scalar2ndarray( 0.0, { + 'dtype': 'generic' + }); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); + + actual = gfillEqual( [ x, searchElement, alpha ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = [ 5.0, -2.0, 3.0, 0.0, 4.0, -6.0 ]; + t.deepEqual( xbuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an input ndarray having a non-zero offset', function test( t ) { + var searchElement; + var expected; + var actual; + var alpha; + var xbuf; + var x; + + xbuf = [ 0.0, -2.0, 3.0, 0.0, 4.0, -6.0 ]; + x = vector( xbuf, 3, 1, 3 ); + searchElement = scalar2ndarray( 0.0, { + 'dtype': 'generic' + }); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); + + actual = gfillEqual( [ x, searchElement, alpha ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = [ 0.0, -2.0, 3.0, 5.0, 4.0, -6.0 ]; + t.deepEqual( xbuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if all elements are not equal to a provided search element, the function returns the input ndarray unchanged', function test( t ) { + var searchElement; + var expected; + var actual; + var alpha; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = vector( xbuf, 4, 1, 0 ); + searchElement = scalar2ndarray( 0.0, { + 'dtype': 'generic' + }); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); + + actual = gfillEqual( [ x, searchElement, alpha ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = [ 1.0, 2.0, 3.0, 4.0 ]; + t.deepEqual( xbuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a search element equal to `NaN`, the function returns the input ndarray unchanged', function test( t ) { + var searchElement; + var actual; + var alpha; + var xbuf; + var x; + + xbuf = [ NaN, 1.0, NaN ]; + x = vector( xbuf, 3, 1, 0 ); + searchElement = scalar2ndarray( NaN, { + 'dtype': 'generic' + }); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); + + actual = gfillEqual( [ x, searchElement, alpha ] ); + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( isnan( xbuf[ 0 ] ), true, 'first element is NaN' ); + t.strictEqual( xbuf[ 1 ], 1.0, 'second element is 1.0' ); + t.strictEqual( isnan( xbuf[ 2 ] ), true, 'third element is NaN' ); + + t.end(); +}); + +tape( 'the function does not replace `NaN` elements', function test( t ) { + var searchElement; + var actual; + var alpha; + var xbuf; + var x; + + xbuf = [ NaN, 0.0, NaN ]; + x = vector( xbuf, 3, 1, 0 ); + searchElement = scalar2ndarray( 0.0, { + 'dtype': 'generic' + }); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); + + actual = gfillEqual( [ x, searchElement, alpha ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + t.strictEqual( isnan( xbuf[ 0 ] ), true, 'first element is NaN' ); + t.strictEqual( xbuf[ 1 ], 5.0, 'second element is 5.0' ); + t.strictEqual( isnan( xbuf[ 2 ] ), true, 'third element is NaN' ); + + t.end(); +}); + +tape( 'the function considers `-0` and `+0` to be the same value', function test( t ) { + var searchElement; + var expected; + var actual; + var alpha; + var xbuf; + var x; + + xbuf = [ -0.0, 1.0, 0.0, -0.0 ]; + x = vector( xbuf, 4, 1, 0 ); + searchElement = scalar2ndarray( 0.0, { + 'dtype': 'generic' + }); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); + + actual = gfillEqual( [ x, searchElement, alpha ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = [ 5.0, 1.0, 5.0, 5.0 ]; + t.deepEqual( xbuf, expected, 'returns expected value' ); + + xbuf = [ -0.0, 1.0, 0.0, -0.0 ]; + x = vector( xbuf, 4, 1, 0 ); + searchElement = scalar2ndarray( -0.0, { + 'dtype': 'generic' + }); + + actual = gfillEqual( [ x, searchElement, alpha ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = [ 5.0, 1.0, 5.0, 5.0 ]; + t.deepEqual( xbuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the input ndarray unchanged when the input ndarray is empty', function test( t ) { + var searchElement; + var expected; + var actual; + var alpha; + var xbuf; + var x; + + xbuf = []; + x = vector( xbuf, 0, 1, 0 ); + searchElement = scalar2ndarray( 0.0, { + 'dtype': 'generic' + }); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); + + actual = gfillEqual( [ x, searchElement, alpha ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = []; + t.deepEqual( xbuf, expected, 'returns expected value' ); + + t.end(); +});