Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
0dac229
Update ndarray.js
Kaushikgtm Mar 13, 2025
1d4d0fa
Update nanminabs.js
Kaushikgtm Mar 13, 2025
ab2d094
Update main.js
Kaushikgtm Mar 13, 2025
9405254
Create accessors.js
Kaushikgtm Mar 13, 2025
e5f5847
Update benchmark.js
Kaushikgtm Mar 13, 2025
6d6d131
Update benchmark.ndarray.js
Kaushikgtm Mar 13, 2025
1b70250
Update README.md
Kaushikgtm Mar 13, 2025
8b839c0
Update test.ndarray.js
Kaushikgtm Mar 13, 2025
545f23a
Update test.nanminabs.js
Kaushikgtm Mar 13, 2025
1a1eff4
Update test.js
Kaushikgtm Mar 13, 2025
4b58244
fixed linting error in accessors.js
Kaushikgtm Mar 13, 2025
2021fb2
Update accessors.js
Kaushikgtm Mar 13, 2025
454fa59
Update main.js
Kaushikgtm Mar 13, 2025
eff537d
Update test.nanminabs.js
Kaushikgtm Mar 13, 2025
b1b03bb
Update accessors.js
Kaushikgtm Mar 13, 2025
d7a27f1
Update accessors.js
Kaushikgtm Mar 13, 2025
ca5a80e
Update accessors.js
Kaushikgtm Mar 13, 2025
37f384b
Update accessors.js
Kaushikgtm Mar 13, 2025
3e64cdf
Update accessors.js
Kaushikgtm Mar 14, 2025
e36963b
Update test.nanminabs.js
Kaushikgtm Mar 14, 2025
1a633de
Update accessors.js
Kaushikgtm Mar 14, 2025
630d5c1
Update accessors.js
Kaushikgtm Mar 14, 2025
b57c07f
Update accessors.js
Kaushikgtm Mar 14, 2025
7cfc267
Update test.nanminabs.js
Kaushikgtm Mar 14, 2025
07a4746
Update accessors.js
Kaushikgtm Mar 14, 2025
b334a81
Update accessors.js
Kaushikgtm Mar 14, 2025
edb144f
Update test.nanminabs.js
Kaushikgtm Mar 14, 2025
e7cbe1f
Update accessors.js
Kaushikgtm Mar 14, 2025
cf21233
Update test.nanminabs.js
Kaushikgtm Mar 14, 2025
a18dff7
Update nanminabs.js
Kaushikgtm Mar 14, 2025
26b6782
Update accessors.js
Kaushikgtm Mar 14, 2025
0aa0d87
Update nanminabs.js
Kaushikgtm Mar 14, 2025
3691d9a
Update accessors.js
Kaushikgtm Mar 14, 2025
c9d41d4
Update accessors.js
Kaushikgtm Mar 14, 2025
8f5dd42
Update accessors.js
Kaushikgtm Mar 14, 2025
bd4ea7e
Update accessors.js
Kaushikgtm Mar 14, 2025
4a87274
Update ndarray.js
Kaushikgtm Mar 14, 2025
6bcc5db
Update nanminabs.js
Kaushikgtm Mar 14, 2025
9829b3e
Update nanminabs.js
Kaushikgtm Mar 16, 2025
14d8d80
Update ndarray.js
Kaushikgtm Mar 16, 2025
450acfe
Update test.ndarray.js
Kaushikgtm Mar 16, 2025
86e2ef2
Update ndarray.js
Kaushikgtm Mar 16, 2025
103f95a
Update test.ndarray.js
Kaushikgtm Mar 16, 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
12 changes: 6 additions & 6 deletions lib/node_modules/@stdlib/stats/base/nanminabs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

@license Apache-2.0

