Skip to content

Commit 0dac229

Browse files
authored
Update ndarray.js
Signed-off-by: Kaushikgtm <[email protected]>
1 parent 87abb74 commit 0dac229

File tree

1 file changed

+16
-10
lines changed
  • lib/node_modules/@stdlib/stats/base/nanminabs/lib

1 file changed

+16
-10
lines changed

lib/node_modules/@stdlib/stats/base/nanminabs/lib/ndarray.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2020 The Stdlib Authors.
4+
* Copyright (c) 2025 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -22,6 +22,8 @@
2222

2323
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2424
var abs = require( '@stdlib/math/base/special/abs' );
25+
var arraylike2object = require( '@stdlib/array/base/arraylike2object' );
26+
var accessors = require( './accessors.js' );
2527

2628

2729
// MAIN //
@@ -31,8 +33,8 @@ var abs = require( '@stdlib/math/base/special/abs' );
3133
*
3234
* @param {PositiveInteger} N - number of indexed elements
3335
* @param {NumericArray} x - input array
34-
* @param {integer} stride - stride length
35-
* @param {NonNegativeInteger} offset - starting index
36+
* @param {integer} strideX - stride length
37+
* @param {NonNegativeInteger} offsetX - starting index
3638
* @returns {number} minimum absolute value
3739
*
3840
* @example
@@ -44,33 +46,38 @@ var abs = require( '@stdlib/math/base/special/abs' );
4446
* var v = nanminabs( N, x, 2, 1 );
4547
* // returns 1.0
4648
*/
47-
function nanminabs( N, x, stride, offset ) {
49+
function nanminabs( N, x, strideX, offsetX ) {
4850
var min;
51+
var o;
4952
var ix;
5053
var v;
5154
var i;
5255

5356
if ( N <= 0 ) {
5457
return NaN;
5558
}
56-
if ( N === 1 || stride === 0 ) {
57-
return x[ offset ];
59+
o = arraylike2object( x );
60+
if ( o.accessorProtocol ) {
61+
return accessors( N, o, strideX, offsetX );
5862
}
59-
ix = offset;
63+
if ( N === 1 || strideX === 0 ) {
64+
return abs(x[ offsetX ]);
65+
}
66+
ix = offsetX + (strideX < 0 ? (N - 1) * strideX : 0);
6067
for ( i = 0; i < N; i++ ) {
6168
v = x[ ix ];
6269
if ( v === v ) {
6370
break;
6471
}
65-
ix += stride;
72+
ix += strideX;
6673
}
6774
if ( i === N ) {
6875
return NaN;
6976
}
7077
min = abs( v );
7178
i += 1;
7279
for ( i; i < N; i++ ) {
73-
ix += stride;
80+
ix += strideX;
7481
v = abs( x[ ix ] );
7582
if ( isnan( v ) ) {
7683
continue;
@@ -82,7 +89,6 @@ function nanminabs( N, x, stride, offset ) {
8289
return min;
8390
}
8491

85-
8692
// EXPORTS //
8793

8894
module.exports = nanminabs;

0 commit comments

Comments
 (0)