Skip to content
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
7c0f342
Create accessors.js
Kaushikgtm Mar 29, 2025
14f0a5f
Update accessors.js
Kaushikgtm Mar 29, 2025
7b487b1
Update nanrange_by.js
Kaushikgtm Mar 29, 2025
af57abf
Update ndarray.js
Kaushikgtm Mar 29, 2025
8f40fa3
Update test.nanrange_by.js
Kaushikgtm Mar 29, 2025
858f1ea
Update test.ndarray.js
Kaushikgtm Mar 29, 2025
d5f8c58
Update README.md
Kaushikgtm Mar 29, 2025
d0d1f6a
Update index.js
Kaushikgtm Mar 29, 2025
70b06be
Update index.d.ts
Kaushikgtm Mar 29, 2025
57ab24a
Update test.ts
Kaushikgtm Mar 29, 2025
a29bea7
Update repl.txt
Kaushikgtm Mar 29, 2025
752c833
Update benchmark.js
Kaushikgtm Mar 29, 2025
d2f1311
Update benchmark.ndarray.js
Kaushikgtm Mar 29, 2025
eb4442d
Update README.md
Kaushikgtm Mar 29, 2025
ff18103
Update README.md
Kaushikgtm Mar 30, 2025
530df0a
Update README.md
Kaushikgtm Mar 30, 2025
cdcf3f2
Update README.md
Kaushikgtm Mar 30, 2025
0bac446
Update README.md
Kaushikgtm Mar 30, 2025
b7b52a2
Update accessors.js
Kaushikgtm Mar 30, 2025
8920c66
Update ndarray.js
Kaushikgtm Mar 30, 2025
9008678
Update accessors.js
Kaushikgtm Mar 30, 2025
55a4cf2
Update README.md
Kaushikgtm Mar 30, 2025
acc496b
Merge remote-tracking branch 'upstream/develop' into Kaushikgtm-patch…
stdlib-bot Jun 8, 2025
fb9b3d1
Merge remote-tracking branch 'upstream/develop' into Kaushikgtm-patch…
stdlib-bot Jul 5, 2025
1c53e34
fix: readme file
gururaj1512 Jul 5, 2025
92e7a5d
fix: benchmarks
gururaj1512 Jul 5, 2025
945f05f
fix: update repl
gururaj1512 Jul 5, 2025
08534e6
fix: update type definitions for nanrangeBy
gururaj1512 Jul 5, 2025
ba4b452
fix: correct test.ts
gururaj1512 Jul 5, 2025
648f0e0
fix: examples
gururaj1512 Jul 5, 2025
bfaefbd
fix: implementation
gururaj1512 Jul 5, 2025
2c55276
chore: minor cleanup
gururaj1512 Jul 5, 2025
4b34ad3
fix: test files
gururaj1512 Jul 5, 2025
41df879
fix: ensure original input array is passed to callback
gururaj1512 Jul 5, 2025
22f5744
style: fix missing space
kgryte Jul 5, 2025
504d4f3
test: update description
kgryte Jul 5, 2025
fb50029
test: update desc
kgryte Jul 5, 2025
25fbf2d
test: update desc
kgryte Jul 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 19 additions & 21 deletions lib/node_modules/@stdlib/stats/base/nanrange-by/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ The [**range**][range] is defined as the difference between the maximum and mini
var nanrangeBy = require( '@stdlib/stats/base/nanrange-by' );
```

#### nanrangeBy( N, x, stride, clbk\[, thisArg] )
#### nanrangeBy( N, x, strideX, clbk\[, thisArg] )

Calculates the [range][range] of strided array `x` via a callback function, ignoring `NaN` values.
Computes the [range][range] of a strided array via a callback function, ignoring `NaN` values.

```javascript
function accessor( v ) {
Expand All @@ -57,7 +57,7 @@ The function has the following parameters:

- **N**: number of indexed elements.
- **x**: input [`Array`][mdn-array], [`typed array`][mdn-typed-array], or an array-like object (excluding strings and functions).
- **stride**: index increment.
- **strideX**: stride length.
- **clbk**: callback function.
- **thisArg**: execution context (_optional_).

Expand Down Expand Up @@ -89,27 +89,23 @@ var cnt = context.count;
// returns 10
```

The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to access every other element
The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to access every other element

```javascript
var floor = require( '@stdlib/math/base/special/floor' );

function accessor( v ) {
return v * 2.0;
}

var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0, NaN, NaN ];
var N = floor( x.length / 2 );

var v = nanrangeBy( N, x, 2, accessor );
var v = nanrangeBy( 5, x, 2, accessor );
// returns 12.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 floor = require( '@stdlib/math/base/special/floor' );

function accessor( v ) {
return v * 2.0;
Expand All @@ -120,16 +116,15 @@ var x0 = new Float64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] );

// Create an offset view...
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
var N = floor( x0.length/2 );