Copyright (c) 2020 The Stdlib Authors.
Copyright (c) 2025 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.
Expand Down Expand Up @@ -36,7 +36,7 @@ limitations under the License.
var nanminabs = require( '@stdlib/stats/base/nanminabs' );
```

#### nanminabs( N, x, stride )
#### nanminabs( N, x, strideX )

Computes the minimum absolute value of a strided array `x`, ignoring `NaN` values.

Expand All @@ -54,7 +54,7 @@ The function has the following parameters:
- **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array].
- **stride**: index increment for `x`.

The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to compute the minimum absolute value of every other element in `x`,
The `N` and `strideX` parameters determine which elements in `x` are accessed at runtime. For example, to compute the minimum absolute value of every other element in `x`,

```javascript
var floor = require( '@stdlib/math/base/special/floor' );
Expand Down Expand Up @@ -83,7 +83,7 @@ var v = nanminabs( N, x1, 2 );
// returns 1.0
```

#### nanminabs.ndarray( N, x, stride, offset )
#### nanminabs.ndarray( N, x, strideX, offsetX )

Computes the minimum absolute value of a strided array, ignoring `NaN` values and using alternative indexing semantics.

Expand All @@ -97,9 +97,9 @@ var v = nanminabs.ndarray( N, x, 1, 0 );

The function has the following additional parameters:

- **offset**: starting index for `x`.
- **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 minimum absolute value for every other value in `x` starting from the second value
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offsetX` parameter supports indexing semantics based on a starting index. For example, to calculate the minimum absolute value for every other value in `x` starting from the second value

```javascript
var floor = require( '@stdlib/math/base/special/floor' );
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2020 The Stdlib Authors.
* Copyright (c) 2025 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.
Expand All @@ -21,13 +21,16 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
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 pkg = require( './../package.json' ).name;
var nanminabs = require( './../lib/nanminabs.js' );


// VARIABLES //
var options = {
'dtype': 'generic'
};
// FUNCTIONS //

/**
Expand All @@ -38,17 +41,7 @@ var nanminabs = require( './../lib/nanminabs.js' );
* @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 = uniform( len, -10, 10, options );
return benchmark;

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

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
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 pkg = require( './../package.json' ).name;
var nanminabs = require( './../lib/ndarray.js' );

// VARIABLES //
var options = {
'dtype': 'generic'
};

// FUNCTIONS //

Expand All @@ -38,17 +42,7 @@ var nanminabs = require( './../lib/ndarray.js' );
* @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 = uniform( len, -10, 10, options );
return benchmark;

function benchmark( b ) {
Expand Down
95 changes: 95 additions & 0 deletions lib/node_modules/@stdlib/stats/base/nanminabs/lib/accessors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2025 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 minimum absolute value of a strided array, ignoring `NaN` values.
* Supports accessor protocol.
*
* @param {PositiveInteger} N - number of indexed elements
* @param {Object} x - input array object
* @param {Collection} x.data - input array data
* @param {Array<Function>} x.accessors - array element accessors
* @param {integer} strideX - stride length for `x`
* @param {NonNegativeInteger} offsetX - starting index for `x`
* @returns {Object} output array object
*
* @example
* var x = { data: [ -3.0, NaN, 2.0, -1.0 ], accessors: [ ( arr, i ) => arr[ i ] ] };
* var minAbs = nanminabs( 4, x, 1, 0 );
* // returns 1.0
*/
function nanminabs( N, x, strideX, offsetX ) {
var xbuf;
var get;
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 ) {
return ((get) ?
abs( get( xbuf, offsetX) ) :
abs( xbuf[offsetX] ) );
}

ix = offsetX;
for ( i = 0; i < N; i++ ) {
v = ((get) ? get(xbuf, ix) : xbuf[ix]);
if ( v === v ) {
break;
}
ix += strideX;
}
if ( i === N ) {
return NaN;
}
min = abs( v );

for ( i += 1; i < N; i++ ) {
ix += strideX;
v = ((get) ? get(xbuf, ix) : xbuf[ix]);
v = abs( v );
if ( isnan( v ) ) {
continue;
}
if ( v < min ) {
min = v;
}
}
return min;
}


// EXPORTS //

module.exports = nanminabs;
26 changes: 21 additions & 5 deletions lib/node_modules/@stdlib/stats/base/nanminabs/lib/main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2020 The Stdlib Authors.
* Copyright (c) 2025 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.
Expand All @@ -20,16 +20,32 @@

// MODULES //

var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
var nanminabs = require( './nanminabs.js' );
var ndarray = require( './ndarray.js' );

var stride2offset = require( '@stdlib/strided/base/stride2offset' );

Check failure on line 25 in lib/node_modules/@stdlib/stats/base/nanminabs/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

`require( '@stdlib/strided/base/stride2offset' )` should come before `require( './nanminabs.js' )`
var setReadOnly = require( '@stdlib/utils/define-read-only-property' );

Check failure on line 26 in lib/node_modules/@stdlib/stats/base/nanminabs/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

`require( '@stdlib/utils/define-read-only-property' )` should come before `require( './nanminabs.js' )`

// MAIN //

Check failure on line 28 in lib/node_modules/@stdlib/stats/base/nanminabs/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Header comment must be preceded by one additional empty line

/**

Check failure on line 29 in lib/node_modules/@stdlib/stats/base/nanminabs/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Encountered an error while running code: `min is not defined`.Did you mean to include a `// throws <ReferenceError>` annotation instead of `// returns -2.0`?
* Computes the minimum absolute value of a strided array.
*
* @param {PositiveInteger} N - number of indexed elements
* @param {NumericArray} x - input array
* @param {integer} strideX - stride length
* @returns {number} minimum absolute value
*
* @example
* var x = [ 1.0, -2.0, 2.0 ];
* var N = x.length;
*
* var v = min( N, x, 1 );
* // returns -2.0
*/
setReadOnly( nanminabs, 'ndarray', ndarray );

