Skip to content

Commit 1b1c643

Browse files
committed
Auto-generated commit
1 parent e84d516 commit 1b1c643

File tree

11 files changed

+751
-1
lines changed

11 files changed

+751
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44

55
<section class="release" id="unreleased">
66

7-
## Unreleased (2026-01-01)
7+
## Unreleased (2026-01-02)
88

99
<section class="features">
1010

1111
### Features
1212

13+
- [`81f1cc5`](https://github.com/stdlib-js/stdlib/commit/81f1cc50d12dbb6ad9c0a198850ee56455c76db7) - add `stats/base/ndarray/nanmidrange` [(#9418)](https://github.com/stdlib-js/stdlib/pull/9418)
1314
- [`b06fcb7`](https://github.com/stdlib-js/stdlib/commit/b06fcb7281ace6b7d917fb124e514bf27dd9816f) - add `stats/strided/dmskmidrange` [(#9446)](https://github.com/stdlib-js/stdlib/pull/9446)
1415
- [`b1ea83c`](https://github.com/stdlib-js/stdlib/commit/b1ea83c92e4080906e3fdbd9530c4013142894ad) - add `stats/strided/nanmidrange-by` [(#9401)](https://github.com/stdlib-js/stdlib/pull/9401)
1516
- [`f4d072e`](https://github.com/stdlib-js/stdlib/commit/f4d072ea93759a1ddb497804a572a13158cdffb9) - add `stats/strided/snanmidrange` [(#9400)](https://github.com/stdlib-js/stdlib/pull/9400)
@@ -3543,6 +3544,7 @@ A total of 560 issues were closed in this release:
35433544

35443545
<details>
35453546

3547+
- [`81f1cc5`](https://github.com/stdlib-js/stdlib/commit/81f1cc50d12dbb6ad9c0a198850ee56455c76db7) - **feat:** add `stats/base/ndarray/nanmidrange` [(#9418)](https://github.com/stdlib-js/stdlib/pull/9418) _(by Sachin Pangal, stdlib-bot)_
35463548
- [`88af63a`](https://github.com/stdlib-js/stdlib/commit/88af63aa54165f09b84ef528cadc3dae622ab05a) - **docs:** replace manual `for` loop in examples [(#9444)](https://github.com/stdlib-js/stdlib/pull/9444) _(by Harsh Yadav)_
35473549
- [`edccce1`](https://github.com/stdlib-js/stdlib/commit/edccce1444f24145380aa51e8439f95928bda403) - **docs:** replace manual `for` loop in examples [(#9479)](https://github.com/stdlib-js/stdlib/pull/9479) _(by Harsh Yadav)_
35483550
- [`8caa497`](https://github.com/stdlib-js/stdlib/commit/8caa4973a29c819b20c60eb5d7e5127a9b3a15b9) - **chore:** clean-up, fix examples, and update tests _(by Athan Reines)_

base/ndarray/nanmidrange/README.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
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+
# nanmidrange
22+
23+
> Compute the [mid-range][mid-range] of a one-dimensional ndarray, ignoring `NaN` values.
24+
25+
<section class="intro">
26+
27+
The [**mid-range**][mid-range], or **mid-extreme**, is the arithmetic mean of the maximum and minimum values in a data set. The measure is the midpoint of the range and a measure of central tendency.
28+
29+
</section>
30+
31+
<!-- /.intro -->
32+
33+
<section class="usage">
34+
35+
## Usage
36+
37+
```javascript
38+
var nanmidrange = require( '@stdlib/stats/base/ndarray/nanmidrange' );
39+
```
40+
41+
#### nanmidrange( arrays )
42+
43+
Computes the [mid-range][mid-range] of a one-dimensional ndarray, ignoring `NaN` values.
44+
45+
```javascript
46+
var ndarray = require( '@stdlib/ndarray/base/ctor' );
47+
48+
var xbuf = [ 1.0, -2.0, NaN, 2.0 ];
49+
var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' );
50+
51+
var v = nanmidrange( [ x ] );
52+
// returns 0.0
53+
```
54+
55+
The function has the following parameters:
56+
57+
- **arrays**: array-like object containing a one-dimensional input ndarray.
58+
59+
</section>
60+
61+
<!-- /.usage -->
62+
63+
<section class="notes">
64+
65+
## Notes
66+
67+
- If provided an empty one-dimensional ndarray, the function returns `NaN`.
68+
69+
</section>
70+
71+
<!-- /.notes -->
72+
73+
<section class="examples">
74+
75+
## Examples
76+
77+
<!-- eslint no-undef: "error" -->
78+
79+
```javascript
80+
var uniform = require( '@stdlib/random/base/uniform' );
81+
var filledarrayBy = require( '@stdlib/array/filled-by' );
82+
var bernoulli = require( '@stdlib/random/base/bernoulli' );
83+
var ndarray = require( '@stdlib/ndarray/base/ctor' );
84+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
85+
var nanmidrange = require( '@stdlib/stats/base/ndarray/nanmidrange' );
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, 'generic', rand );
95+
var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' );
96+
console.log( ndarray2array( x ) );
97+
98+
var v = nanmidrange( [ x ] );
99+
console.log( v );
100+
```
101+
102+
</section>
103+
104+
<!-- /.examples -->
105+
106+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
107+
108+
<section class="related">
109+
110+
</section>
111+
112+
<!-- /.related -->
113+
114+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
115+
116+
<section class="links">
117+
118+
[mid-range]: https://en.wikipedia.org/wiki/Mid-range
119+
120+
</section>
121+
122+
<!-- /.links -->
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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 pkg = require( './../package.json' ).name;
31+
var nanmidrange = require( './../lib' );
32+
33+
34+
// FUNCTIONS //
35+
36+
/**
37+
* Returns a random number.
38+
*
39+
* @private
40+
* @returns {number} random number or `NaN`
41+
*/
42+
function rand() {
43+
if ( bernoulli( 0.8 ) < 1 ) {
44+
return NaN;
45+
}
46+
return uniform( -10.0, 10.0 );
47+
}
48+
49+
/**
50+
* Creates a benchmark function.
51+
*
52+
* @private
53+
* @param {PositiveInteger} len - array length
54+
* @returns {Function} benchmark function
55+
*/
56+
function createBenchmark( len ) {
57+
var xbuf;
58+
var x;
59+
60+
xbuf = filledarrayBy( len, 'generic', rand );
61+
x = new ndarray( 'generic', xbuf, [ len ], [ 1 ], 0, 'row-major' );
62+
63+
return benchmark;
64+
65+
function benchmark( b ) {
66+
var v;
67+
var i;
68+
69+
b.tic();
70+
for ( i = 0; i < b.iterations; i++ ) {
71+
v = nanmidrange( [ x ] );
72+
if ( isnan( v ) ) {
73+
b.fail( 'should not return NaN' );
74+
}
75+
}
76+
b.toc();
77+
if ( isnan( v ) ) {
78+
b.fail( 'should not return NaN' );
79+
}
80+
b.pass( 'benchmark finished' );
81+
b.end();
82+
}
83+
}
84+
85+
86+
// MAIN //
87+
88+
/**
89+
* Main execution sequence.
90+
*
91+
* @private
92+
*/
93+
function main() {
94+
var len;
95+
var min;
96+
var max;
97+
var f;
98+
var i;
99+
100+
min = 1; // 10^min
101+
max = 6; // 10^max
102+
103+
for ( i = min; i <= max; i++ ) {
104+
len = pow( 10, i );
105+
f = createBenchmark( len );
106+
bench( pkg+':len='+len, f );
107+
}
108+
}
109+
110+
main();
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
{{alias}}( arrays )
3+
Computes the mid-range of a one-dimensional ndarray, ignoring `NaN` values.
4+
5+
If provided an empty ndarray, the function returns `NaN`.
6+
7+
Parameters
8+
----------
9+
arrays: ArrayLikeObject<ndarray>
10+
Array-like object containing a one-dimensional input ndarray.
11+
12+
Returns
13+
-------
14+
out: number
15+
Mid-range.
16+
17+
Examples
18+
--------
19+
> var xbuf = [ 1.0, -2.0, 2.0 ];
20+
> var dt = 'generic';
21+
> var sh = [ xbuf.length ];
22+
> var sx = [ 1 ];
23+
> var ox = 0;
24+
> var ord = 'row-major';
25+
> var x = new {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, sx, ox, ord );
26+
> {{alias}}( [ x ] )
27+
0.0
28+
29+
See Also
30+
--------
31+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 { typedndarray } from '@stdlib/types/ndarray';
24+
25+
/**
26+
* Computes the mid-range of a one-dimensional ndarray, ignoring `NaN` values.
27+
*
28+
* @param arrays - array-like object containing an input ndarray
29+
* @returns mid-range
30+
*
31+
* @example
32+
* var ndarray = require( '@stdlib/ndarray/base/ctor' );
33+
*
34+
* var xbuf = [ 1.0, -2.0, NaN, 2.0 ];
35+
* var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' );
36+
*
37+
* var v = nanmidrange( [ x ] );
38+
* // returns 0.0
39+
*/
40+
declare function nanmidrange<T extends typedndarray<number> = typedndarray<number>>( arrays: [ T ] ): number;
41+
42+
43+
// EXPORTS //
44+
45+
export = nanmidrange;
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 nanmidrange = require( './index' );
23+
24+
25+
// TESTS //
26+
27+
// The function returns a number...
28+
{
29+
const x = zeros( [ 10 ], {
30+
'dtype': 'generic'
31+
});
32+
33+
nanmidrange( [ 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+
nanmidrange( '10' ); // $ExpectError
39+
nanmidrange( 10 ); // $ExpectError
40+
nanmidrange( true ); // $ExpectError
41+
nanmidrange( false ); // $ExpectError
42+
nanmidrange( null ); // $ExpectError
43+
nanmidrange( undefined ); // $ExpectError
44+
nanmidrange( [] ); // $ExpectError
45+
nanmidrange( {} ); // $ExpectError
46+
nanmidrange( ( 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': 'generic'
53+
});
54+
55+
nanmidrange(); // $ExpectError
56+
nanmidrange( [ x ], {} ); // $ExpectError
57+
}

0 commit comments

Comments
 (0)