// Access every other element...
var v = nanrangeBy( N, x1, 2, accessor );
var v = nanrangeBy( 3, x1, 2, accessor );
// returns 8.0
```

#### nanrangeBy.ndarray( N, x, stride, offset, clbk\[, thisArg] )
#### nanrangeBy.ndarray( N, x, strideX, offsetX, clbk\[, thisArg] )

Calculates the [range][range] of strided array `x` via a callback function, ignoring `NaN` values and using alternative indexing semantics.
Computes the [range][range] of a strided array via a callback function, ignoring `NaN` values and using alternative indexing semantics.

```javascript
function accessor( v ) {
Expand All @@ -144,9 +139,9 @@ var v = nanrangeBy.ndarray( x.length, x, 1, 0, accessor );

The function has the following additional parameters:

- **offset**: starting index.
- **offsetX**: starting index.

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 access only the last three elements of `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 access only the last three elements of `x`

```javascript
function accessor( v ) {
Expand All @@ -171,6 +166,7 @@ var v = nanrangeBy.ndarray( 3, x, 1, x.length-3, accessor );
- A provided callback function should return a numeric value.
- If a provided callback function returns `NaN`, the value is ignored.
- If a provided callback function does not return any value (or equivalently, explicitly returns `undefined`), the value is ignored.
- 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]).
- When possible, prefer using [`dnanrange`][@stdlib/stats/strided/dnanrange], [`snanrange`][@stdlib/stats/strided/snanrange], and/or [`nanrange`][@stdlib/stats/base/nanrange], as, depending on the environment, these interfaces are likely to be significantly more performant.

</section>
Expand All @@ -184,23 +180,23 @@ var v = nanrangeBy.ndarray( 3, x, 1, x.length-3, accessor );
<!-- eslint no-undef: "error" -->