function nanminabs( N, x, strideX ) {

Check failure on line 45 in lib/node_modules/@stdlib/stats/base/nanminabs/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

nanminabs is already defined

Check failure on line 45 in lib/node_modules/@stdlib/stats/base/nanminabs/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Missing JSDoc comment
return ndarray( N, x, strideX, stride2offset( N, strideX ) );

Check failure on line 46 in lib/node_modules/@stdlib/stats/base/nanminabs/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Expected indentation of 1 tab but found 6 spaces
}

// EXPORTS //

Check failure on line 49 in lib/node_modules/@stdlib/stats/base/nanminabs/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Header comment must be preceded by one additional empty line

module.exports = nanminabs;
44 changes: 31 additions & 13 deletions lib/node_modules/@stdlib/stats/base/nanminabs/lib/nanminabs.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2020 The Stdlib Authors.
* Copyright (c) 2025 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.
Expand All @@ -22,6 +22,8 @@

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 //
Expand All @@ -31,7 +33,8 @@ var abs = require( '@stdlib/math/base/special/abs' );
*
* @param {PositiveInteger} N - number of indexed elements
* @param {NumericArray} x - input array
* @param {integer} stride - stride length
* @param {integer} strideX - stride length
* @param {NonNegativeInteger} offsetX - starting index for `x`
* @returns {number} minimum absolute value
*
* @example
Expand All @@ -41,41 +44,56 @@ var abs = require( '@stdlib/math/base/special/abs' );
* var v = nanminabs( N, x, 1 );
* // returns 1.0
*/
function nanminabs( N, x, stride ) {
function nanminabs( N, x, strideX, offsetX ) {
var min;
var o;
var ix;
var v;
var i;

if ( N <= 0 ) {
return NaN;
}
if ( N === 1 || stride === 0 ) {
return abs( x[ 0 ] );
o = arraylike2object( x );
if ( o.accessorProtocol ) {
return accessors( N, o, strideX, offsetX );
}
if ( stride < 0 ) {
ix = (1-N) * stride;

if ( N === 1 || strideX === 0 ) {
v = x[ offsetX ];
return isnan( v ) ? NaN : abs( v );
}

if ( strideX < 0 ) {
ix = offsetX + (N-1) * strideX;
} else {
ix = 0;
ix = offsetX;
}

// Find the first non-NaN value:
for ( i = 0; i < N; i++ ) {
v = x[ ix ];
if ( v === v ) {
if ( !isnan( v ) ) {
break;
}
ix += stride;
ix += strideX;
}
if ( i === N ) {
return NaN;
}

// Initialize min with the first non-NaN value:
min = abs( v );
i += 1;
for ( i; i < N; i++ ) {
ix += stride;
v = abs( x[ ix ] );

// Iterate through the remaining elements:
for ( ; i < N; i++ ) {
ix += strideX;
v = x[ ix ];
if ( isnan( v ) ) {
continue;
}
v = abs( v );
if ( v < min ) {
min = v;
}
Expand Down
Loading
Loading