Skip to content

Commit f2fe585

Browse files
committed
Auto-generated commit
1 parent 2496cd1 commit f2fe585

File tree

11 files changed

+864
-0
lines changed

11 files changed

+864
-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+
- [`c216b80`](https://github.com/stdlib-js/stdlib/commit/c216b80baf3efe0d21387a280368c44122328b76) - add `stats/base/ndarray/smskmidrange` [(#9519)](https://github.com/stdlib-js/stdlib/pull/9519)
1314
- [`d681872`](https://github.com/stdlib-js/stdlib/commit/d681872a9b87321f4f66852f5aabfeec19e195fc) - add `stats/base/ndarray/mskmidrange` [(#9511)](https://github.com/stdlib-js/stdlib/pull/9511)
1415
- [`c824fea`](https://github.com/stdlib-js/stdlib/commit/c824feae2f1582ff59f0d3bee99896fa77ef1f81) - add `stats/base/ndarray/snanmidrange` [(#9505)](https://github.com/stdlib-js/stdlib/pull/9505)
1516
- [`8107a5a`](https://github.com/stdlib-js/stdlib/commit/8107a5a755bbdeb69c8110a2dbc9ed1a39d136c9) - add `stats/base/ndarray/dnanmidrange` [(#9504)](https://github.com/stdlib-js/stdlib/pull/9504)
@@ -3550,6 +3551,7 @@ A total of 562 issues were closed in this release:
35503551

35513552
<details>
35523553

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

0 commit comments

Comments
 (0)