```javascript
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' );
var filledarrayBy = require( '@stdlib/array/filled-by' );
var bernoulli = require( '@stdlib/random/base/bernoulli' );
var nanrangeBy = require( '@stdlib/stats/base/nanrange-by' );

function fill() {
if ( randu() < 0.2 ) {
function rand() {
if ( bernoulli( 0.8 ) < 0.2 ) {
return NaN;
}
return discreteUniform( -50, 50 );
return uniform( -50.0, 50.0 );
}

function accessor( v ) {
return v * 2.0;
}

var x = filledarrayBy( 10, 'float64', fill );
var x = filledarrayBy( 10, 'float64', rand );
console.log( x );

var v = nanrangeBy( x.length, x, 1, accessor );
Expand Down Expand Up @@ -240,6 +236,8 @@ console.log( v );

[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray

[@stdlib/array/base/accessor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/accessor

<!-- <related-links> -->

[@stdlib/stats/strided/dnanrange]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/dnanrange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' );
var filledarrayBy = require( '@stdlib/array/filled-by' );
var bernoulli = require( '@stdlib/random/base/bernoulli' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var pkg = require( './../package.json' ).name;
var nanrangeBy = require( './../lib/nanrange_by.js' );
var nanrangeBy = require( './../lib/main.js' );


// FUNCTIONS //
Expand All @@ -41,6 +43,19 @@ function accessor( value ) {
return value * 2.0;
}

/**
* Returns a random number.
*
* @private
* @returns {number} random number
*/
function rand() {
if ( bernoulli( 0.8 ) < 1 ) {
return NaN;
}
return uniform( -50.0, 50.0 );
}

/**
* Create a benchmark function.
*
Expand All @@ -49,17 +64,7 @@ function accessor( value ) {
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var i;

x = [];
for ( i = 0; i < len; i++ ) {
if ( randu() < 0.2 ) {
x.push( NaN );
} else {
x.push( ( randu()*20.0 ) - 10.0 );
}
}
var x = filledarrayBy( len, 'generic', rand );
return benchmark;

function benchmark( b ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' );
var filledarrayBy = require( '@stdlib/array/filled-by' );
var bernoulli = require( '@stdlib/random/base/bernoulli' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var pkg = require( './../package.json' ).name;
Expand All @@ -41,6 +43,19 @@ function accessor( value ) {
return value * 2.0;
}

/**
* Returns a random number.
*
* @private
* @returns {number} random number
*/
function rand() {
if ( bernoulli( 0.8 ) < 1 ) {
return NaN;
}
return uniform( -50.0, 50.0 );
}

/**
* Create a benchmark function.
*
Expand All @@ -49,17 +64,7 @@ function accessor( value ) {
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var i;

x = [];
for ( i = 0; i < len; i++ ) {
if ( randu() < 0.2 ) {
x.push( NaN );
} else {
x.push( ( randu()*20.0 ) - 10.0 );
}
}
var x = filledarrayBy( len, 'generic', rand );
return benchmark;

function benchmark( b ) {
Expand Down
36 changes: 17 additions & 19 deletions lib/node_modules/@stdlib/stats/base/nanrange-by/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

{{alias}}( N, x, stride, clbk[, thisArg] )
Calculates the range of a strided array via a callback function, ignoring
{{alias}}( N, x, strideX, clbk[, thisArg] )
Computes the range of a strided array via a callback function, ignoring
`NaN` values.

The `N` and `stride` parameters determine which elements in `x` are accessed
at runtime.
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 typed
array views.
Expand Down Expand Up @@ -34,8 +34,8 @@
Input array/collection. If provided an object, the object must be array-
like (excluding strings and functions).

stride: integer
Index increment for `x`.
strideX: integer
Stride length.

clbk: Function
Callback function.
Expand All @@ -56,25 +56,24 @@
> {{alias}}( x.length, x, 1, accessor )
18.0

// Using `N` and `stride` parameters:
// Using `N` and stride parameters:
> x = [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0, 1.0 ];
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
> {{alias}}( N, x, 2, accessor )
> {{alias}}( 4, x, 2, accessor )
14.0

// Using view offsets:
> var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] );
> var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 );
> N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 );
> {{alias}}( N, x1, 2, accessor )
> {{alias}}( 3, x1, 2, accessor )
8.0

{{alias}}.ndarray( N, x, stride, offset, clbk[, thisArg] )

{{alias}}.ndarray( N, x, strideX, offsetX, clbk[, thisArg] )
Calculates the range of a strided array via a callback function, ignoring
`NaN` values and 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
buffer, the offset parameter supports indexing semantics based on a
starting index.

Parameters
Expand All @@ -86,11 +85,11 @@
Input array/collection. If provided an object, the object must be array-
like (excluding strings and functions).

stride: integer
Index increment for `x`.
strideX: integer
Stride length.

offset: integer
Starting index of `x`.
offsetX: integer
Starting index.

clbk: Function
Callback function.
Expand All @@ -113,8 +112,7 @@

// Using an index offset:
> x = [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ];
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
> {{alias}}.ndarray( N, x, 2, 1, accessor )
> {{alias}}.ndarray( 3, x, 2, 1, accessor )
8.0

See Also
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@

/// <reference types="@stdlib/types"/>

import { Collection } from '@stdlib/types/array';
import { Collection, AccessorArrayLike } from '@stdlib/types/array';

/**
* Input array.
*/
type InputArray<T> = Collection<T> | AccessorArrayLike<T>;

/**
* Returns an accessed value.
Expand Down Expand Up @@ -83,7 +88,7 @@ type Callback<T, U> = Nullary<U> | Unary<T, U> | Binary<T, U> | Ternary<T, U> |
*/
interface Routine {
/**
* Calculates the range of a strided array via a callback function, ignoring `NaN` values.
* Computes the range of a strided array via a callback function, ignoring `NaN` values.
*
* ## Notes
*
Expand All @@ -102,7 +107,7 @@ interface Routine {
*
* @param N - number of indexed elements
* @param x - input array
* @param stride - stride length
* @param strideX - stride length
* @param clbk - callback
* @param thisArg - execution context
* @returns range
Expand All @@ -117,10 +122,10 @@ interface Routine {
* var v = nanrangeBy( x.length, x, 1, accessor );
* // returns 18.0
*/
<T = unknown, U = unknown>( N: number, x: Collection<T>, stride: number, clbk: Callback<T, U>, thisArg?: ThisParameterType<Callback<T, U>> ): number;
<T = unknown, U = unknown>( N: number, x: InputArray<T>, strideX: number, clbk: Callback<T, U>, thisArg?: ThisParameterType<Callback<T, U>> ): number;

/**
* Calculates the range of a strided array via a callback function, ignoring `NaN` values and using alternative indexing semantics.
* Computes the range of a strided array via a callback function, ignoring `NaN` values and using alternative indexing semantics.
*
* ## Notes
*
Expand All @@ -139,8 +144,8 @@ interface Routine {
*
* @param N - number of indexed elements
* @param x - input array
* @param stride - stride length
* @param offset - starting index
* @param strideX - stride length
* @param offsetX - starting index
* @param clbk - callback
* @param thisArg - execution context
* @returns range
Expand All @@ -155,11 +160,11 @@ interface Routine {
* var v = nanrangeBy.ndarray( x.length, x, 1, 0, accessor );
* // returns 18.0
*/
ndarray<T = unknown, U = unknown>( N: number, x: Collection<T>, stride: number, offset: number, clbk: Callback<T, U>, thisArg?: ThisParameterType<Callback<T, U>> ): number;
ndarray<T = unknown, U = unknown>( N: number, x: InputArray<T>, strideX: number, offsetX: number, clbk: Callback<T, U>, thisArg?: ThisParameterType<Callback<T, U>> ): number;
}

/**
* Calculates the range of a strided array via a callback function, ignoring `NaN` values.
* Computes the range of a strided array via a callback function, ignoring `NaN` values.
*
* ## Notes
*
Expand All @@ -178,7 +183,7 @@ interface Routine {
*
* @param N - number of indexed elements
* @param x - input array
* @param stride - stride length
* @param strideX - stride length
* @param clbk - callback
* @param thisArg - execution context
* @returns range
Expand Down
Loading