From 1f0d692b681405acc6d3bd475b6f2d3256131429 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Thu, 17 Sep 2026 23:18:05 +0500 Subject: [PATCH] feat: add blas/ext/base/ndarray/gfill-greater-than --- .../base/ndarray/gfill-greater-than/README.md | 149 ++++ .../gfill-greater-than/benchmark/benchmark.js | 124 ++++ .../ndarray/gfill-greater-than/docs/repl.txt | 46 ++ .../gfill-greater-than/docs/types/index.d.ts | 73 ++ .../gfill-greater-than/docs/types/test.ts | 82 +++ .../gfill-greater-than/examples/index.js | 47 ++ .../ndarray/gfill-greater-than/lib/index.js | 60 ++ .../ndarray/gfill-greater-than/lib/main.js | 107 +++ .../ndarray/gfill-greater-than/package.json | 70 ++ .../ndarray/gfill-greater-than/test/test.js | 638 ++++++++++++++++++ 10 files changed, 1396 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-greater-than/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-greater-than/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-greater-than/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-greater-than/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-greater-than/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-greater-than/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-greater-than/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-greater-than/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-greater-than/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-greater-than/test/test.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-greater-than/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-greater-than/README.md new file mode 100644 index 000000000000..766164291350 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-greater-than/README.md @@ -0,0 +1,149 @@ + + +# gfillGreaterThan + +> Replace elements in a one-dimensional ndarray greater than a provided search element with a specified scalar constant. + +
+ +
+ + + +
+ +## Usage + +```javascript +var gfillGreaterThan = require( '@stdlib/blas/ext/base/ndarray/gfill-greater-than' ); +``` + +#### gfillGreaterThan( arrays ) + +Replaces elements in a one-dimensional ndarray greater than 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( -3.0, { + 'dtype': 'generic' +}); + +var alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' +}); + +var start = scalar2ndarray( 0, { + 'dtype': 'generic' +}); + +var end = scalar2ndarray( 2, { + 'dtype': 'generic' +}); + +gfillGreaterThan( [ x, searchElement, alpha, start, end ] ); +// x => [ 5.0, 5.0, 3.0, 0.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. + - a zero-dimensional ndarray containing the starting index (inclusive). + - a zero-dimensional ndarray containing the ending index (exclusive). + +
+ + + +
+ +## Notes + +- The input ndarray is modified **in-place** (i.e., the input ndarray is **mutated**). +- If a specified `start` or `end` index is negative, the function resolves the respective index by counting backward from the last element (where `-1` refers to the last element). +- When comparing elements, the function uses the greater-than operator `>`. As a consequence, `NaN` values are never greater than any value, and `-0` and `+0` are considered equal. + +
+ + + +
+ +## 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 gfillGreaterThan = require( '@stdlib/blas/ext/base/ndarray/gfill-greater-than' ); + +var opts = { + 'dtype': 'generic' +}; + +var x = discreteUniform( [ 20 ], 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 ) ); + +var start = scalar2ndarray( 5, opts ); +console.log( 'Start Index: %d', ndarraylike2scalar( start ) ); + +var end = scalar2ndarray( 15, opts ); +console.log( 'End Index: %d', ndarraylike2scalar( end ) ); + +gfillGreaterThan( [ x, searchElement, alpha, start, end ] ); +console.log( ndarray2array( x ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-greater-than/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-greater-than/benchmark/benchmark.js new file mode 100644 index 000000000000..f8d73cd99f4f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-greater-than/benchmark/benchmark.js @@ -0,0 +1,124 @@ +/** +* @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 gfill = require( '@stdlib/blas/ext/base/gfill' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gfillGreaterThan = 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 start; + var xbuf; + var end; + var x; + + xbuf = uniform( len, -100.0, 0.0, options ); + gfill( len, 1.0, xbuf, 3 ); + x = vector( xbuf, options.dtype ); + searchElement = [ + scalar2ndarray( 0.0, options ), + scalar2ndarray( 1.0, options ) + ]; + alpha = [ + scalar2ndarray( 2.0, options ), + scalar2ndarray( 1.0, options ) + ]; + start = scalar2ndarray( 0, options ); + end = scalar2ndarray( len, 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 = gfillGreaterThan( [ x, searchElement[ i%2 ], alpha[ i%2 ], start, end ] ); // eslint-disable-line max-len + 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-greater-than/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-greater-than/docs/repl.txt new file mode 100644 index 000000000000..fdfa145002a8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-greater-than/docs/repl.txt @@ -0,0 +1,46 @@ + +{{alias}}( arrays ) + Replaces elements in a one-dimensional ndarray greater than a provided + search element with a specified scalar constant. + + The input ndarray is modified *in-place* (i.e., the input ndarray is + *mutated*). + + If a specified `start` or `end` index is negative, the function resolves + the respective index by counting backward from the last element (where `-1` + refers to the last element). + + When comparing elements, the function uses the greater-than operator `>`. + As a consequence, `NaN` values are never greater than any value, and `-0` + and `+0` are considered equal. + + 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. + - a zero-dimensional ndarray containing the starting index (inclusive). + - a zero-dimensional ndarray containing the ending index (exclusive). + + 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}}( -3.0, opts ); + > var alpha = {{alias:@stdlib/ndarray/from-scalar}}( 5.0, opts ); + > var st = {{alias:@stdlib/ndarray/from-scalar}}( 0, opts ); + > var en = {{alias:@stdlib/ndarray/from-scalar}}( 2, opts ); + > {{alias}}( [ x, v, alpha, st, en ] ) + [ 5.0, 5.0, 3.0, 0.0, 4.0, -6.0 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-greater-than/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-greater-than/docs/types/index.d.ts new file mode 100644 index 000000000000..8b9a2bc2da2c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-greater-than/docs/types/index.d.ts @@ -0,0 +1,73 @@ +/* +* @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 greater than 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. +* - a zero-dimensional ndarray containing the starting index (inclusive). +* - a zero-dimensional ndarray containing the ending index (exclusive). +* +* - When comparing elements, the function uses the greater-than operator `>`. As a consequence, `NaN` values are never greater than any value, and `-0` and `+0` are considered equal. +* +* @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( -3.0, { +* 'dtype': 'generic' +* }); +* +* var alpha = scalar2ndarray( 5.0, { +* 'dtype': 'generic' +* }); +* +* var start = scalar2ndarray( 0, { +* 'dtype': 'generic' +* }); +* +* var end = scalar2ndarray( 2, { +* 'dtype': 'generic' +* }); +* +* var out = gfillGreaterThan( [ x, searchElement, alpha, start, end ] ); +* // returns [ 5.0, 5.0, 3.0, 0.0, 4.0, -6.0 ] +*/ +declare function gfillGreaterThan = typedndarray>( arrays: [ T, typedndarray, typedndarray, typedndarray, typedndarray ] ): T; + + +// EXPORTS // + +export = gfillGreaterThan; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-greater-than/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-greater-than/docs/types/test.ts new file mode 100644 index 000000000000..bd2bd551a6d7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-greater-than/docs/types/test.ts @@ -0,0 +1,82 @@ +/* +* @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 gfillGreaterThan = 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' + }); + const start = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + const end = scalar2ndarray( 10, { + 'dtype': 'generic' + }); + + gfillGreaterThan( [ x, searchElement, alpha, start, end ] ); // $ExpectType genericndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + gfillGreaterThan( '10' ); // $ExpectError + gfillGreaterThan( 5 ); // $ExpectError + gfillGreaterThan( true ); // $ExpectError + gfillGreaterThan( false ); // $ExpectError + gfillGreaterThan( null ); // $ExpectError + gfillGreaterThan( undefined ); // $ExpectError + gfillGreaterThan( [] ); // $ExpectError + gfillGreaterThan( {} ); // $ExpectError + gfillGreaterThan( ( 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' + }); + const start = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + const end = scalar2ndarray( 10, { + 'dtype': 'generic' + }); + + gfillGreaterThan(); // $ExpectError + gfillGreaterThan( [ x, searchElement, alpha, start, end ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-greater-than/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-greater-than/examples/index.js new file mode 100644 index 000000000000..2a5420d74dcc --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-greater-than/examples/index.js @@ -0,0 +1,47 @@ +/** +* @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 gfillGreaterThan = require( './../lib' ); + +var opts = { + 'dtype': 'generic' +}; + +var x = discreteUniform( [ 20 ], 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 ) ); + +var start = scalar2ndarray( 5, opts ); +console.log( 'Start Index: %d', ndarraylike2scalar( start ) ); + +var end = scalar2ndarray( 15, opts ); +console.log( 'End Index: %d', ndarraylike2scalar( end ) ); + +gfillGreaterThan( [ x, searchElement, alpha, start, end ] ); +console.log( ndarray2array( x ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-greater-than/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-greater-than/lib/index.js new file mode 100644 index 000000000000..59d4822d9aa4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-greater-than/lib/index.js @@ -0,0 +1,60 @@ +/** +* @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 greater than a provided search element with a specified scalar constant. +* +* @module @stdlib/blas/ext/base/ndarray/gfill-greater-than +* +* @example +* var vector = require( '@stdlib/ndarray/vector/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var gfillGreaterThan = require( '@stdlib/blas/ext/base/ndarray/gfill-greater-than' ); +* +* var x = vector( [ 0.0, -2.0, 3.0, 0.0, 4.0, -6.0 ], 'generic' ); +* +* var searchElement = scalar2ndarray( -3.0, { +* 'dtype': 'generic' +* }); +* +* var alpha = scalar2ndarray( 5.0, { +* 'dtype': 'generic' +* }); +* +* var start = scalar2ndarray( 0, { +* 'dtype': 'generic' +* }); +* +* var end = scalar2ndarray( 2, { +* 'dtype': 'generic' +* }); +* +* var out = gfillGreaterThan( [ x, searchElement, alpha, start, end ] ); +* // returns [ 5.0, 5.0, 3.0, 0.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-greater-than/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-greater-than/lib/main.js new file mode 100644 index 000000000000..51ff5f5c5cd4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-greater-than/lib/main.js @@ -0,0 +1,107 @@ +/** +* @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 clipIndex = require( '@stdlib/ndarray/base/clip-index' ); +var getStride = require( '@stdlib/ndarray/base/stride' ); +var getOffset = require( '@stdlib/ndarray/base/offset' ); +var getData = require( '@stdlib/ndarray/base/data-buffer' ); +var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); +var strided = require( '@stdlib/blas/ext/base/gfill-greater-than' ).ndarray; + + +// MAIN // + +/** +* Replaces elements in a one-dimensional ndarray greater than 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. +* - a zero-dimensional ndarray containing the starting index (inclusive). +* - a zero-dimensional ndarray containing the ending index (exclusive). +* +* - When comparing elements, the function uses the greater-than operator `>`. As a consequence, `NaN` values are never greater than any value, and `-0` and `+0` are considered equal. +* +* @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( -3.0, { +* 'dtype': 'generic' +* }); +* +* var alpha = scalar2ndarray( 5.0, { +* 'dtype': 'generic' +* }); +* +* var start = scalar2ndarray( 0, { +* 'dtype': 'generic' +* }); +* +* var end = scalar2ndarray( 2, { +* 'dtype': 'generic' +* }); +* +* var out = gfillGreaterThan( [ x, searchElement, alpha, start, end ] ); +* // returns [ 5.0, 5.0, 3.0, 0.0, 4.0, -6.0 ] +*/ +function gfillGreaterThan( arrays ) { + var searchElement; + var stride; + var offset; + var alpha; + var start; + var end; + var N; + var x; + + x = arrays[ 0 ]; + searchElement = ndarraylike2scalar( arrays[ 1 ] ); + alpha = ndarraylike2scalar( arrays[ 2 ] ); + + N = numelDimension( x, 0 ); + start = clipIndex( ndarraylike2scalar( arrays[ 3 ] ), N ); + end = clipIndex( ndarraylike2scalar( arrays[ 4 ] ), N ); + if ( start >= end ) { + return x; + } + stride = getStride( x, 0 ); + offset = getOffset( x ) + ( stride*start ); + + strided( end-start, searchElement, alpha, getData( x ), stride, offset ); + return x; +} + + +// EXPORTS // + +module.exports = gfillGreaterThan; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-greater-than/package.json b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-greater-than/package.json new file mode 100644 index 000000000000..7059b841fb89 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-greater-than/package.json @@ -0,0 +1,70 @@ +{ + "name": "@stdlib/blas/ext/base/ndarray/gfill-greater-than", + "version": "0.0.0", + "description": "Replace elements in a one-dimensional ndarray greater than 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", + "greater-than", + "replace", + "assign", + "set", + "strided", + "array", + "ndarray", + "generic" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-greater-than/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-greater-than/test/test.js new file mode 100644 index 000000000000..d6cf10e3ebd7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill-greater-than/test/test.js @@ -0,0 +1,638 @@ +/** +* @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 isSameArray = require( '@stdlib/assert/is-same-array' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var gfillGreaterThan = 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 gfillGreaterThan, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function replaces elements greater than a provided search element', function test( t ) { + var searchElement; + var expected; + var actual; + var alpha; + var start; + var xbuf; + var end; + var x; + + xbuf = [ 0.0, -2.0, 3.0, 0.0, 4.0, -6.0 ]; + x = vector( xbuf, 6, 1, 0 ); + searchElement = scalar2ndarray( 2.0, { + 'dtype': 'generic' + }); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); + start = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + end = scalar2ndarray( 6, { + 'dtype': 'generic' + }); + + actual = gfillGreaterThan( [ x, searchElement, alpha, start, end ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = [ 0.0, -2.0, 5.0, 0.0, 5.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 start; + var xbuf; + var end; + var x; + + xbuf = [ 0.0, -2.0, 3.0, 0.0, 4.0, -6.0 ]; + x = vector( xbuf, 3, 2, 0 ); + searchElement = scalar2ndarray( 2.0, { + 'dtype': 'generic' + }); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); + start = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + end = scalar2ndarray( 3, { + 'dtype': 'generic' + }); + + actual = gfillGreaterThan( [ x, searchElement, alpha, start, end ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = [ 0.0, -2.0, 5.0, 0.0, 5.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 start; + var xbuf; + var end; + var x; + + xbuf = [ 0.0, -2.0, 3.0, 0.0, 4.0, -6.0 ]; + x = vector( xbuf, 3, -2, 4 ); + searchElement = scalar2ndarray( 2.0, { + 'dtype': 'generic' + }); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); + start = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + end = scalar2ndarray( 3, { + 'dtype': 'generic' + }); + + actual = gfillGreaterThan( [ x, searchElement, alpha, start, end ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = [ 0.0, -2.0, 5.0, 0.0, 5.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 start; + var xbuf; + var end; + var x; + + xbuf = [ 0.0, -2.0, 3.0, 0.0, 4.0, -6.0 ]; + x = vector( xbuf, 3, 1, 3 ); + searchElement = scalar2ndarray( 2.0, { + 'dtype': 'generic' + }); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); + start = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + end = scalar2ndarray( 3, { + 'dtype': 'generic' + }); + + actual = gfillGreaterThan( [ x, searchElement, alpha, start, end ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = [ 0.0, -2.0, 3.0, 0.0, 5.0, -6.0 ]; + t.deepEqual( xbuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a nonnegative starting index', function test( t ) { + var searchElement; + var expected; + var actual; + var alpha; + var start; + var xbuf; + var end; + var x; + + xbuf = [ 0.0, 0.0, 0.0, 0.0 ]; + x = vector( xbuf, 4, 1, 0 ); + searchElement = scalar2ndarray( -1.0, { + 'dtype': 'generic' + }); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); + start = scalar2ndarray( 1, { + 'dtype': 'generic' + }); + end = scalar2ndarray( 4, { + 'dtype': 'generic' + }); + + actual = gfillGreaterThan( [ x, searchElement, alpha, start, end ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = [ 0.0, 5.0, 5.0, 5.0 ]; + t.deepEqual( xbuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a negative starting index', function test( t ) { + var searchElement; + var expected; + var actual; + var alpha; + var start; + var xbuf; + var end; + var x; + + xbuf = [ 0.0, 0.0, 0.0, 0.0 ]; + x = vector( xbuf, 4, 1, 0 ); + searchElement = scalar2ndarray( -1.0, { + 'dtype': 'generic' + }); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); + start = scalar2ndarray( -3, { + 'dtype': 'generic' + }); + end = scalar2ndarray( 4, { + 'dtype': 'generic' + }); + + actual = gfillGreaterThan( [ x, searchElement, alpha, start, end ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = [ 0.0, 5.0, 5.0, 5.0 ]; + t.deepEqual( xbuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a nonnegative ending index', function test( t ) { + var searchElement; + var expected; + var actual; + var alpha; + var start; + var xbuf; + var end; + var x; + + xbuf = [ 0.0, 0.0, 0.0, 0.0 ]; + x = vector( xbuf, 4, 1, 0 ); + searchElement = scalar2ndarray( -1.0, { + 'dtype': 'generic' + }); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); + start = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + end = scalar2ndarray( 3, { + 'dtype': 'generic' + }); + + actual = gfillGreaterThan( [ x, searchElement, alpha, start, end ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = [ 5.0, 5.0, 5.0, 0.0 ]; + t.deepEqual( xbuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a negative ending index', function test( t ) { + var searchElement; + var expected; + var actual; + var alpha; + var start; + var xbuf; + var end; + var x; + + xbuf = [ 0.0, 0.0, 0.0, 0.0 ]; + x = vector( xbuf, 4, 1, 0 ); + searchElement = scalar2ndarray( -1.0, { + 'dtype': 'generic' + }); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); + start = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + end = scalar2ndarray( -1, { + 'dtype': 'generic' + }); + + actual = gfillGreaterThan( [ x, searchElement, alpha, start, end ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = [ 5.0, 5.0, 5.0, 0.0 ]; + t.deepEqual( xbuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function clamps out-of-bounds starting and ending indices', function test( t ) { + var searchElement; + var expected; + var actual; + var alpha; + var start; + var xbuf; + var end; + var x; + + xbuf = [ 0.0, 0.0, 0.0, 0.0 ]; + x = vector( xbuf, 4, 1, 0 ); + searchElement = scalar2ndarray( -1.0, { + 'dtype': 'generic' + }); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); + start = scalar2ndarray( -10, { + 'dtype': 'generic' + }); + end = scalar2ndarray( 10, { + 'dtype': 'generic' + }); + + actual = gfillGreaterThan( [ x, searchElement, alpha, start, end ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = [ 5.0, 5.0, 5.0, 5.0 ]; + t.deepEqual( xbuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if a resolved starting index is greater than or equal to a resolved ending index, the function returns the input ndarray unchanged', function test( t ) { + var searchElement; + var expected; + var actual; + var alpha; + var start; + var xbuf; + var end; + var x; + + xbuf = [ 0.0, 0.0, 0.0, 0.0 ]; + x = vector( xbuf, 4, 1, 0 ); + searchElement = scalar2ndarray( -1.0, { + 'dtype': 'generic' + }); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); + expected = [ 0.0, 0.0, 0.0, 0.0 ]; + + start = scalar2ndarray( 2, { + 'dtype': 'generic' + }); + end = scalar2ndarray( 2, { + 'dtype': 'generic' + }); + actual = gfillGreaterThan( [ x, searchElement, alpha, start, end ] ); + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( xbuf, expected, 'returns expected value' ); + + start = scalar2ndarray( 3, { + 'dtype': 'generic' + }); + end = scalar2ndarray( 1, { + 'dtype': 'generic' + }); + actual = gfillGreaterThan( [ x, searchElement, alpha, start, end ] ); + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( xbuf, expected, 'returns expected value' ); + + start = scalar2ndarray( 5, { + 'dtype': 'generic' + }); + end = scalar2ndarray( 4, { + 'dtype': 'generic' + }); + actual = gfillGreaterThan( [ x, searchElement, alpha, start, end ] ); + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( xbuf, expected, 'returns expected value' ); + + start = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + end = scalar2ndarray( -10, { + 'dtype': 'generic' + }); + actual = gfillGreaterThan( [ x, searchElement, alpha, start, end ] ); + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( xbuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a fill range for an input ndarray having a non-unit stride', function test( t ) { + var searchElement; + var expected; + var actual; + var alpha; + var start; + var xbuf; + var end; + var x; + + xbuf = [ 0.0, -2.0, 0.0, 4.0 ]; + x = vector( xbuf, 2, 2, 0 ); + searchElement = scalar2ndarray( -1.0, { + 'dtype': 'generic' + }); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); + start = scalar2ndarray( 1, { + 'dtype': 'generic' + }); + end = scalar2ndarray( 2, { + 'dtype': 'generic' + }); + + actual = gfillGreaterThan( [ x, searchElement, alpha, start, end ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = [ 0.0, -2.0, 5.0, 4.0 ]; + t.deepEqual( xbuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if all elements are not greater than a provided search element, the function returns the input ndarray unchanged', function test( t ) { + var searchElement; + var expected; + var actual; + var alpha; + var start; + var xbuf; + var end; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = vector( xbuf, 4, 1, 0 ); + searchElement = scalar2ndarray( 4.0, { + 'dtype': 'generic' + }); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); + start = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + end = scalar2ndarray( 4, { + 'dtype': 'generic' + }); + + actual = gfillGreaterThan( [ x, searchElement, alpha, start, end ] ); + 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 expected; + var actual; + var alpha; + var start; + var xbuf; + var end; + var x; + + xbuf = [ NaN, 1.0, NaN ]; + x = vector( xbuf, 3, 1, 0 ); + searchElement = scalar2ndarray( NaN, { + 'dtype': 'generic' + }); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); + start = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + end = scalar2ndarray( 3, { + 'dtype': 'generic' + }); + + actual = gfillGreaterThan( [ x, searchElement, alpha, start, end ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = [ NaN, 1.0, NaN ]; + t.strictEqual( isSameArray( xbuf, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function does not replace `NaN` elements', function test( t ) { + var searchElement; + var expected; + var actual; + var alpha; + var start; + var xbuf; + var end; + var x; + + xbuf = [ NaN, 1.0, NaN ]; + x = vector( xbuf, 3, 1, 0 ); + searchElement = scalar2ndarray( 0.0, { + 'dtype': 'generic' + }); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); + start = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + end = scalar2ndarray( 3, { + 'dtype': 'generic' + }); + + actual = gfillGreaterThan( [ x, searchElement, alpha, start, end ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = [ NaN, 5.0, NaN ]; + t.strictEqual( isSameArray( xbuf, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function considers `-0` and `+0` to be equal', function test( t ) { + var searchElement; + var expected; + var actual; + var alpha; + var start; + var xbuf; + var end; + 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' + }); + start = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + end = scalar2ndarray( 4, { + 'dtype': 'generic' + }); + + actual = gfillGreaterThan( [ x, searchElement, alpha, start, end ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = [ -0.0, 5.0, 0.0, -0.0 ]; + t.strictEqual( isSameArray( xbuf, expected ), true, '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 = gfillGreaterThan( [ x, searchElement, alpha, start, end ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = [ -0.0, 5.0, 0.0, -0.0 ]; + t.strictEqual( isSameArray( xbuf, expected ), true, '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 start; + var xbuf; + var end; + var x; + + xbuf = []; + x = vector( xbuf, 0, 1, 0 ); + searchElement = scalar2ndarray( 0.0, { + 'dtype': 'generic' + }); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); + start = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + end = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + + actual = gfillGreaterThan( [ x, searchElement, alpha, start, end ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = []; + t.deepEqual( xbuf, expected, 'returns expected value' ); + + t.end(); +});