diff --git a/lib/node_modules/@stdlib/stats/strided/rangeabs/README.md b/lib/node_modules/@stdlib/stats/strided/rangeabs/README.md new file mode 100644 index 000000000000..76d6bb694d6e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/rangeabs/README.md @@ -0,0 +1,187 @@ + + +# rangeabs + +> Calculate the range of absolute values of a strided array. + +
+ +
+ + + +
+ +## Usage + +```javascript +var rangeabs = require( '@stdlib/stats/strided/rangeabs' ); +``` + +#### rangeabs( N, x, strideX ) + +Computes the range of absolute values of a strided array `x`. + +```javascript +var x = [ 1.0, -2.0, 2.0 ]; + +var v = rangeabs( x.length, x, 1 ); +// returns 1.0 +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. +- **strideX**: stride length for `x`. + +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the range of absolute values of every other element in `x`, + +```javascript +var x = [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ]; + +var v = rangeabs( 4, x, 2 ); +// returns 3.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' ); + +var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +var v = rangeabs( 4, x1, 2 ); +// returns 3.0 +``` + +#### rangeabs.ndarray( N, x, strideX, offsetX ) + +Computes the range of absolute values of a strided array using alternative indexing semantics. + +```javascript +var x = [ 1.0, -2.0, 2.0 ]; + +var v = rangeabs.ndarray( x.length, x, 1, 0 ); +// returns 1.0 +``` + +The function has the following additional parameters: + +- **offsetX**: starting index for `x`. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to calculate the range of absolute values for every other element in `x` starting from the second element + +```javascript +var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; + +var v = rangeabs.ndarray( 4, x, 2, 1 ); +// returns 3.0 +``` + +
+ + + +
+ +## Notes + +- If `N <= 0`, both functions return `NaN`. +- Depending on the environment, the typed versions ([`drangeabs`][@stdlib/stats/strided/drangeabs], [`srangeabs`][@stdlib/stats/strided/srangeabs], etc.) are likely to be significantly more performant. +- 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 rangeabs = require( '@stdlib/stats/strided/rangeabs' ); + +var x = discreteUniform( 10, -50, 50, { + 'dtype': 'float64' +}); +console.log( x ); + +var v = rangeabs( x.length, x, 1 ); +console.log( v ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/strided/rangeabs/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/strided/rangeabs/benchmark/benchmark.js new file mode 100644 index 000000000000..03d2f44924ab --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/rangeabs/benchmark/benchmark.js @@ -0,0 +1,103 @@ +/** +* @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 rangeabs = require( './../lib/main.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -10, 10, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = rangeabs( x.length, x, 1 ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + 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/stats/strided/rangeabs/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/strided/rangeabs/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..83827a414a7f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/rangeabs/benchmark/benchmark.ndarray.js @@ -0,0 +1,103 @@ +/** +* @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 rangeabs = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -10, 10, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = rangeabs( x.length, x, 1, 0 ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + 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/stats/strided/rangeabs/docs/repl.txt b/lib/node_modules/@stdlib/stats/strided/rangeabs/docs/repl.txt new file mode 100644 index 000000000000..71d6ba41f584 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/rangeabs/docs/repl.txt @@ -0,0 +1,89 @@ + +{{alias}}( N, x, strideX ) + Computes the range of absolute values of a strided array. + + The `N` and stride parameters determine which elements in the strided array + are accessed at runtime. + + Indexing is relative to the first index. To introduce an offset, use a typed + array view. + + If `N <= 0`, the function returns `NaN`. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: Array|TypedArray + Input array. + + strideX: integer + Stride length. + + Returns + ------- + out: number + Range of absolute values. + + Examples + -------- + // Standard Usage: + > var x = [ 1.0, -2.0, 2.0 ]; + > {{alias}}( x.length, x, 1 ) + 1.0 + + // Using `N` and stride parameters: + > x = [ -2.0, 1.0, -5.0, -5.0, 2.0, -1.0 ]; + > {{alias}}( 3, x, 2 ) + 3.0 + + // Using view offsets: + > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 10.0, 5.0, -1.0 ] ); + > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > {{alias}}( 3, x1, 2 ) + 9.0 + + +{{alias}}.ndarray( N, x, strideX, offsetX ) + Computes the range of absolute values of a strided array using alternative + indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the `offset` parameter supports indexing semantics based on a + starting index. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: Array|TypedArray + Input array. + + strideX: integer + Stride length. + + offsetX: integer + Starting index. + + Returns + ------- + out: number + Range of absolute values. + + Examples + -------- + // Standard Usage: + > var x = [ 1.0, -2.0, 2.0 ]; + > {{alias}}.ndarray( x.length, x, 1, 0 ) + 1.0 + + // Using offset parameter: + > var x = [ 1.0, -2.0, 3.0, 10.0, 5.0, -1.0 ]; + > {{alias}}.ndarray( 3, x, 2, 1 ) + 9.0 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/strided/rangeabs/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/strided/rangeabs/docs/types/index.d.ts new file mode 100644 index 000000000000..906e75c2d808 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/rangeabs/docs/types/index.d.ts @@ -0,0 +1,93 @@ +/* +* @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 `rangeabs`. +*/ +interface Routine { + /** + * Computes the range of absolute values of a strided array. + * + * @param N - number of indexed elements + * @param x - input array + * @param strideX - stride length + * @returns range of absolute values + * + * @example + * var x = [ 1.0, -2.0, 2.0 ]; + * + * var v = rangeabs( x.length, x, 1 ); + * // returns 1.0 + */ + ( N: number, x: InputArray, strideX: number ): number; + + /** + * Computes the range of absolute values of a strided array using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param x - input array + * @param strideX - stride length + * @param offsetX - starting index + * @returns range of absolute values + * + * @example + * var x = [ 1.0, -2.0, 2.0 ]; + * + * var v = rangeabs.ndarray( x.length, x, 1, 0 ); + * // returns 1.0 + */ + ndarray( N: number, x: InputArray, strideX: number, offsetX: number ): number; +} + +/** +* Computes the range of absolute values of a strided array. +* +* @param N - number of indexed elements +* @param x - input array +* @param strideX - stride length +* @returns range of absolute values +* +* @example +* var x = [ 1.0, -2.0, 2.0 ]; +* +* var v = rangeabs( x.length, x, 1 ); +* // returns 1.0 +* +* @example +* var x = [ 1.0, -2.0, 2.0 ]; +* +* var v = rangeabs.ndarray( x.length, x, 1, 0 ); +* // returns 1.0 +*/ +declare var rangeabs: Routine; + + +// EXPORTS // + +export = rangeabs; diff --git a/lib/node_modules/@stdlib/stats/strided/rangeabs/docs/types/test.ts b/lib/node_modules/@stdlib/stats/strided/rangeabs/docs/types/test.ts new file mode 100644 index 000000000000..e0c532d48e68 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/rangeabs/docs/types/test.ts @@ -0,0 +1,158 @@ +/* +* @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 rangeabs = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const x = new Float64Array( 10 ); + + rangeabs( x.length, x, 1 ); // $ExpectType number + rangeabs( x.length, new AccessorArray( x ), 1 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + + rangeabs( '10', x, 1 ); // $ExpectError + rangeabs( true, x, 1 ); // $ExpectError + rangeabs( false, x, 1 ); // $ExpectError + rangeabs( null, x, 1 ); // $ExpectError + rangeabs( undefined, x, 1 ); // $ExpectError + rangeabs( [], x, 1 ); // $ExpectError + rangeabs( {}, x, 1 ); // $ExpectError + rangeabs( ( x: number ): number => x, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a numeric array... +{ + const x = new Float64Array( 10 ); + + rangeabs( x.length, 10, 1 ); // $ExpectError + rangeabs( x.length, '10', 1 ); // $ExpectError + rangeabs( x.length, true, 1 ); // $ExpectError + rangeabs( x.length, false, 1 ); // $ExpectError + rangeabs( x.length, null, 1 ); // $ExpectError + rangeabs( x.length, undefined, 1 ); // $ExpectError + rangeabs( x.length, {}, 1 ); // $ExpectError + rangeabs( x.length, ( x: number ): number => x, 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 ); + + rangeabs( x.length, x, '10' ); // $ExpectError + rangeabs( x.length, x, true ); // $ExpectError + rangeabs( x.length, x, false ); // $ExpectError + rangeabs( x.length, x, null ); // $ExpectError + rangeabs( x.length, x, undefined ); // $ExpectError + rangeabs( x.length, x, [] ); // $ExpectError + rangeabs( x.length, x, {} ); // $ExpectError + rangeabs( x.length, x, ( 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 ); + + rangeabs(); // $ExpectError + rangeabs( x.length ); // $ExpectError + rangeabs( x.length, x ); // $ExpectError + rangeabs( x.length, x, 1, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a number... +{ + const x = new Float64Array( 10 ); + + rangeabs.ndarray( x.length, x, 1, 0 ); // $ExpectType number + rangeabs.ndarray( x.length, new AccessorArray( x ), 1, 0 ); // $ExpectType number +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + + rangeabs.ndarray( '10', x, 1, 0 ); // $ExpectError + rangeabs.ndarray( true, x, 1, 0 ); // $ExpectError + rangeabs.ndarray( false, x, 1, 0 ); // $ExpectError + rangeabs.ndarray( null, x, 1, 0 ); // $ExpectError + rangeabs.ndarray( undefined, x, 1, 0 ); // $ExpectError + rangeabs.ndarray( [], x, 1, 0 ); // $ExpectError + rangeabs.ndarray( {}, x, 1, 0 ); // $ExpectError + rangeabs.ndarray( ( x: number ): number => x, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a numeric array... +{ + const x = new Float64Array( 10 ); + + rangeabs.ndarray( x.length, 10, 1, 0 ); // $ExpectError + rangeabs.ndarray( x.length, '10', 1, 0 ); // $ExpectError + rangeabs.ndarray( x.length, true, 1, 0 ); // $ExpectError + rangeabs.ndarray( x.length, false, 1, 0 ); // $ExpectError + rangeabs.ndarray( x.length, null, 1, 0 ); // $ExpectError + rangeabs.ndarray( x.length, undefined, 1, 0 ); // $ExpectError + rangeabs.ndarray( x.length, {}, 1, 0 ); // $ExpectError + rangeabs.ndarray( x.length, ( x: number ): number => x, 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 ); + + rangeabs.ndarray( x.length, x, '10', 0 ); // $ExpectError + rangeabs.ndarray( x.length, x, true, 0 ); // $ExpectError + rangeabs.ndarray( x.length, x, false, 0 ); // $ExpectError + rangeabs.ndarray( x.length, x, null, 0 ); // $ExpectError + rangeabs.ndarray( x.length, x, undefined, 0 ); // $ExpectError + rangeabs.ndarray( x.length, x, [], 0 ); // $ExpectError + rangeabs.ndarray( x.length, x, {}, 0 ); // $ExpectError + rangeabs.ndarray( x.length, x, ( x: number ): number => x, 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 ); + + rangeabs.ndarray( x.length, x, 1, '10' ); // $ExpectError + rangeabs.ndarray( x.length, x, 1, true ); // $ExpectError + rangeabs.ndarray( x.length, x, 1, false ); // $ExpectError + rangeabs.ndarray( x.length, x, 1, null ); // $ExpectError + rangeabs.ndarray( x.length, x, 1, undefined ); // $ExpectError + rangeabs.ndarray( x.length, x, 1, [] ); // $ExpectError + rangeabs.ndarray( x.length, x, 1, {} ); // $ExpectError + rangeabs.ndarray( x.length, x, 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 ); + + rangeabs.ndarray(); // $ExpectError + rangeabs.ndarray( x.length ); // $ExpectError + rangeabs.ndarray( x.length, x ); // $ExpectError + rangeabs.ndarray( x.length, x, 1 ); // $ExpectError + rangeabs.ndarray( x.length, x, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/strided/rangeabs/examples/index.js b/lib/node_modules/@stdlib/stats/strided/rangeabs/examples/index.js new file mode 100644 index 000000000000..3204aa6721e8 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/rangeabs/examples/index.js @@ -0,0 +1,30 @@ +/** +* @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 rangeabs = require( './../lib' ); + +var x = discreteUniform( 10, -50, 50, { + 'dtype': 'float64' +}); +console.log( x ); + +var v = rangeabs( x.length, x, 1 ); +console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/strided/rangeabs/lib/accessors.js b/lib/node_modules/@stdlib/stats/strided/rangeabs/lib/accessors.js new file mode 100644 index 000000000000..f5188fb73e64 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/rangeabs/lib/accessors.js @@ -0,0 +1,92 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var abs = require( '@stdlib/math/base/special/abs' ); + + +// MAIN // + +/** +* Computes the range of absolute values of a strided array. +* +* @private +* @param {PositiveInteger} N - number of indexed elements +* @param {Object} x - input array object +* @param {Collection} x.data - input array data +* @param {Array} x.accessors - array element accessors +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @returns {number} range of absolute values +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var x = toAccessorArray( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); +* +* var v = rangeabs( 4, arraylike2object( x ), 2, 1 ); +* // returns 3.0 +*/ +function rangeabs( N, x, strideX, offsetX ) { + var xbuf; + var get; + var max; + var min; + var ix; + var v; + var i; + + // Cache reference to array data: + xbuf = x.data; + + // Cache a reference to the element accessor: + get = x.accessors[ 0 ]; + + if ( N === 1 || strideX === 0 ) { + if ( isnan( get( xbuf, offsetX ) ) ) { + return NaN; + } + return 0.0; + } + ix = offsetX; + min = abs( get( xbuf, ix ) ); + max = min; + for ( i = 1; i < N; i++ ) { + ix += strideX; + v = abs( get( xbuf, ix ) ); + if ( isnan( v ) ) { + return v; + } + if ( v < min ) { + min = v; + } else if ( v > max ) { + max = v; + } + } + return max - min; +} + + +// EXPORTS // + +module.exports = rangeabs; diff --git a/lib/node_modules/@stdlib/stats/strided/rangeabs/lib/index.js b/lib/node_modules/@stdlib/stats/strided/rangeabs/lib/index.js new file mode 100644 index 000000000000..12cec2f75f38 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/rangeabs/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'; + +/** +* Compute the range of absolute values of a strided array. +* +* @module @stdlib/stats/strided/rangeabs +* +* @example +* var rangeabs = require( '@stdlib/stats/strided/rangeabs' ); +* +* var x = [ 1.0, -2.0, 2.0 ]; +* +* var v = rangeabs( x.length, x, 1 ); +* // returns 1.0 +* +* @example +* var rangeabs = require( '@stdlib/stats/strided/rangeabs' ); +* +* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; +* +* var v = rangeabs.ndarray( 4, x, 2, 1 ); +* // returns 3.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; + +// exports: { "ndarray": "main.ndarray" } diff --git a/lib/node_modules/@stdlib/stats/strided/rangeabs/lib/main.js b/lib/node_modules/@stdlib/stats/strided/rangeabs/lib/main.js new file mode 100644 index 000000000000..7c6a20b64fa7 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/rangeabs/lib/main.js @@ -0,0 +1,50 @@ +/** +* @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 stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +/** +* Computes the range of absolute values of a strided array. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {NumericArray} x - input array +* @param {integer} strideX - stride length +* @returns {number} range of absolute values +* +* @example +* var x = [ 1.0, -2.0, 2.0 ]; +* +* var v = rangeabs( x.length, x, 1 ); +* // returns 1.0 +*/ +function rangeabs( N, x, strideX ) { + return ndarray( N, x, strideX, stride2offset( N, strideX ) ); +} + + +// EXPORTS // + +module.exports = rangeabs; diff --git a/lib/node_modules/@stdlib/stats/strided/rangeabs/lib/ndarray.js b/lib/node_modules/@stdlib/stats/strided/rangeabs/lib/ndarray.js new file mode 100644 index 000000000000..c598981773b9 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/rangeabs/lib/ndarray.js @@ -0,0 +1,88 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var accessors = require( './accessors.js' ); + + +// MAIN // + +/** +* Computes the range of absolute values of a strided array. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {NumericArray} x - input array +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @returns {number} range of absolute values +* +* @example +* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; +* +* var v = rangeabs( 4, x, 2, 1 ); +* // returns 3.0 +*/ +function rangeabs( N, x, strideX, offsetX ) { + var max; + var min; + var ix; + var o; + var v; + var i; + + if ( N <= 0 ) { + return NaN; + } + o = arraylike2object( x ); + if ( o.accessorProtocol ) { + return accessors( N, o, strideX, offsetX ); + } + if ( N === 1 || strideX === 0 ) { + if ( isnan( x[ offsetX ] ) ) { + return NaN; + } + return 0.0; + } + ix = offsetX; + min = abs( x[ ix ] ); + max = min; + for ( i = 1; i < N; i++ ) { + ix += strideX; + v = abs( x[ ix ] ); + if ( isnan( v ) ) { + return v; + } + if ( v < min ) { + min = v; + } else if ( v > max ) { + max = v; + } + } + return max - min; +} + + +// EXPORTS // + +module.exports = rangeabs; diff --git a/lib/node_modules/@stdlib/stats/strided/rangeabs/package.json b/lib/node_modules/@stdlib/stats/strided/rangeabs/package.json new file mode 100644 index 000000000000..5db6b0828b44 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/rangeabs/package.json @@ -0,0 +1,73 @@ +{ + "name": "@stdlib/stats/strided/rangeabs", + "version": "0.0.0", + "description": "Calculate the range of absolute values of a strided array.", + "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", + "statistics", + "stats", + "mathematics", + "math", + "minimum", + "min", + "maximum", + "range", + "absolute", + "abs", + "extremes", + "dispersion", + "domain", + "extent", + "strided", + "strided array", + "array" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/strided/rangeabs/test/test.js b/lib/node_modules/@stdlib/stats/strided/rangeabs/test/test.js new file mode 100644 index 000000000000..7310a4845325 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/rangeabs/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 rangeabs = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof rangeabs, '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 rangeabs.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/strided/rangeabs/test/test.main.js b/lib/node_modules/@stdlib/stats/strided/rangeabs/test/test.main.js new file mode 100644 index 000000000000..a2eae1fa010b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/rangeabs/test/test.main.js @@ -0,0 +1,268 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var Float64Array = require( '@stdlib/array/float64' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var rangeabs = require( './../lib/main.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof rangeabs, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 3', function test( t ) { + t.strictEqual( rangeabs.length, 3, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the range of absolute values of a strided array', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = rangeabs( x.length, x, 1 ); + t.strictEqual( v, 5.0, 'returns expected value' ); + + x = [ -4.0, -5.0 ]; + v = rangeabs( x.length, x, 1 ); + t.strictEqual( v, 1.0, 'returns expected value' ); + + x = [ -0.0, 0.0, -0.0 ]; + v = rangeabs( x.length, x, 1 ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + + x = [ NaN ]; + v = rangeabs( x.length, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + v = rangeabs( x.length, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the range of absolute values of a strided array (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = rangeabs( x.length, toAccessorArray( x ), 1 ); + t.strictEqual( v, 5.0, 'returns expected value' ); + + x = [ -4.0, -5.0 ]; + v = rangeabs( x.length, toAccessorArray( x ), 1 ); + t.strictEqual( v, 1.0, 'returns expected value' ); + + x = [ -0.0, 0.0, -0.0 ]; + v = rangeabs( x.length, toAccessorArray( x ), 1 ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + + x = [ NaN ]; + v = rangeabs( x.length, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + v = rangeabs( x.length, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = rangeabs( 0, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = rangeabs( -1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns `0.0`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = rangeabs( 1, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns `0.0` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = rangeabs( 1, toAccessorArray( x ), 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `stride` parameter', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]; + + v = rangeabs( 4, x, 2 ); + + t.strictEqual( v, 3.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `stride` parameter (accessors)', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]; + + v = rangeabs( 4, toAccessorArray( x ), 2 ); + + t.strictEqual( v, 3.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + + v = rangeabs( 4, x, -2 ); + + t.strictEqual( v, 3.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter (accessors)', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + + v = rangeabs( 4, toAccessorArray( x ), -2 ); + + t.strictEqual( v, 3.0, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0.0`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = rangeabs( x.length, x, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0.0` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = rangeabs( x.length, toAccessorArray( x ), 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var x0; + var x1; + var v; + + x0 = new Float64Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0, // 3 + 6.0 + ]); + + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + + v = rangeabs( 4, x1, 2 ); + t.strictEqual( v, 3.0, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/strided/rangeabs/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/strided/rangeabs/test/test.ndarray.js new file mode 100644 index 000000000000..4c36a8077e32 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/rangeabs/test/test.ndarray.js @@ -0,0 +1,284 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var rangeabs = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof rangeabs, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 4', function test( t ) { + t.strictEqual( rangeabs.length, 4, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the range of absolute values of a strided array', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = rangeabs( x.length, x, 1, 0 ); + t.strictEqual( v, 5.0, 'returns expected value' ); + + x = [ -4.0, -5.0 ]; + v = rangeabs( x.length, x, 1, 0 ); + t.strictEqual( v, 1.0, 'returns expected value' ); + + x = [ -0.0, 0.0, -0.0 ]; + v = rangeabs( x.length, x, 1, 0 ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + + x = [ NaN ]; + v = rangeabs( x.length, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + v = rangeabs( x.length, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the range of absolute values of a strided array (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = rangeabs( x.length, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 5.0, 'returns expected value' ); + + x = [ -4.0, -5.0 ]; + v = rangeabs( x.length, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 1.0, 'returns expected value' ); + + x = [ -0.0, 0.0, -0.0 ]; + v = rangeabs( x.length, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + + x = [ NaN ]; + v = rangeabs( x.length, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + v = rangeabs( x.length, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = rangeabs( 0, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = rangeabs( -1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns `0.0`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = rangeabs( 1, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns `0.0` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = rangeabs( 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `stride` parameter', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]; + + v = rangeabs( 4, x, 2, 0 ); + + t.strictEqual( v, 3.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `stride` parameter (accessors)', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]; + + v = rangeabs( 4, toAccessorArray( x ), 2, 0 ); + + t.strictEqual( v, 3.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + + v = rangeabs( 4, x, -2, 6 ); + + t.strictEqual( v, 3.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter (accessors)', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + + v = rangeabs( 4, toAccessorArray( x ), -2, 6 ); + + t.strictEqual( v, 3.0, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0.0`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = rangeabs( x.length, x, 0, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0.0` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = rangeabs( x.length, toAccessorArray( x ), 0, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `offset` parameter', function test( t ) { + var x; + var v; + + x = [ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0 // 3 + ]; + + v = rangeabs( 4, x, 2, 1 ); + t.strictEqual( v, 3.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `offset` parameter (accessors)', function test( t ) { + var x; + var v; + + x = [ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0 // 3 + ]; + + v = rangeabs( 4, toAccessorArray( x ), 2, 1 ); + t.strictEqual( v, 3.0, 'returns expected value' ); + + t.end(); +});