Skip to content

Commit 59c3513

Browse files
committed
Auto-generated commit
1 parent 0c0af56 commit 59c3513

File tree

11 files changed

+847
-0
lines changed

11 files changed

+847
-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+
- [`d681872`](https://github.com/stdlib-js/stdlib/commit/d681872a9b87321f4f66852f5aabfeec19e195fc) - add `stats/base/ndarray/mskmidrange` [(#9511)](https://github.com/stdlib-js/stdlib/pull/9511)
1314
- [`c824fea`](https://github.com/stdlib-js/stdlib/commit/c824feae2f1582ff59f0d3bee99896fa77ef1f81) - add `stats/base/ndarray/snanmidrange` [(#9505)](https://github.com/stdlib-js/stdlib/pull/9505)
1415
- [`8107a5a`](https://github.com/stdlib-js/stdlib/commit/8107a5a755bbdeb69c8110a2dbc9ed1a39d136c9) - add `stats/base/ndarray/dnanmidrange` [(#9504)](https://github.com/stdlib-js/stdlib/pull/9504)
1516
- [`fb7c43e`](https://github.com/stdlib-js/stdlib/commit/fb7c43e10a7a6f10f2677fa7ea1790fff535c968) - add `stats/strided/smskmidrange` [(#9492)](https://github.com/stdlib-js/stdlib/pull/9492)
@@ -3548,6 +3549,7 @@ A total of 562 issues were closed in this release:
35483549

35493550
<details>
35503551

3552+
- [`d681872`](https://github.com/stdlib-js/stdlib/commit/d681872a9b87321f4f66852f5aabfeec19e195fc) - **feat:** add `stats/base/ndarray/mskmidrange` [(#9511)](https://github.com/stdlib-js/stdlib/pull/9511) _(by Sachin Pangal)_
35513553
- [`c824fea`](https://github.com/stdlib-js/stdlib/commit/c824feae2f1582ff59f0d3bee99896fa77ef1f81) - **feat:** add `stats/base/ndarray/snanmidrange` [(#9505)](https://github.com/stdlib-js/stdlib/pull/9505) _(by Sachin Pangal)_
35523554
- [`c7b5670`](https://github.com/stdlib-js/stdlib/commit/c7b567035c988493c48a6f305b535d6510e72501) - **chore:** fix EditorConfig lint errors [(#9528)](https://github.com/stdlib-js/stdlib/pull/9528) _(by Shreelaxmi Hegde)_
35533555
- [`a27671f`](https://github.com/stdlib-js/stdlib/commit/a27671f8fc907e4f054086e3e422234ed56964cd) - **docs:** update string interpolation in various `stats/base/dists` examples [(#9533)](https://github.com/stdlib-js/stdlib/pull/9533) _(by Harsh Yadav)_

base/ndarray/mskmidrange/README.md

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
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+
# mskmidrange
22+
23+
> Calculate the [mid-range][mid-range] of a one-dimensional ndarray according to a mask.
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 mskmidrange = require( '@stdlib/stats/base/ndarray/mskmidrange' );
39+
```
40+
41+
#### mskmidrange( arrays )
42+
43+
Computes the [mid-range][mid-range] of a one-dimensional ndarray according to a mask.
44+
45+
```javascript
46+
var ndarray = require( '@stdlib/ndarray/base/ctor' );
47+
48+
var xbuf = [ 1.0, -2.0, 4.0, 2.0 ];
49+
var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' );
50+
51+
var maskbuf = [ 0, 0, 1, 0 ];
52+
var mask = new ndarray( 'generic', maskbuf, [ 4 ], [ 1 ], 0, 'row-major' );
53+
54+
var v = mskmidrange( [ x, mask ] );
55+
// returns 0.0
56+
```
57+
58+
The function has the following parameters:
59+
60+
- **arrays**: array-like object containing an input ndarray and a mask ndarray.
61+
62+
If a `mask` array element is `0`, the corresponding element in the input ndarray is considered valid and **included** in computation. If a `mask` array element is `1`, the corresponding element in the input ndarray is considered invalid/missing and **excluded** from computation.
63+
64+
</section>
65+
66+
<!-- /.usage -->
67+
68+
<section class="notes">
69+
70+
## Notes
71+
72+
- If provided an empty ndarray or a mask with all elements set to `1`, the function returns `NaN`.
73+
74+
</section>
75+
76+
<!-- /.notes -->
77+
78+
<section class="examples">
79+
80+
## Examples
81+
82+
<!-- eslint no-undef: "error" -->
83+
84+
```javascript
85+
var uniform = require( '@stdlib/random/array/uniform' );
86+
var bernoulli = require( '@stdlib/random/array/bernoulli' );
87+
var ndarray = require( '@stdlib/ndarray/base/ctor' );
88+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
89+
var mskmidrange = require( '@stdlib/stats/base/ndarray/mskmidrange' );
90+
91+
var xbuf = uniform( 10, -50.0, 50.0, {
92+
'dtype': 'generic'
93+
});
94+
var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' );
95+
console.log( ndarray2array( x ) );
96+
97+
var maskbuf = bernoulli( xbuf.length, 0.2, {
98+
'dtype': 'uint8'
99+
});
100+
var mask = new ndarray( 'uint8', maskbuf, [ maskbuf.length ], [ 1 ], 0, 'row-major' );
101+
console.log( ndarray2array( mask ) );
102+
103+
var v = mskmidrange( [ x, mask ] );
104+
console.log( v );
105+
```
106+
107+
</section>
108+
109+
<!-- /.examples -->
110+
111+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
112+
113+
<section class="related">
114+
115+
</section>
116+
117+
<!-- /.related -->
118+
119+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
120+
121+
<section class="links">
122+
123+
[mid-range]: https://en.wikipedia.org/wiki/Mid-range
124+
125+
</section>
126+
127+
<!-- /.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/array/uniform' );
25+
var bernoulli = require( '@stdlib/random/array/bernoulli' );
26+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
27+
var pow = require( '@stdlib/math/base/special/pow' );
28+
var ndarray = require( '@stdlib/ndarray/base/ctor' );
29+
var format = require( '@stdlib/string/format' );
30+
var pkg = require( './../package.json' ).name;
31+
var mskmidrange = require( './../lib' );
32+
33+
34+
// VARIABLES //
35+
36+
var options = {
37+
'dtype': 'generic'
38+
};
39+
40+
41+
// FUNCTIONS //
42+
43+
/**
44+
* Creates a benchmark function.
45+
*
46+
* @private
47+
* @param {PositiveInteger} len - array length
48+
* @returns {Function} benchmark function
49+
*/
50+
function createBenchmark( len ) {
51+
var mask;
52+
var mbuf;
53+
var xbuf;
54+
var x;
55+
56+
xbuf = uniform( len, -100.0, 100.0, options );
57+
x = new ndarray( options.dtype, xbuf, [ len ], [ 1 ], 0, 'row-major' );
58+
59+
mbuf = bernoulli( len, 0.2, options );
60+
mask = new ndarray( options.dtype, mbuf, [ len ], [ 1 ], 0, 'row-major' );
61+
62+
return benchmark;
63+
64+
function benchmark( b ) {
65+
var v;
66+
var i;
67+
68+
b.tic();
69+
for ( i = 0; i < b.iterations; i++ ) {
70+
xbuf[ i%len ] = i;
71+
v = mskmidrange( [ x, mask ] );
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( format( '%s:len=%d', pkg, len ), f );
107+
}
108+
}
109+
110+
main();
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
{{alias}}( arrays )
3+
Calculates the mid-range of a one-dimensional ndarray according to a mask.
4+
5+
If provided an empty ndarray or a mask with all elements set to `1`, the
6+
function returns `NaN`.
7+
8+
Parameters
9+
----------
10+
arrays: ArrayLikeObject<ndarray>
11+
Array-like object containing an input ndarray and a mask ndarray.
12+
13+
Returns
14+
-------
15+
out: number
16+
Mid-range.
17+
18+
Examples
19+
--------
20+
> var xbuf = [ 1.0, -2.0, 4.0, 2.0 ];
21+
> var dt = 'generic';
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+
> var mbuf = [ 0, 0, 1, 0 ];
28+
> var mask = new {{alias:@stdlib/ndarray/ctor}}( dt, mbuf, sh, sx, ox, ord );
29+
> {{alias}}( [ x, mask ] )
30+
0.0
31+
32+
See Also
33+
--------
34+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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 { ndarray } from '@stdlib/types/ndarray';
24+
25+
/**
26+
* Calculates the mid-range of a one-dimensional ndarray according to a mask.
27+
*
28+
* @param arrays - array-like object containing an input ndarray and a mask ndarray
29+
* @returns mid-range
30+
*
31+
* @example
32+
* var ndarray = require( '@stdlib/ndarray/base/ctor' );
33+
*
34+
* var xbuf = [ 1.0, -2.0, 4.0, 2.0 ];
35+
* var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' );
36+
*
37+
* var mbuf = [ 0, 0, 1, 0 ];
38+
* var mask = new ndarray( 'generic', mbuf, [ 4 ], [ 1 ], 0, 'row-major' );
39+
*
40+
* var v = mskmidrange( [ x, mask ] );
41+
* // returns 0.0
42+
*/
43+
declare function mskmidrange<T extends ndarray = ndarray>( arrays: [ T, T ] ): number;
44+
45+
46+
// EXPORTS //
47+
48+
export = mskmidrange;

0 commit comments

Comments
 (0)