Skip to content

Commit bd9c65f

Browse files
committed
Auto-generated commit
1 parent fee2b47 commit bd9c65f

File tree

11 files changed

+761
-0
lines changed

11 files changed

+761
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
### Features
1212

13+
- [`2c7da1c`](https://github.com/stdlib-js/stdlib/commit/2c7da1c4a81b3856be1724146b68ce8b4fb12f30) - add `stats/base/ndarray/dnanrangeabs` [(#11346)](https://github.com/stdlib-js/stdlib/pull/11346)
1314
- [`1588bf2`](https://github.com/stdlib-js/stdlib/commit/1588bf256bf277102e267b41a7d68c1798293b7e) - add `svariance` to namespace
1415
- [`d985063`](https://github.com/stdlib-js/stdlib/commit/d985063b6fc9348485640f52158bbea28c7e4b86) - add `stats/base/ndarray/svariance` [(#11510)](https://github.com/stdlib-js/stdlib/pull/11510)
1516
- [`66be61a`](https://github.com/stdlib-js/stdlib/commit/66be61a4af9d5aa12e2cc5a7acf6e9fae0030a27) - add `midrangeabs` to namespace
@@ -3798,6 +3799,7 @@ A total of 586 issues were closed in this release:
37983799

37993800
<details>
38003801

3802+
- [`2c7da1c`](https://github.com/stdlib-js/stdlib/commit/2c7da1c4a81b3856be1724146b68ce8b4fb12f30) - **feat:** add `stats/base/ndarray/dnanrangeabs` [(#11346)](https://github.com/stdlib-js/stdlib/pull/11346) _(by Sachin Pangal)_
38013803
- [`7be0aa6`](https://github.com/stdlib-js/stdlib/commit/7be0aa66fb4527b9d255e0d507427dc14f7fa151) - **docs:** improve doctests for ndarray instances in `stats/base/ndarray/scumax` [(#11531)](https://github.com/stdlib-js/stdlib/pull/11531) _(by Uday Kakade)_
38023804
- [`a6b67f6`](https://github.com/stdlib-js/stdlib/commit/a6b67f6978e82bbcb309c36dfda36a7d28b19fbf) - **docs:** improve doctests for ndarray instances in `stats/base/ndarray/scumin` [(#11532)](https://github.com/stdlib-js/stdlib/pull/11532) _(by Uday Kakade)_
38033805
- [`1588bf2`](https://github.com/stdlib-js/stdlib/commit/1588bf256bf277102e267b41a7d68c1798293b7e) - **feat:** add `svariance` to namespace _(by Athan Reines)_
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2026 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# dnanrangeabs
22+
23+
> Compute the [range][range] of absolute values of a one-dimensional double-precision floating-point ndarray, ignoring `NaN` values.
24+
25+
<section class="intro">
26+
27+
The [**range**][range] of absolute values is defined as the difference between the maximum and minimum absolute values.
28+
29+
</section>
30+
31+
<!-- /.intro -->
32+
33+
<section class="usage">
34+
35+
## Usage
36+
37+
```javascript
38+
var dnanrangeabs = require( '@stdlib/stats/base/ndarray/dnanrangeabs' );
39+
```
40+
41+
#### dnanrangeabs( arrays )
42+
43+
Computes the [range][range] of absolute values of a one-dimensional double-precision floating-point ndarray, ignoring `NaN` values.
44+
45+
```javascript
46+
var Float64Array = require( '@stdlib/array/float64' );
47+
var ndarray = require( '@stdlib/ndarray/base/ctor' );
48+
49+
var xbuf = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] );
50+
var x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' );
51+
52+
var v = dnanrangeabs( [ x ] );
53+
// returns 1.0
54+
```
55+
56+
The function has the following parameters:
57+
58+
- **arrays**: array-like object containing a one-dimensional input ndarray.
59+
60+
</section>
61+
62+
<!-- /.usage -->
63+
64+
<section class="notes">
65+
66+
## Notes
67+
68+
- If provided an empty one-dimensional ndarray, the function returns `NaN`.
69+
70+
</section>
71+
72+
<!-- /.notes -->
73+
74+
<section class="examples">
75+
76+
## Examples
77+
78+
<!-- eslint no-undef: "error" -->
79+
80+
```javascript
81+
var uniform = require( '@stdlib/random/base/uniform' );
82+
var filledarrayBy = require( '@stdlib/array/filled-by' );
83+
var bernoulli = require( '@stdlib/random/base/bernoulli' );
84+
var ndarray = require( '@stdlib/ndarray/base/ctor' );
85+
var dnanrangeabs = require( '@stdlib/stats/base/ndarray/dnanrangeabs' );
86+
87+
function rand() {
88+
if ( bernoulli( 0.8 ) < 1 ) {
89+
return NaN;
90+
}
91+
return uniform( -50.0, 50.0 );
92+
}
93+
94+
var xbuf = filledarrayBy( 10, 'float64', rand );
95+
var x = new ndarray( 'float64', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' );
96+
97+
var v = dnanrangeabs( [ x ] );
98+
console.log( v );
99+
```
100+
101+
</section>
102+
103+
<!-- /.examples -->
104+
105+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
106+
107+
<section class="related">
108+
109+
</section>
110+
111+
<!-- /.related -->
112+
113+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
114+
115+
<section class="links">
116+
117+
[range]: https://en.wikipedia.org/wiki/Range_%28statistics%29
118+
119+
</section>
120+
121+
<!-- /.links -->
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var uniform = require( '@stdlib/random/base/uniform' );
25+
var bernoulli = require( '@stdlib/random/base/bernoulli' );
26+
var filledarrayBy = require( '@stdlib/array/filled-by' );
27+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
28+
var pow = require( '@stdlib/math/base/special/pow' );
29+
var ndarray = require( '@stdlib/ndarray/base/ctor' );
30+
var format = require( '@stdlib/string/format' );
31+
var pkg = require( './../package.json' ).name;
32+
var dnanrangeabs = require( './../lib' );
33+
34+
35+
// FUNCTIONS //
36+
37+
/**
38+
* Returns a random number.
39+
*
40+
* @private
41+
* @returns {number} random number or `NaN`
42+
*/
43+
function rand() {
44+
if ( bernoulli( 0.8 ) < 1 ) {
45+
return NaN;
46+
}
47+
return uniform( -10.0, 10.0 );
48+
}
49+
50+
/**
51+
* Creates a benchmark function.
52+
*
53+
* @private
54+
* @param {PositiveInteger} len - array length
55+
* @returns {Function} benchmark function
56+
*/
57+
function createBenchmark( len ) {
58+
var xbuf;
59+
var x;
60+
61+
xbuf = filledarrayBy( len, 'float64', rand );
62+
x = new ndarray( 'float64', xbuf, [ len ], [ 1 ], 0, 'row-major' );
63+
64+
return benchmark;
65+
66+
/**
67+
* Benchmark function.
68+
*
69+
* @private
70+
* @param {Benchmark} b - benchmark instance
71+
*/
72+
function benchmark( b ) {
73+
var v;
74+
var i;
75+
76+
b.tic();
77+
for ( i = 0; i < b.iterations; i++ ) {
78+
v = dnanrangeabs( [ x ] );
79+
if ( isnan( v ) ) {
80+
b.fail( 'should not return NaN' );
81+
}
82+
}
83+
b.toc();
84+
if ( isnan( v ) ) {
85+
b.fail( 'should not return NaN' );
86+
}
87+
b.pass( 'benchmark finished' );
88+
b.end();
89+
}
90+
}
91+
92+
93+
// MAIN //
94+
95+
/**
96+
* Main execution sequence.
97+
*
98+
* @private
99+
*/
100+
function main() {
101+
var len;
102+
var min;
103+
var max;
104+
var f;
105+
var i;
106+
107+
min = 1; // 10^min
108+
max = 6; // 10^max
109+
110+
for ( i = min; i <= max; i++ ) {
111+
len = pow( 10, i );
112+
f = createBenchmark( len );
113+
bench( format( '%s:len=%d', pkg, len ), f );
114+
}
115+
}
116+
117+
main();
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
{{alias}}( arrays )
3+
Computes the range of absolute values of a one-dimensional double-precision
4+
floating-point ndarray, ignoring NaN values.
5+
6+
If provided an empty ndarray, the function returns `NaN`.
7+
8+
Parameters
9+
----------
10+
arrays: ArrayLikeObject<ndarray>
11+
Array-like object containing a one-dimensional input ndarray.
12+
13+
Returns
14+
-------
15+
out: number
16+
Range of absolute values.
17+
18+
Examples
19+
--------
20+
> var xbuf = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, NaN, 2.0 ] );
21+
> var dt = 'float64';
22+
> var sh = [ xbuf.length ];
23+
> var sx = [ 1 ];
24+
> var ox = 0;
25+
> var ord = 'row-major';
26+
> var x = new {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, sx, ox, ord );
27+
> {{alias}}( [ x ] )
28+
1.0
29+
30+
See Also
31+
--------
32+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
// TypeScript Version: 4.1
20+
21+
/// <reference types="@stdlib/types"/>
22+
23+
import { float64ndarray } from '@stdlib/types/ndarray';
24+
25+
/**
26+
* Computes the range of absolute values of a one-dimensional double-precision floating-point ndarray, ignoring NaN values.
27+
*
28+
* @param arrays - array-like object containing an input ndarray
29+
* @returns range of absolute values
30+
*
31+
* @example
32+
* var Float64Array = require( '@stdlib/array/float64' );
33+
* var ndarray = require( '@stdlib/ndarray/base/ctor' );
34+
*
35+
* var xbuf = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] );
36+
* var x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' );
37+
*
38+
* var v = dnanrangeabs( [ x ] );
39+
* // returns 1.0
40+
*/
41+
declare function dnanrangeabs( arrays: [ float64ndarray ] ): number;
42+
43+
44+
// EXPORTS //
45+
46+
export = dnanrangeabs;
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/* eslint-disable space-in-parens */
20+
21+
import zeros = require( '@stdlib/ndarray/zeros' );
22+
import dnanrangeabs = require( './index' );
23+
24+
25+
// TESTS //
26+
27+
// The function returns a number...
28+
{
29+
const x = zeros( [ 10 ], {
30+
'dtype': 'float64'
31+
});
32+
33+
dnanrangeabs( [ x ] ); // $ExpectType number
34+
}
35+
36+
// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays...
37+
{
38+
dnanrangeabs( '10' ); // $ExpectError
39+
dnanrangeabs( 10 ); // $ExpectError
40+
dnanrangeabs( true ); // $ExpectError
41+
dnanrangeabs( false ); // $ExpectError
42+
dnanrangeabs( null ); // $ExpectError
43+
dnanrangeabs( undefined ); // $ExpectError
44+
dnanrangeabs( [] ); // $ExpectError
45+
dnanrangeabs( {} ); // $ExpectError
46+
dnanrangeabs( ( x: number ): number => x ); // $ExpectError
47+
}
48+
49+
// The compiler throws an error if the function is provided an unsupported number of arguments...
50+
{
51+
const x = zeros( [ 10 ], {
52+
'dtype': 'float64'
53+
});
54+
55+
dnanrangeabs(); // $ExpectError
56+
dnanrangeabs( [ x ], {} ); // $ExpectError
57+
}

0 commit comments

Comments
 (0)