Skip to content

Commit 8986ee9

Browse files
committed
Auto-generated commit
1 parent 966f1f5 commit 8986ee9

File tree

11 files changed

+762
-0
lines changed

11 files changed

+762
-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+
- [`8107a5a`](https://github.com/stdlib-js/stdlib/commit/8107a5a755bbdeb69c8110a2dbc9ed1a39d136c9) - add `stats/base/ndarray/dnanmidrange` [(#9504)](https://github.com/stdlib-js/stdlib/pull/9504)
1314
- [`fb7c43e`](https://github.com/stdlib-js/stdlib/commit/fb7c43e10a7a6f10f2677fa7ea1790fff535c968) - add `stats/strided/smskmidrange` [(#9492)](https://github.com/stdlib-js/stdlib/pull/9492)
1415
- [`81f1cc5`](https://github.com/stdlib-js/stdlib/commit/81f1cc50d12dbb6ad9c0a198850ee56455c76db7) - add `stats/base/ndarray/nanmidrange` [(#9418)](https://github.com/stdlib-js/stdlib/pull/9418)
1516
- [`b06fcb7`](https://github.com/stdlib-js/stdlib/commit/b06fcb7281ace6b7d917fb124e514bf27dd9816f) - add `stats/strided/dmskmidrange` [(#9446)](https://github.com/stdlib-js/stdlib/pull/9446)
@@ -3545,6 +3546,7 @@ A total of 560 issues were closed in this release:
35453546

35463547
<details>
35473548

3549+
- [`8107a5a`](https://github.com/stdlib-js/stdlib/commit/8107a5a755bbdeb69c8110a2dbc9ed1a39d136c9) - **feat:** add `stats/base/ndarray/dnanmidrange` [(#9504)](https://github.com/stdlib-js/stdlib/pull/9504) _(by Sachin Pangal)_
35483550
- [`fb7c43e`](https://github.com/stdlib-js/stdlib/commit/fb7c43e10a7a6f10f2677fa7ea1790fff535c968) - **feat:** add `stats/strided/smskmidrange` [(#9492)](https://github.com/stdlib-js/stdlib/pull/9492) _(by Sachin Pangal, Athan Reines, stdlib-bot)_
35493551
- [`c026135`](https://github.com/stdlib-js/stdlib/commit/c0261358afbc15c908bd276eb789f86f9d90ffaa) - **style:** remove empty line [(#9507)](https://github.com/stdlib-js/stdlib/pull/9507) _(by stdlib-bot)_
35503552
- [`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)_
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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+
# dnanmidrange
22+
23+
> Compute the [mid-range][mid-range] of a one-dimensional double-precision floating-point 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 dnanmidrange = require( '@stdlib/stats/base/ndarray/dnanmidrange' );
39+
```
40+
41+
#### dnanmidrange( arrays )
42+
43+
Computes the [mid-range][mid-range] 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 = dnanmidrange( [ x ] );
53+
// returns 0.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 ndarray2array = require( '@stdlib/ndarray/to-array' );
86+
var dnanmidrange = require( '@stdlib/stats/base/ndarray/dnanmidrange' );
87+
88+
function rand() {
89+
if ( bernoulli( 0.8 ) < 1 ) {
90+
return NaN;
91+
}
92+
return uniform( -50.0, 50.0 );
93+
}
94+
95+
var xbuf = filledarrayBy( 10, 'float64', rand );
96+
var x = new ndarray( 'float64', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' );
97+
console.log( ndarray2array( x ) );
98+
99+
var v = dnanmidrange( [ x ] );
100+
console.log( v );
101+
```
102+
103+
</section>
104+
105+
<!-- /.examples -->
106+
107+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
108+
109+
<section class="related">
110+
111+
</section>
112+
113+
<!-- /.related -->
114+
115+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
116+
117+
<section class="links">
118+
119+
[mid-range]: https://en.wikipedia.org/wiki/Mid-range
120+
121+
</section>
122+
123+
<!-- /.links -->
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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 format = require( '@stdlib/string/format' );
30+
var ndarray = require( '@stdlib/ndarray/base/ctor' );
31+
var pkg = require( './../package.json' ).name;
32+
var dnanmidrange = 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+
function benchmark( b ) {
67+
var v;
68+
var i;
69+
70+
b.tic();
71+
for ( i = 0; i < b.iterations; i++ ) {
72+
v = dnanmidrange( [ x ] );
73+
if ( isnan( v ) ) {
74+
b.fail( 'should not return NaN' );
75+
}
76+
}
77+
b.toc();
78+
if ( isnan( v ) ) {
79+
b.fail( 'should not return NaN' );
80+
}
81+
b.pass( 'benchmark finished' );
82+
b.end();
83+
}
84+
}
85+
86+
87+
// MAIN //
88+
89+
/**
90+
* Main execution sequence.
91+
*
92+
* @private
93+
*/
94+
function main() {
95+
var len;
96+
var min;
97+
var max;
98+
var f;
99+
var i;
100+
101+
min = 1; // 10^min
102+
max = 6; // 10^max
103+
104+
for ( i = min; i <= max; i++ ) {
105+
len = pow( 10, i );
106+
f = createBenchmark( len );
107+
bench( format( '%s:len=%d', pkg, len ), f );
108+
}
109+
}
110+
111+
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 mid-range of a one-dimensional double-precision floating-point
4+
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+
Mid-range.
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+
0.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 mid-range 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 mid-range
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 = dnanmidrange( [ x ] );
39+
* // returns 0.0
40+
*/
41+
declare function dnanmidrange( arrays: [ float64ndarray ] ): number;
42+
43+
44+
// EXPORTS //
45+
46+
export = dnanmidrange;
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 dnanmidrange = 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+
dnanmidrange( [ 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+
dnanmidrange( '10' ); // $ExpectError
39+
dnanmidrange( 10 ); // $ExpectError
40+
dnanmidrange( true ); // $ExpectError
41+
dnanmidrange( false ); // $ExpectError
42+
dnanmidrange( null ); // $ExpectError
43+
dnanmidrange( undefined ); // $ExpectError
44+
dnanmidrange( [] ); // $ExpectError
45+
dnanmidrange( {} ); // $ExpectError
46+
dnanmidrange( ( 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+
dnanmidrange(); // $ExpectError
56+
dnanmidrange( [ x ], {} ); // $ExpectError
57+
}

0 commit comments

Comments
 (0)