diff --git a/lib/node_modules/@stdlib/blas/ext/base/grescale/README.md b/lib/node_modules/@stdlib/blas/ext/base/grescale/README.md new file mode 100644 index 000000000000..5736188f55cc --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/grescale/README.md @@ -0,0 +1,189 @@ + + +# grescale + +> Rescale each element in a strided array from one range to another and assign the results to a strided array `y`. + +
+ + + +```math +\mathbf{y} = c + \frac{\mathbf{x} - a}{b - a} \cdot (d - c) +``` + + + +
+ + + +
+ +## Usage + +```javascript +var grescale = require( '@stdlib/blas/ext/base/grescale' ); +``` + +#### grescale( N, a, b, c, d, x, strideX, y, strideY ) + +Rescales each element in a strided array from the range `[a, b]` to the range `[c, d]` and assigns the results to a strided array `y`. + +```javascript +var x = [ 1.0, 3.0, 5.0, 7.0, 9.0 ]; +var y = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + +grescale( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, y, 1 ); +// y => [ 2.0, 3.0, 4.0, 5.0, 6.0 ] +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **a**: lower bound of the input range. +- **b**: upper bound of the input range. +- **c**: lower bound of the output range. +- **d**: upper bound of the output range. +- **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. +- **strideX**: stride length for `x`. +- **y**: output [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. +- **strideY**: stride length for `y`. + +The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to rescale every other element in `x` and assign the results to every other element in `y`: + +```javascript +var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +var y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + +grescale( 3, 1.0, 9.0, 2.0, 6.0, x, 2, y, 2 ); +// y => [ 2.0, 0.0, 3.0, 0.0, 4.0, 0.0 ] +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +// Initial arrays... +var x0 = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var y0 = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + +// Create offset views... +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element +var y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*2 ); // start at 3rd element + +grescale( 3, 1.0, 9.0, 2.0, 6.0, x1, 1, y1, 1 ); +// y0 => [ 0.0, 0.0, 2.5, 3.0, 3.5, 0.0 ] +``` + +#### grescale.ndarray( N, a, b, c, d, x, strideX, offsetX, y, strideY, offsetY ) + +Rescales each element in a strided array from the range `[a, b]` to the range `[c, d]` and assigns the results to a strided array `y` using alternative indexing semantics. + +```javascript +var x = [ 1.0, 3.0, 5.0, 7.0, 9.0 ]; +var y = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + +grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, 0, y, 1, 0 ); +// y => [ 2.0, 3.0, 4.0, 5.0, 6.0 ] +``` + +The function has the following additional parameters: + +- **offsetX**: starting index for `x`. +- **offsetY**: starting index for `y`. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example, to rescale and assign to the last three elements of `y`: + +```javascript +var x = [ 1.0, 3.0, 5.0, 7.0, 9.0 ]; +var y = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + +grescale.ndarray( 3, 1.0, 9.0, 2.0, 6.0, x, 1, x.length-3, y, 1, y.length-3 ); +// y => [ 0.0, 0.0, 4.0, 5.0, 6.0 ] +``` + +
+ + + +
+ +## Notes + +- If `N <= 0`, both functions return `y` unchanged. +- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var logEach = require( '@stdlib/console/log-each' ); +var grescale = require( '@stdlib/blas/ext/base/grescale' ); + +var opts = { + 'dtype': 'float64' +}; +var x = discreteUniform( 10, -100, 100, opts ); +var y = discreteUniform( 10, -100, 100, opts ); + +grescale( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, y, 1 ); +logEach( '2.0 + (%d - 1.0) * 4.0 / 8.0 = %0.4f', x, y ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/grescale/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/grescale/benchmark/benchmark.js new file mode 100644 index 000000000000..ded9f1b17c6d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/grescale/benchmark/benchmark.js @@ -0,0 +1,104 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var grescale = require( './../lib/main.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Create a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -100.0, 100.0, options ); + var y = uniform( len, -100.0, 100.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var z; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = grescale( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, y, 1 ); + if ( isnan( z[ i%x.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( z[ i%x.length ] ) ) { + b.fail( 'should not return NaN' ); + } + 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/grescale/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/grescale/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..9a43e2003b0e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/grescale/benchmark/benchmark.ndarray.js @@ -0,0 +1,104 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var grescale = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Create a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -100.0, 100.0, options ); + var y = uniform( len, -100.0, 100.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var z; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = grescale( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, 0, y, 1, 0 ); + if ( isnan( z[ i%x.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( z[ i%x.length ] ) ) { + b.fail( 'should not return NaN' ); + } + 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:ndarray:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/grescale/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/grescale/docs/repl.txt new file mode 100644 index 000000000000..2b0f2be18430 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/grescale/docs/repl.txt @@ -0,0 +1,141 @@ + +{{alias}}( N, a, b, c, d, x, strideX, y, strideY ) + Rescales each element in a strided array from the range [a, b] to the range + [c, d] and assigns the results to a strided array `y`. + + The `N` and stride parameters determine which elements in the strided arrays + are accessed at runtime. + + Indexing is relative to the first index. To introduce an offset, use typed + array views. + + If `N <= 0`, the function returns `y` unchanged. + + Parameters + ---------- + N: integer + Number of indexed elements. + + a: number + Lower bound of the input range. + + b: number + Upper bound of the input range. + + c: number + Lower bound of the output range. + + d: number + Upper bound of the output range. + + x: Array|TypedArray + Input array. + + strideX: integer + Stride length for `x`. + + y: Array|TypedArray + Output array. + + strideY: integer + Stride length for `y`. + + Returns + ------- + y: Array|TypedArray + Output array. + + Examples + -------- + // Standard Usage: + > var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; + > var y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, y, 1 ) + [ 0.5, 2.0, 3.0, -1.0, 3.5, 1.5, 1.0, 0.0 ] + + // Using `N` and stride parameters: + > x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; + > y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}( 4, 1.0, 9.0, 2.0, 6.0, x, 2, y, 2 ) + [ 0.5, 0.0, 3.0, 0.0, 3.5, 0.0, 1.0, 0.0 ] + + // Using view offsets: + > var bufX = [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ]; + > var bufY = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + > var x0 = new {{alias:@stdlib/array/float64}}( bufX ); + > var y0 = new {{alias:@stdlib/array/float64}}( bufY ); + > var offsetX = x0.BYTES_PER_ELEMENT * 1; + > var offsetY = y0.BYTES_PER_ELEMENT * 1; + > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, offsetX ); + > var y1 = new {{alias:@stdlib/array/float64}}( y0.buffer, offsetY ); + > {{alias}}( 3, 1.0, 9.0, 2.0, 6.0, x1, 2, y1, 2 ) + [ 0.5, 0.0, -0.5, 0.0, -1.5 ] + > y0 + [ 0.0, 0.5, 0.0, -0.5, 0.0, -1.5 ] + + +{{alias}}.ndarray( N, a, b, c, d, x, strideX, offsetX, y, strideY, offsetY ) + Rescales each element in a strided array from the range [a, b] to the range + [c, d] and assigns the results to a strided array `y` using alternative + indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameters support indexing semantics based on starting + indices. + + Parameters + ---------- + N: integer + Number of indexed elements. + + a: number + Lower bound of the input range. + + b: number + Upper bound of the input range. + + c: number + Lower bound of the output range. + + d: number + Upper bound of the output range. + + x: Array|TypedArray + Input array. + + strideX: integer + Stride length for `x`. + + offsetX: integer + Starting index for `x`. + + y: Array|TypedArray + Output array. + + strideY: integer + Stride length for `y`. + + offsetY: integer + Starting index for `y`. + + Returns + ------- + y: Array|TypedArray + Output array. + + Examples + -------- + // Standard Usage: + > var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; + > var y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, 0, y, 1, 0 ) + [ 0.5, 2.0, 3.0, -1.0, 3.5, 1.5, 1.0, 0.0 ] + + // Using index offsets: + > x = [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ]; + > y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}.ndarray( 3, 1.0, 9.0, 2.0, 6.0, x, 1, 3, y, 1, 3 ) + [ 0.0, 0.0, 0.0, -0.5, 4.0, -1.5 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/grescale/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/grescale/docs/types/index.d.ts new file mode 100644 index 000000000000..abc2be75e05e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/grescale/docs/types/index.d.ts @@ -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. +*/ + +// TypeScript Version: 4.1 + +/// + +import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array'; + +/** +* Input array. +*/ +type InputArray = NumericArray | Collection | AccessorArrayLike; + +/** +* Interface describing `grescale`. +*/ +interface Routine { + /** + * Rescales each element in a strided array from the range `[a, b]` to the range `[c, d]` and assigns the results to a strided array `y`. + * + * @param N - number of indexed elements + * @param a - lower bound of the input range + * @param b - upper bound of the input range + * @param c - lower bound of the output range + * @param d - upper bound of the output range + * @param x - input array + * @param strideX - `x` stride length + * @param y - output array + * @param strideY - `y` stride length + * @returns `y` + * + * @example + * var x = [ 1.0, 3.0, 5.0, 7.0, 9.0 ]; + * var y = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + * + * grescale( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, y, 1 ); + * // y => [ 2.0, 3.0, 4.0, 5.0, 6.0 ] + */ + ( N: number, a: number, b: number, c: number, d: number, x: InputArray, strideX: number, y: T, strideY: number ): T; + + /** + * Rescales each element in a strided array from the range `[a, b]` to the range `[c, d]` and assigns the results to a strided array `y` using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param a - lower bound of the input range + * @param b - upper bound of the input range + * @param c - lower bound of the output range + * @param d - upper bound of the output range + * @param x - input array + * @param strideX - `x` stride length + * @param offsetX - starting index for `x` + * @param y - output array + * @param strideY - `y` stride length + * @param offsetY - starting index for `y` + * @returns `y` + * + * @example + * var x = [ 1.0, 3.0, 5.0, 7.0, 9.0 ]; + * var y = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + * + * grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, 0, y, 1, 0 ); + * // y => [ 2.0, 3.0, 4.0, 5.0, 6.0 ] + */ + ndarray( N: number, a: number, b: number, c: number, d: number, x: InputArray, strideX: number, offsetX: number, y: T, strideY: number, offsetY: number ): T; +} + +/** +* Rescales each element in a strided array from the range `[a, b]` to the range `[c, d]` and assigns the results to a strided array `y`. +* +* @param N - number of indexed elements +* @param a - lower bound of the input range +* @param b - upper bound of the input range +* @param c - lower bound of the output range +* @param d - upper bound of the output range +* @param x - input array +* @param strideX - `x` stride length +* @param y - output array +* @param strideY - `y` stride length +* @returns `y` +* +* @example +* var x = [ 1.0, 3.0, 5.0, 7.0, 9.0 ]; +* var y = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* grescale( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, y, 1 ); +* // y => [ 2.0, 3.0, 4.0, 5.0, 6.0 ] +* +* @example +* var x = [ 1.0, 3.0, 5.0, 7.0, 9.0 ]; +* var y = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, 0, y, 1, 0 ); +* // y => [ 2.0, 3.0, 4.0, 5.0, 6.0 ] +*/ +declare var grescale: Routine; + + +// EXPORTS // + +export = grescale; diff --git a/lib/node_modules/@stdlib/blas/ext/base/grescale/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/grescale/docs/types/test.ts new file mode 100644 index 000000000000..620e0dbefc00 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/grescale/docs/types/test.ts @@ -0,0 +1,377 @@ +/* +* @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. +*/ + +import AccessorArray = require( '@stdlib/array/base/accessor' ); +import grescale = require( './index' ); + + +// TESTS // + +// The function returns a numeric array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + grescale( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, y, 1 ); // $ExpectType Float64Array + grescale( x.length, 1.0, 9.0, 2.0, 6.0, new AccessorArray( x ), 1, new AccessorArray( y ), 1 ); // $ExpectType AccessorArray +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + grescale( '10', 1.0, 9.0, 2.0, 6.0, x, 1, y, 1 ); // $ExpectError + grescale( true, 1.0, 9.0, 2.0, 6.0, x, 1, y, 1 ); // $ExpectError + grescale( false, 1.0, 9.0, 2.0, 6.0, x, 1, y, 1 ); // $ExpectError + grescale( null, 1.0, 9.0, 2.0, 6.0, x, 1, y, 1 ); // $ExpectError + grescale( undefined, 1.0, 9.0, 2.0, 6.0, x, 1, y, 1 ); // $ExpectError + grescale( [], 1.0, 9.0, 2.0, 6.0, x, 1, y, 1 ); // $ExpectError + grescale( {}, 1.0, 9.0, 2.0, 6.0, x, 1, y, 1 ); // $ExpectError + grescale( ( x: number ): number => x, 1.0, 9.0, 2.0, 6.0, x, 1, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + grescale( x.length, '10', 9.0, 2.0, 6.0, x, 1, y, 1 ); // $ExpectError + grescale( x.length, true, 9.0, 2.0, 6.0, x, 1, y, 1 ); // $ExpectError + grescale( x.length, false, 9.0, 2.0, 6.0, x, 1, y, 1 ); // $ExpectError + grescale( x.length, null, 9.0, 2.0, 6.0, x, 1, y, 1 ); // $ExpectError + grescale( x.length, undefined, 9.0, 2.0, 6.0, x, 1, y, 1 ); // $ExpectError + grescale( x.length, [], 9.0, 2.0, 6.0, x, 1, y, 1 ); // $ExpectError + grescale( x.length, {}, 9.0, 2.0, 6.0, x, 1, y, 1 ); // $ExpectError + grescale( x.length, ( x: number ): number => x, 9.0, 2.0, 6.0, x, 1, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + grescale( x.length, 1.0, '10', 2.0, 6.0, x, 1, y, 1 ); // $ExpectError + grescale( x.length, 1.0, true, 2.0, 6.0, x, 1, y, 1 ); // $ExpectError + grescale( x.length, 1.0, false, 2.0, 6.0, x, 1, y, 1 ); // $ExpectError + grescale( x.length, 1.0, null, 2.0, 6.0, x, 1, y, 1 ); // $ExpectError + grescale( x.length, 1.0, undefined, 2.0, 6.0, x, 1, y, 1 ); // $ExpectError + grescale( x.length, 1.0, [], 2.0, 6.0, x, 1, y, 1 ); // $ExpectError + grescale( x.length, 1.0, {}, 2.0, 6.0, x, 1, y, 1 ); // $ExpectError + grescale( x.length, 1.0, ( x: number ): number => x, 2.0, 6.0, x, 1, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + grescale( x.length, 1.0, 9.0, '10', 6.0, x, 1, y, 1 ); // $ExpectError + grescale( x.length, 1.0, 9.0, true, 6.0, x, 1, y, 1 ); // $ExpectError + grescale( x.length, 1.0, 9.0, false, 6.0, x, 1, y, 1 ); // $ExpectError + grescale( x.length, 1.0, 9.0, null, 6.0, x, 1, y, 1 ); // $ExpectError + grescale( x.length, 1.0, 9.0, undefined, 6.0, x, 1, y, 1 ); // $ExpectError + grescale( x.length, 1.0, 9.0, [], 6.0, x, 1, y, 1 ); // $ExpectError + grescale( x.length, 1.0, 9.0, {}, 6.0, x, 1, y, 1 ); // $ExpectError + grescale( x.length, 1.0, 9.0, ( x: number ): number => x, 6.0, x, 1, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + grescale( x.length, 1.0, 9.0, 2.0, '10', x, 1, y, 1 ); // $ExpectError + grescale( x.length, 1.0, 9.0, 2.0, true, x, 1, y, 1 ); // $ExpectError + grescale( x.length, 1.0, 9.0, 2.0, false, x, 1, y, 1 ); // $ExpectError + grescale( x.length, 1.0, 9.0, 2.0, null, x, 1, y, 1 ); // $ExpectError + grescale( x.length, 1.0, 9.0, 2.0, undefined, x, 1, y, 1 ); // $ExpectError + grescale( x.length, 1.0, 9.0, 2.0, [], x, 1, y, 1 ); // $ExpectError + grescale( x.length, 1.0, 9.0, 2.0, {}, x, 1, y, 1 ); // $ExpectError + grescale( x.length, 1.0, 9.0, 2.0, ( x: number ): number => x, x, 1, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a numeric array... +{ + const y = new Float64Array( 10 ); + + grescale( 10, 1.0, 9.0, 2.0, 6.0, 10, 1, y, 1 ); // $ExpectError + grescale( 10, 1.0, 9.0, 2.0, 6.0, '10', 1, y, 1 ); // $ExpectError + grescale( 10, 1.0, 9.0, 2.0, 6.0, true, 1, y, 1 ); // $ExpectError + grescale( 10, 1.0, 9.0, 2.0, 6.0, false, 1, y, 1 ); // $ExpectError + grescale( 10, 1.0, 9.0, 2.0, 6.0, null, 1, y, 1 ); // $ExpectError + grescale( 10, 1.0, 9.0, 2.0, 6.0, undefined, 1, y, 1 ); // $ExpectError + grescale( 10, 1.0, 9.0, 2.0, 6.0, [ '1' ], 1, y, 1 ); // $ExpectError + grescale( 10, 1.0, 9.0, 2.0, 6.0, {}, 1, y, 1 ); // $ExpectError + grescale( 10, 1.0, 9.0, 2.0, 6.0, ( x: number ): number => x, 1, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a seventh argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + grescale( x.length, 1.0, 9.0, 2.0, 6.0, x, '10', y, 1 ); // $ExpectError + grescale( x.length, 1.0, 9.0, 2.0, 6.0, x, true, y, 1 ); // $ExpectError + grescale( x.length, 1.0, 9.0, 2.0, 6.0, x, false, y, 1 ); // $ExpectError + grescale( x.length, 1.0, 9.0, 2.0, 6.0, x, null, y, 1 ); // $ExpectError + grescale( x.length, 1.0, 9.0, 2.0, 6.0, x, undefined, y, 1 ); // $ExpectError + grescale( x.length, 1.0, 9.0, 2.0, 6.0, x, [], y, 1 ); // $ExpectError + grescale( x.length, 1.0, 9.0, 2.0, 6.0, x, {}, y, 1 ); // $ExpectError + grescale( x.length, 1.0, 9.0, 2.0, 6.0, x, ( x: number ): number => x, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an eighth argument which is not a numeric array... +{ + const x = new Float64Array( 10 ); + + grescale( 10, 1.0, 9.0, 2.0, 6.0, x, 1, 10, 1 ); // $ExpectError + grescale( 10, 1.0, 9.0, 2.0, 6.0, x, 1, '10', 1 ); // $ExpectError + grescale( 10, 1.0, 9.0, 2.0, 6.0, x, 1, true, 1 ); // $ExpectError + grescale( 10, 1.0, 9.0, 2.0, 6.0, x, 1, false, 1 ); // $ExpectError + grescale( 10, 1.0, 9.0, 2.0, 6.0, x, 1, null, 1 ); // $ExpectError + grescale( 10, 1.0, 9.0, 2.0, 6.0, x, 1, undefined, 1 ); // $ExpectError + grescale( 10, 1.0, 9.0, 2.0, 6.0, x, 1, [ '1' ], 1 ); // $ExpectError + grescale( 10, 1.0, 9.0, 2.0, 6.0, x, 1, {}, 1 ); // $ExpectError + grescale( 10, 1.0, 9.0, 2.0, 6.0, x, 1, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a ninth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + grescale( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, y, '10' ); // $ExpectError + grescale( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, y, true ); // $ExpectError + grescale( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, y, false ); // $ExpectError + grescale( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, y, null ); // $ExpectError + grescale( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, y, undefined ); // $ExpectError + grescale( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, y, [] ); // $ExpectError + grescale( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, y, {} ); // $ExpectError + grescale( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, y, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + grescale(); // $ExpectError + grescale( x.length ); // $ExpectError + grescale( x.length, 1.0 ); // $ExpectError + grescale( x.length, 1.0, 9.0 ); // $ExpectError + grescale( x.length, 1.0, 9.0, 2.0 ); // $ExpectError + grescale( x.length, 1.0, 9.0, 2.0, 6.0 ); // $ExpectError + grescale( x.length, 1.0, 9.0, 2.0, 6.0, x ); // $ExpectError + grescale( x.length, 1.0, 9.0, 2.0, 6.0, x, 1 ); // $ExpectError + grescale( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, y ); // $ExpectError + grescale( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, y, 1, 10 ); // $ExpectError +} + +// Attached to the main export is an `ndarray` method which returns a numeric array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, 0, y, 1, 0 ); // $ExpectType Float64Array + grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, new AccessorArray( x ), 1, 0, new AccessorArray( y ), 1, 0 ); // $ExpectType AccessorArray +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + grescale.ndarray( '10', 1.0, 9.0, 2.0, 6.0, x, 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( true, 1.0, 9.0, 2.0, 6.0, x, 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( false, 1.0, 9.0, 2.0, 6.0, x, 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( null, 1.0, 9.0, 2.0, 6.0, x, 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( undefined, 1.0, 9.0, 2.0, 6.0, x, 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( [], 1.0, 9.0, 2.0, 6.0, x, 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( {}, 1.0, 9.0, 2.0, 6.0, x, 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( ( x: number ): number => x, 1.0, 9.0, 2.0, 6.0, x, 1, 0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + grescale.ndarray( x.length, '10', 9.0, 2.0, 6.0, x, 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, true, 9.0, 2.0, 6.0, x, 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, false, 9.0, 2.0, 6.0, x, 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, null, 9.0, 2.0, 6.0, x, 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, undefined, 9.0, 2.0, 6.0, x, 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, [], 9.0, 2.0, 6.0, x, 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, {}, 9.0, 2.0, 6.0, x, 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, ( x: number ): number => x, 9.0, 2.0, 6.0, x, 1, 0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + grescale.ndarray( x.length, 1.0, '10', 2.0, 6.0, x, 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, true, 2.0, 6.0, x, 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, false, 2.0, 6.0, x, 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, null, 2.0, 6.0, x, 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, undefined, 2.0, 6.0, x, 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, [], 2.0, 6.0, x, 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, {}, 2.0, 6.0, x, 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, ( x: number ): number => x, 2.0, 6.0, x, 1, 0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + grescale.ndarray( x.length, 1.0, 9.0, '10', 6.0, x, 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, true, 6.0, x, 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, false, 6.0, x, 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, null, 6.0, x, 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, undefined, 6.0, x, 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, [], 6.0, x, 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, {}, 6.0, x, 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, ( x: number ): number => x, 6.0, x, 1, 0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + grescale.ndarray( x.length, 1.0, 9.0, 2.0, '10', x, 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0, true, x, 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0, false, x, 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0, null, x, 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0, undefined, x, 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0, [], x, 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0, {}, x, 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0, ( x: number ): number => x, x, 1, 0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a sixth argument which is not a numeric array... +{ + const y = new Float64Array( 10 ); + + grescale.ndarray( 10, 1.0, 9.0, 2.0, 6.0, 10, 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( 10, 1.0, 9.0, 2.0, 6.0, '10', 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( 10, 1.0, 9.0, 2.0, 6.0, true, 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( 10, 1.0, 9.0, 2.0, 6.0, false, 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( 10, 1.0, 9.0, 2.0, 6.0, null, 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( 10, 1.0, 9.0, 2.0, 6.0, undefined, 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( 10, 1.0, 9.0, 2.0, 6.0, [ '1' ], 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( 10, 1.0, 9.0, 2.0, 6.0, {}, 1, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( 10, 1.0, 9.0, 2.0, 6.0, ( x: number ): number => x, 1, 0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a seventh argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, '10', 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, true, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, false, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, null, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, undefined, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, [], 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, {}, 0, y, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, ( x: number ): number => x, 0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an eighth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, '10', y, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, true, y, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, false, y, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, null, y, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, undefined, y, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, [], y, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, {}, y, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, ( x: number ): number => x, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a ninth argument which is not a numeric array... +{ + const x = new Float64Array( 10 ); + + grescale.ndarray( 10, 1.0, 9.0, 2.0, 6.0, x, 1, 0, 10, 1, 0 ); // $ExpectError + grescale.ndarray( 10, 1.0, 9.0, 2.0, 6.0, x, 1, 0, '10', 1, 0 ); // $ExpectError + grescale.ndarray( 10, 1.0, 9.0, 2.0, 6.0, x, 1, 0, true, 1, 0 ); // $ExpectError + grescale.ndarray( 10, 1.0, 9.0, 2.0, 6.0, x, 1, 0, false, 1, 0 ); // $ExpectError + grescale.ndarray( 10, 1.0, 9.0, 2.0, 6.0, x, 1, 0, null, 1, 0 ); // $ExpectError + grescale.ndarray( 10, 1.0, 9.0, 2.0, 6.0, x, 1, 0, undefined, 1, 0 ); // $ExpectError + grescale.ndarray( 10, 1.0, 9.0, 2.0, 6.0, x, 1, 0, [ '1' ], 1, 0 ); // $ExpectError + grescale.ndarray( 10, 1.0, 9.0, 2.0, 6.0, x, 1, 0, {}, 1, 0 ); // $ExpectError + grescale.ndarray( 10, 1.0, 9.0, 2.0, 6.0, x, 1, 0, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a tenth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, 0, y, '10', 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, 0, y, true, 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, 0, y, false, 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, 0, y, null, 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, 0, y, undefined, 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, 0, y, [], 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, 0, y, {}, 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, 0, y, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an eleventh argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, 0, y, 1, '10' ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, 0, y, 1, true ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, 0, y, 1, false ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, 0, y, 1, null ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, 0, y, 1, undefined ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, 0, y, 1, [] ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, 0, y, 1, {} ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, 0, y, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + grescale.ndarray(); // $ExpectError + grescale.ndarray( x.length ); // $ExpectError + grescale.ndarray( x.length, 1.0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, 1 ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, 0 ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, 0, y ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, 0, y, 1 ); // $ExpectError + grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, 0, y, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/grescale/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/grescale/examples/index.js new file mode 100644 index 000000000000..9f5826dc22e0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/grescale/examples/index.js @@ -0,0 +1,32 @@ +/** +* @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/array/discrete-uniform' ); +var logEach = require( '@stdlib/console/log-each' ); +var grescale = require( './../lib' ); + +var opts = { + 'dtype': 'float64' +}; +var x = discreteUniform( 10, -100, 100, opts ); +var y = discreteUniform( 10, -100, 100, opts ); + +grescale( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, y, 1 ); +logEach( '2.0 + (%d - 1.0) * 4.0 / 8.0 = %0.4f', x, y ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/grescale/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/grescale/lib/index.js new file mode 100644 index 000000000000..2f8f98b1de06 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/grescale/lib/index.js @@ -0,0 +1,59 @@ +/** +* @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'; + +/** +* Rescale each element in a strided array from one range to another and assign the results to a strided array `y`. +* +* @module @stdlib/blas/ext/base/grescale +* +* @example +* var grescale = require( '@stdlib/blas/ext/base/grescale' ); +* +* var x = [ 1.0, 3.0, 5.0, 7.0, 9.0 ]; +* var y = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* grescale( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, y, 1 ); +* // y => [ 2.0, 3.0, 4.0, 5.0, 6.0 ] +* +* @example +* var grescale = require( '@stdlib/blas/ext/base/grescale' ); +* +* var x = [ 1.0, 3.0, 5.0, 7.0, 9.0 ]; +* var y = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* grescale.ndarray( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, 0, y, 1, 0 ); +* // y => [ 2.0, 3.0, 4.0, 5.0, 6.0 ] +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( main, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/base/grescale/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/grescale/lib/main.js new file mode 100644 index 000000000000..0ff5aafef6f5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/grescale/lib/main.js @@ -0,0 +1,57 @@ +/** +* @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 gwaxpb = require( '@stdlib/blas/ext/base/gwaxpb' ); + + +// MAIN // + +/** +* Rescales each element in a strided array from the range `[a, b]` to the range `[c, d]` and assigns the results to a strided array `y`. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {number} a - lower bound of the input range +* @param {number} b - upper bound of the input range +* @param {number} c - lower bound of the output range +* @param {number} d - upper bound of the output range +* @param {NumericArray} x - input array +* @param {integer} strideX - `x` stride length +* @param {NumericArray} y - output array +* @param {integer} strideY - `y` stride length +* @returns {NumericArray} output array +* +* @example +* var x = [ 1.0, 3.0, 5.0, 7.0, 9.0 ]; +* var y = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* grescale( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, y, 1 ); +* // y => [ 2.0, 3.0, 4.0, 5.0, 6.0 ] +*/ +function grescale( N, a, b, c, d, x, strideX, y, strideY ) { + var alpha = ( d - c ) / ( b - a ); + return gwaxpb( N, alpha, c - ( a * alpha ), x, strideX, y, strideY ); +} + + +// EXPORTS // + +module.exports = grescale; diff --git a/lib/node_modules/@stdlib/blas/ext/base/grescale/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/grescale/lib/ndarray.js new file mode 100644 index 000000000000..9c82dc9d350d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/grescale/lib/ndarray.js @@ -0,0 +1,61 @@ +/** +* @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 max-params, max-len */ + +'use strict'; + +// MODULES // + +var gwaxpb = require( '@stdlib/blas/ext/base/gwaxpb' ).ndarray; + + +// MAIN // + +/** +* Rescales each element in a strided array from the range `[a, b]` to the range `[c, d]` and assigns the results to a strided array `y` using alternative indexing semantics. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {number} a - lower bound of the input range +* @param {number} b - upper bound of the input range +* @param {number} c - lower bound of the output range +* @param {number} d - upper bound of the output range +* @param {NumericArray} x - input array +* @param {integer} strideX - `x` stride length +* @param {NonNegativeInteger} offsetX - starting `x` index +* @param {NumericArray} y - output array +* @param {integer} strideY - `y` stride length +* @param {NonNegativeInteger} offsetY - starting `y` index +* @returns {NumericArray} output array +* +* @example +* var x = [ 1.0, 3.0, 5.0, 7.0, 9.0 ]; +* var y = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* grescale( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, 0, y, 1, 0 ); +* // y => [ 2.0, 3.0, 4.0, 5.0, 6.0 ] +*/ +function grescale( N, a, b, c, d, x, strideX, offsetX, y, strideY, offsetY ) { + var alpha = ( d - c ) / ( b - a ); + return gwaxpb( N, alpha, c - ( a * alpha ), x, strideX, offsetX, y, strideY, offsetY ); +} + + +// EXPORTS // + +module.exports = grescale; diff --git a/lib/node_modules/@stdlib/blas/ext/base/grescale/package.json b/lib/node_modules/@stdlib/blas/ext/base/grescale/package.json new file mode 100644 index 000000000000..cc578ba002bc --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/grescale/package.json @@ -0,0 +1,72 @@ +{ + "name": "@stdlib/blas/ext/base/grescale", + "version": "0.0.0", + "description": "Rescale each element in a strided array from one range to another and assign the results to a strided array `y`.", + "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", + "linear", + "algebra", + "subroutines", + "rescale", + "normalize", + "range", + "transform", + "strided", + "array", + "ndarray", + "vector", + "grescale" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/grescale/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/grescale/test/test.js new file mode 100644 index 000000000000..76414518ad82 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/grescale/test/test.js @@ -0,0 +1,38 @@ +/** +* @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 grescale = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof grescale, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { + t.strictEqual( typeof grescale.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/grescale/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/grescale/test/test.main.js new file mode 100644 index 000000000000..2e8c3c97c211 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/grescale/test/test.main.js @@ -0,0 +1,407 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var grescale = require( './../lib/main.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof grescale, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 9', function test( t ) { + t.strictEqual( grescale.length, 9, 'has expected arity' ); + t.end(); +}); + +tape( 'the function rescales each element from the range [a, b] to [c, d] and assigns the results to `y`', function test( t ) { + var expected; + var x; + var y; + + x = [ + 4.0, + 2.0, + -3.0, + 5.0, + -1.0, + 2.0, + -5.0, + 6.0 + ]; + y = zeros( x.length ); + expected = [ + 3.5, // 2.0 + (4.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 2.5, // 2.0 + (2.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 0.0, // 2.0 + (-3.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 4.0, // 2.0 + (5.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 1.0, // 2.0 + (-1.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 2.5, // 2.0 + (2.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + -1.0, // 2.0 + (-5.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 4.5 // 2.0 + (6.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + ]; + + grescale( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, y, 1 ); + t.deepEqual( y, expected, 'returns expected value' ); + + x = [ 1.0, 3.0 ]; + y = zeros( x.length ); + expected = [ 2.0, 3.0 ]; + + grescale( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, y, 1 ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function rescales each element from the range [a, b] to [c, d] and assigns the results to `y` (accessors)', function test( t ) { + var expected; + var x; + var y; + + x = [ + 4.0, + 2.0, + -3.0, + 5.0, + -1.0, + 2.0, + -5.0, + 6.0 + ]; + y = zeros( x.length ); + expected = [ + 3.5, // 2.0 + (4.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 2.5, // 2.0 + (2.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 0.0, // 2.0 + (-3.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 4.0, // 2.0 + (5.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 1.0, // 2.0 + (-1.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 2.5, // 2.0 + (2.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + -1.0, // 2.0 + (-5.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 4.5 // 2.0 + (6.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + ]; + + grescale( x.length, 1.0, 9.0, 2.0, 6.0, toAccessorArray( x ), 1, toAccessorArray( y ), 1 ); // eslint-disable-line max-len + t.deepEqual( y, expected, 'returns expected value' ); + + x = [ 1.0, 3.0 ]; + y = zeros( x.length ); + expected = [ 2.0, 3.0 ]; + + grescale( x.length, 1.0, 9.0, 2.0, 6.0, toAccessorArray( x ), 1, toAccessorArray( y ), 1 ); // eslint-disable-line max-len + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a reference to the output array', function test( t ) { + var out; + var x; + var y; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + y = zeros( x.length ); + out = grescale( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, y, 1 ); + + t.strictEqual( out, y, 'same reference' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `y` unchanged', function test( t ) { + var expected; + var x; + var y; + + x = [ 3.0, -4.0, 1.0 ]; + y = [ 4.0, 5.0, 6.0 ]; + expected = [ 4.0, 5.0, 6.0 ]; + + grescale( 0, 1.0, 9.0, 2.0, 6.0, x, 1, y, 1 ); + t.deepEqual( y, expected, 'returns expected value' ); + + grescale( -4, 1.0, 9.0, 2.0, 6.0, x, 1, y, 1 ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'when the input and output ranges have the same width, the function shifts each element', function test( t ) { + var expected; + var x; + var y; + + x = [ 3.0, -4.0, 1.0, 15.0, 4.0, 3.0 ]; + y = zeros( x.length ); + expected = [ 6.0, -1.0, 4.0, 18.0, 7.0, 6.0 ]; // x + 3.0 + + grescale( x.length, 2.0, 6.0, 5.0, 9.0, x, 1, y, 1 ); + t.deepEqual( y, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'when both lower bounds are zero, the function scales each element', function test( t ) { + var expected; + var x; + var y; + + x = [ 10.0, -5.0, 15.0, 20.0, -10.0, 25.0 ]; + y = zeros( x.length ); + expected = [ 5.0, -2.5, 7.5, 10.0, -5.0, 12.5 ]; // x * 0.5 + + grescale( x.length, 0.0, 10.0, 0.0, 5.0, x, 1, y, 1 ); + t.deepEqual( y, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `x` stride', function test( t ) { + var expected; + var x; + var y; + + x = [ + 2.0, // 0 + -3.0, + -5.0, // 1 + 7.0, + 6.0 // 2 + ]; + y = zeros( 3 ); + expected = [ + 2.5, // 2.0 + (2.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + -1.0, // 2.0 + (-5.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 4.5 // 2.0 + (6.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + ]; + + grescale( 3, 1.0, 9.0, 2.0, 6.0, x, 2, y, 1 ); + t.deepEqual( y, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `x` stride (accessors)', function test( t ) { + var expected; + var x; + var y; + + x = [ + 2.0, // 0 + -3.0, + -5.0, // 1 + 7.0, + 6.0 // 2 + ]; + y = zeros( 3 ); + expected = [ + 2.5, // 2.0 + (2.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + -1.0, // 2.0 + (-5.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 4.5 // 2.0 + (6.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + ]; + + grescale( 3, 1.0, 9.0, 2.0, 6.0, toAccessorArray( x ), 2, toAccessorArray( y ), 1 ); // eslint-disable-line max-len + t.deepEqual( y, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `y` stride', function test( t ) { + var expected; + var x; + var y; + + x = [ 1.0, 3.0, 5.0 ]; + y = [ + 0.0, // 0 + 30.0, + 0.0, // 1 + 10.0, + 0.0 // 2 + ]; + expected = [ + 2.0, // 2.0 + (1.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 30.0, + 3.0, // 2.0 + (3.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 10.0, + 4.0 // 2.0 + (5.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + ]; + + grescale( 3, 1.0, 9.0, 2.0, 6.0, x, 1, y, 2 ); + t.deepEqual( y, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `y` stride (accessors)', function test( t ) { + var expected; + var x; + var y; + + x = [ 1.0, 3.0, 5.0 ]; + y = [ + 0.0, // 0 + 30.0, + 0.0, // 1 + 10.0, + 0.0 // 2 + ]; + expected = [ + 2.0, // 2.0 + (1.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 30.0, + 3.0, // 2.0 + (3.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 10.0, + 4.0 // 2.0 + (5.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + ]; + + grescale( 3, 1.0, 9.0, 2.0, 6.0, toAccessorArray( x ), 1, toAccessorArray( y ), 2 ); // eslint-disable-line max-len + t.deepEqual( y, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports negative strides', function test( t ) { + var expected; + var x; + var y; + + x = [ + 2.0, // 2 + -3.0, + -5.0, // 1 + 7.0, + 6.0 // 0 + ]; + y = zeros( 5 ); + expected = [ + 2.5, // 2.0 + (2.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 0.0, + -1.0, // 2.0 + (-5.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 0.0, + 4.5 // 2.0 + (6.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + ]; + + grescale( 3, 1.0, 9.0, 2.0, 6.0, x, -2, y, -2 ); + t.deepEqual( y, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports negative strides (accessors)', function test( t ) { + var expected; + var x; + var y; + + x = [ + 2.0, // 2 + -3.0, + -5.0, // 1 + 7.0, + 6.0 // 0 + ]; + y = zeros( 5 ); + expected = [ + 2.5, // 2.0 + (2.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 0.0, + -1.0, // 2.0 + (-5.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 0.0, + 4.5 // 2.0 + (6.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + ]; + + grescale( 3, 1.0, 9.0, 2.0, 6.0, toAccessorArray( x ), -2, toAccessorArray( y ), -2 ); // eslint-disable-line max-len + t.deepEqual( y, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var expected; + var x0; + var y0; + var x1; + var y1; + + x0 = new Float64Array([ + 1.0, + 2.0, // 0 + 3.0, // 1 + 4.0, // 2 + 5.0 + ]); + y0 = new Float64Array([ + 10.0, + 10.0, + 0.0, // 0 + 0.0, // 1 + 0.0 // 2 + ]); + + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*2 ); + + expected = new Float64Array([ + 10.0, + 10.0, + 2.5, // 2.0 + (2.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 3.0, // 2.0 + (3.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 3.5 // 2.0 + (4.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + ]); + + grescale( 3, 1.0, 9.0, 2.0, 6.0, x1, 1, y1, 1 ); + t.deepEqual( y0, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if both strides are equal to `1`, the function efficiently rescales elements', function test( t ) { + var expected; + var x; + var y; + var a; + var b; + var c; + var d; + var i; + + a = 1.0; + b = 9.0; + c = 2.0; + d = 6.0; + x = new Float64Array( 100 ); + y = new Float64Array( 100 ); + expected = new Float64Array( x.length ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = i; + expected[ i ] = c + ( ( x[ i ] - a ) * ( d - c ) / ( b - a ) ); + } + grescale( x.length, a, b, c, d, x, 1, y, 1 ); + t.deepEqual( y, expected, 'returns expected value' ); + + x = new Float64Array( 240 ); + y = new Float64Array( 240 ); + expected = new Float64Array( x.length ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = i; + expected[ i ] = c + ( ( x[ i ] - a ) * ( d - c ) / ( b - a ) ); + } + grescale( x.length, a, b, c, d, x, 1, y, 1 ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/grescale/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/grescale/test/test.ndarray.js new file mode 100644 index 000000000000..cc9a73db1c0b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/grescale/test/test.ndarray.js @@ -0,0 +1,425 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var grescale = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof grescale, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 11', function test( t ) { + t.strictEqual( grescale.length, 11, 'has expected arity' ); + t.end(); +}); + +tape( 'the function rescales each element from the range [a, b] to [c, d] and assigns the results to `y`', function test( t ) { + var expected; + var x; + var y; + + x = [ + 4.0, + 2.0, + -3.0, + 5.0, + -1.0, + 2.0, + -5.0, + 6.0 + ]; + y = zeros( x.length ); + expected = [ + 3.5, // 2.0 + (4.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 2.5, // 2.0 + (2.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 0.0, // 2.0 + (-3.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 4.0, // 2.0 + (5.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 1.0, // 2.0 + (-1.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 2.5, // 2.0 + (2.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + -1.0, // 2.0 + (-5.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 4.5 // 2.0 + (6.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + ]; + + grescale( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, 0, y, 1, 0 ); + t.deepEqual( y, expected, 'returns expected value' ); + + x = [ 1.0, 3.0 ]; + y = zeros( x.length ); + expected = [ 2.0, 3.0 ]; + + grescale( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, 0, y, 1, 0 ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function rescales each element from the range [a, b] to [c, d] and assigns the results to `y` (accessors)', function test( t ) { + var expected; + var x; + var y; + + x = [ + 4.0, + 2.0, + -3.0, + 5.0, + -1.0, + 2.0, + -5.0, + 6.0 + ]; + y = zeros( x.length ); + expected = [ + 3.5, // 2.0 + (4.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 2.5, // 2.0 + (2.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 0.0, // 2.0 + (-3.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 4.0, // 2.0 + (5.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 1.0, // 2.0 + (-1.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 2.5, // 2.0 + (2.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + -1.0, // 2.0 + (-5.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 4.5 // 2.0 + (6.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + ]; + + grescale( x.length, 1.0, 9.0, 2.0, 6.0, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 1, 0 ); // eslint-disable-line max-len + t.deepEqual( y, expected, 'returns expected value' ); + + x = [ 1.0, 3.0 ]; + y = zeros( x.length ); + expected = [ 2.0, 3.0 ]; + + grescale( x.length, 1.0, 9.0, 2.0, 6.0, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 1, 0 ); // eslint-disable-line max-len + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a reference to the output array', function test( t ) { + var out; + var x; + var y; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + y = zeros( x.length ); + out = grescale( x.length, 1.0, 9.0, 2.0, 6.0, x, 1, 0, y, 1, 0 ); + + t.strictEqual( out, y, 'same reference' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `y` unchanged', function test( t ) { + var expected; + var x; + var y; + + x = [ 3.0, -4.0, 1.0 ]; + y = [ 4.0, 5.0, 6.0 ]; + expected = [ 4.0, 5.0, 6.0 ]; + + grescale( 0, 1.0, 9.0, 2.0, 6.0, x, 1, 0, y, 1, 0 ); + t.deepEqual( y, expected, 'returns expected value' ); + + grescale( -4, 1.0, 9.0, 2.0, 6.0, x, 1, 0, y, 1, 0 ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'when the input and output ranges have the same width, the function shifts each element', function test( t ) { + var expected; + var x; + var y; + + x = [ 3.0, -4.0, 1.0, 15.0, 4.0, 3.0 ]; + y = zeros( x.length ); + expected = [ 6.0, -1.0, 4.0, 18.0, 7.0, 6.0 ]; // x + 3.0 + + grescale( x.length, 2.0, 6.0, 5.0, 9.0, x, 1, 0, y, 1, 0 ); + t.deepEqual( y, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'when both lower bounds are zero, the function scales each element', function test( t ) { + var expected; + var x; + var y; + + x = [ 10.0, -5.0, 15.0, 20.0, -10.0, 25.0 ]; + y = zeros( x.length ); + expected = [ 5.0, -2.5, 7.5, 10.0, -5.0, 12.5 ]; // x * 0.5 + + grescale( x.length, 0.0, 10.0, 0.0, 5.0, x, 1, 0, y, 1, 0 ); + t.deepEqual( y, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `x` stride', function test( t ) { + var expected; + var x; + var y; + + x = [ + 2.0, // 0 + -3.0, + -5.0, // 1 + 7.0, + 6.0 // 2 + ]; + y = zeros( 3 ); + expected = [ + 2.5, // 2.0 + (2.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + -1.0, // 2.0 + (-5.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 4.5 // 2.0 + (6.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + ]; + + grescale( 3, 1.0, 9.0, 2.0, 6.0, x, 2, 0, y, 1, 0 ); + t.deepEqual( y, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `x` stride (accessors)', function test( t ) { + var expected; + var x; + var y; + + x = [ + 2.0, // 0 + -3.0, + -5.0, // 1 + 7.0, + 6.0 // 2 + ]; + y = zeros( 3 ); + expected = [ + 2.5, // 2.0 + (2.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + -1.0, // 2.0 + (-5.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 4.5 // 2.0 + (6.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + ]; + + grescale( 3, 1.0, 9.0, 2.0, 6.0, toAccessorArray( x ), 2, 0, toAccessorArray( y ), 1, 0 ); // eslint-disable-line max-len + t.deepEqual( y, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `y` stride', function test( t ) { + var expected; + var x; + var y; + + x = [ 1.0, 3.0, 5.0 ]; + y = [ + 0.0, // 0 + 30.0, + 0.0, // 1 + 10.0, + 0.0 // 2 + ]; + expected = [ + 2.0, // 2.0 + (1.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 30.0, + 3.0, // 2.0 + (3.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 10.0, + 4.0 // 2.0 + (5.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + ]; + + grescale( 3, 1.0, 9.0, 2.0, 6.0, x, 1, 0, y, 2, 0 ); + t.deepEqual( y, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `y` stride (accessors)', function test( t ) { + var expected; + var x; + var y; + + x = [ 1.0, 3.0, 5.0 ]; + y = [ + 0.0, // 0 + 30.0, + 0.0, // 1 + 10.0, + 0.0 // 2 + ]; + expected = [ + 2.0, // 2.0 + (1.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 30.0, + 3.0, // 2.0 + (3.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 10.0, + 4.0 // 2.0 + (5.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + ]; + + grescale( 3, 1.0, 9.0, 2.0, 6.0, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 2, 0 ); // eslint-disable-line max-len + t.deepEqual( y, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports negative strides', function test( t ) { + var expected; + var x; + var y; + + x = [ + 2.0, // 2 + -3.0, + -5.0, // 1 + 7.0, + 6.0 // 0 + ]; + y = [ + 0.0, // 2 + 0.0, // 1 + 0.0 // 0 + ]; + expected = [ + 2.5, // 2.0 + (2.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + -1.0, // 2.0 + (-5.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 4.5 // 2.0 + (6.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + ]; + + grescale( 3, 1.0, 9.0, 2.0, 6.0, x, -2, x.length-1, y, -1, y.length-1 ); + t.deepEqual( y, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports negative strides (accessors)', function test( t ) { + var expected; + var x; + var y; + + x = [ + 2.0, // 2 + -3.0, + -5.0, // 1 + 7.0, + 6.0 // 0 + ]; + y = [ + 0.0, // 2 + 0.0, // 1 + 0.0 // 0 + ]; + expected = [ + 2.5, // 2.0 + (2.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + -1.0, // 2.0 + (-5.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 4.5 // 2.0 + (6.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + ]; + + grescale( 3, 1.0, 9.0, 2.0, 6.0, toAccessorArray( x ), -2, x.length-1, toAccessorArray( y ), -1, y.length-1 ); // eslint-disable-line max-len + t.deepEqual( y, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `x` offset', function test( t ) { + var expected; + var x; + var y; + + x = [ + 1.0, + 2.0, // 0 + 3.0, // 1 + 4.0, // 2 + 5.0 + ]; + y = zeros( 5 ); + expected = [ + 2.5, // 2.0 + (2.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 3.0, // 2.0 + (3.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 3.5, // 2.0 + (4.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 0.0, + 0.0 + ]; + + grescale( 3, 1.0, 9.0, 2.0, 6.0, x, 1, 1, y, 1, 0 ); + t.deepEqual( y, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `y` offset', function test( t ) { + var expected; + var x; + var y; + + x = [ 1.0, 3.0, 5.0 ]; + y = [ + 0.0, + 0.0, + 0.0, // 0 + 0.0, // 1 + 0.0 // 2 + ]; + expected = [ + 0.0, + 0.0, + 2.0, // 2.0 + (1.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 3.0, // 2.0 + (3.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + 4.0 // 2.0 + (5.0 - 1.0) * (6.0 - 2.0) / (9.0 - 1.0) + ]; + + grescale( 3, 1.0, 9.0, 2.0, 6.0, x, 1, 0, y, 1, 2 ); + t.deepEqual( y, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if both strides are equal to `1`, the function efficiently rescales elements', function test( t ) { + var expected; + var x; + var y; + var a; + var b; + var c; + var d; + var i; + + a = 1.0; + b = 9.0; + c = 2.0; + d = 6.0; + x = new Float64Array( 100 ); + y = new Float64Array( 100 ); + expected = new Float64Array( x.length ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = i; + expected[ i ] = c + ( ( x[ i ] - a ) * ( d - c ) / ( b - a ) ); + } + grescale( x.length, a, b, c, d, x, 1, 0, y, 1, 0 ); + t.deepEqual( y, expected, 'returns expected value' ); + + x = new Float64Array( 240 ); + y = new Float64Array( 240 ); + expected = new Float64Array( x.length ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = i; + expected[ i ] = c + ( ( x[ i ] - a ) * ( d - c ) / ( b - a ) ); + } + grescale( x.length, a, b, c, d, x, 1, 0, y, 1, 0 ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +});