Skip to content

Commit 745d634

Browse files
committed
Auto-generated commit
1 parent 832ee29 commit 745d634

34 files changed

+3565
-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+
- [`f4d072e`](https://github.com/stdlib-js/stdlib/commit/f4d072ea93759a1ddb497804a572a13158cdffb9) - add `stats/strided/snanmidrange` [(#9400)](https://github.com/stdlib-js/stdlib/pull/9400)
1314
- [`7be3235`](https://github.com/stdlib-js/stdlib/commit/7be3235f58dab6f5a5ac11a58ddad8d5ba2fcb1a) - add `stats/strided/distances/dcosine-similarity` [(#9281)](https://github.com/stdlib-js/stdlib/pull/9281)
1415
- [`9e5b1db`](https://github.com/stdlib-js/stdlib/commit/9e5b1dbcb5c122ac460507aa889a171a8f67bd2e) - add `stats/base/ndarray/stdevpn` [(#9381)](https://github.com/stdlib-js/stdlib/pull/9381)
1516
- [`9a44f1a`](https://github.com/stdlib-js/stdlib/commit/9a44f1ac8a945490b8703f52c32f3aaef3ae1283) - add `stats/base/ndarray/stdevtk` [(#9382)](https://github.com/stdlib-js/stdlib/pull/9382)
@@ -3540,6 +3541,7 @@ A total of 560 issues were closed in this release:
35403541

35413542
<details>
35423543

3544+
- [`f4d072e`](https://github.com/stdlib-js/stdlib/commit/f4d072ea93759a1ddb497804a572a13158cdffb9) - **feat:** add `stats/strided/snanmidrange` [(#9400)](https://github.com/stdlib-js/stdlib/pull/9400) _(by Sachin Pangal, Athan Reines)_
35433545
- [`40fddc9`](https://github.com/stdlib-js/stdlib/commit/40fddc9801524ef1ff07040447efbb70cdfa7452) - **test:** fix test descriptions _(by Athan Reines)_
35443546
- [`7830472`](https://github.com/stdlib-js/stdlib/commit/783047291af025831264739d9841e60ab32232f2) - **bench:** fix description _(by Athan Reines)_
35453547
- [`eb83311`](https://github.com/stdlib-js/stdlib/commit/eb83311758f6cf348950ac84555127d03dd0155e) - **bench:** fix description _(by Athan Reines)_

strided/snanmidrange/README.md

Lines changed: 294 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,294 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 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+
# snanmidrange
22+
23+
> Calculate the [mid-range][mid-range] of a single-precision floating-point strided array, 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 snanmidrange = require( '@stdlib/stats/strided/snanmidrange' );
39+
```
40+
41+
#### snanmidrange( N, x, strideX )
42+
43+
Computes the [mid-range][mid-range] of a single-precision floating-point strided array, ignoring `NaN` values.
44+
45+
```javascript
46+
var Float32Array = require( '@stdlib/array/float32' );
47+
48+
var x = new Float32Array( [ 1.0, -2.0, NaN, 2.0 ] );
49+
50+
var v = snanmidrange( x.length, x, 1 );
51+
// returns 0.0
52+
```
53+
54+
The function has the following parameters:
55+
56+
- **N**: number of indexed elements.
57+
- **x**: input [`Float32Array`][@stdlib/array/float32].
58+
- **strideX**: stride length for `x`.
59+
60+
The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the [mid-range][mid-range] of every other element in `x`,
61+
62+
```javascript
63+
var Float32Array = require( '@stdlib/array/float32' );
64+
65+
var x = new Float32Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0, NaN ] );
66+
67+
var v = snanmidrange( 5, x, 2 );
68+
// returns 1.0
69+
```
70+
71+
Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.
72+
73+
<!-- eslint-disable stdlib/capitalized-comments -->
74+
75+
```javascript
76+
var Float32Array = require( '@stdlib/array/float32' );
77+
78+
var x0 = new Float32Array( [ 2.0, 1.0, -2.0, -2.0, 3.0, 4.0, NaN, NaN ] );
79+
var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
80+
81+
var v = snanmidrange( 4, x1, 2 );
82+
// returns 1.0
83+
```
84+
85+
#### snanmidrange.ndarray( N, x, strideX, offsetX )
86+
87+
Computes the [mid-range][mid-range] of a single-precision floating-point strided array, ignoring `NaN` values and using alternative indexing semantics.
88+
89+
```javascript
90+
var Float32Array = require( '@stdlib/array/float32' );
91+
92+
var x = new Float32Array( [ 1.0, -2.0, NaN, 2.0 ] );
93+
94+
var v = snanmidrange.ndarray( x.length, x, 1, 0 );
95+
// returns 0.0
96+
```
97+
98+
The function has the following additional parameters:
99+
100+
- **offsetX**: starting index for `x`.
101+
102+
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to calculate the [mid-range][mid-range] for every other element in `x` starting from the second element
103+
104+
```javascript
105+
var Float32Array = require( '@stdlib/array/float32' );
106+
107+
var x = new Float32Array( [ 2.0, 1.0, -2.0, -2.0, 3.0, 4.0, NaN, NaN ] );
108+
109+
var v = snanmidrange.ndarray( 4, x, 2, 1 );
110+
// returns 1.0
111+
```
112+
113+
</section>
114+
115+
<!-- /.usage -->
116+
117+
<section class="notes">
118+
119+
## Notes
120+
121+
- If `N <= 0`, both functions return `NaN`.
122+
123+
</section>
124+
125+
<!-- /.notes -->
126+
127+
<section class="examples">
128+
129+
## Examples
130+
131+
<!-- eslint no-undef: "error" -->
132+
133+
```javascript
134+
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
135+
var bernoulli = require( '@stdlib/random/base/bernoulli' );
136+
var filledarrayBy = require( '@stdlib/array/filled-by' );
137+
var snanmidrange = require( '@stdlib/stats/strided/snanmidrange' );
138+
139+
function random() {
140+
if ( bernoulli( 0.8 ) < 1 ) {
141+
return NaN;
142+
}
143+
return discreteUniform( -100, 100 );
144+
}
145+
146+
var x = filledarrayBy( 100, 'float32', random );
147+
console.log( x );
148+
149+
var v = snanmidrange( x.length, x, 1 );
150+
console.log( v );
151+
```
152+
153+
</section>
154+
155+
<!-- /.examples -->
156+
157+
<!-- C interface documentation. -->
158+
159+
* * *
160+
161+
<section class="c">
162+
163+
## C APIs
164+
165+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
166+
167+
<section class="intro">
168+
169+
</section>
170+
171+
<!-- /.intro -->
172+
173+
<!-- C usage documentation. -->
174+
175+
<section class="usage">
176+
177+
### Usage
178+
179+
```c
180+
#include "stdlib/stats/strided/snanmidrange.h"
181+
```
182+
183+
#### stdlib_strided_snanmidrange( N, \*X, strideX )
184+
185+
Computes the [mid-range][mid-range] of a single-precision floating-point strided array, ignoring `NaN` values.
186+
187+
```c
188+
const float x[] = { 1.0f, 0.0f/0.0f, 3.0f, -4.0f };
189+
190+
float v = stdlib_strided_snanmidrange( 4, x, 1 );
191+
// returns -0.5f
192+
```
193+
194+
The function accepts the following arguments:
195+
196+
- **N**: `[in] CBLAS_INT` number of indexed elements.
197+
- **X**: `[in] float*` input array.
198+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
199+
200+
```c
201+
float stdlib_strided_snanmidrange( const CBLAS_INT N, const float *X, const CBLAS_INT strideX );
202+
```
203+
204+
#### stdlib_strided_snanmidrange_ndarray( N, \*X, strideX, offsetX )
205+
206+
Computes the [mid-range][mid-range] of a single-precision floating-point strided array, ignoring `NaN` values and using alternative indexing semantics.
207+
208+
```c
209+
const float x[] = { 1.0f, 0.0f/0.0f, 3.0f, -4.0f };
210+
211+
float v = stdlib_strided_snanmidrange_ndarray( 4, x, 1, 0 );
212+
// returns -0.5f
213+
```
214+
215+
The function accepts the following arguments:
216+
217+
- **N**: `[in] CBLAS_INT` number of indexed elements.
218+
- **X**: `[in] float*` input array.
219+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
220+
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
221+
222+
```c
223+
float stdlib_strided_snanmidrange_ndarray( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
224+
```
225+
226+
</section>
227+
228+
<!-- /.usage -->
229+
230+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
231+
232+
<section class="notes">
233+
234+
</section>
235+
236+
<!-- /.notes -->
237+
238+
<!-- C API usage examples. -->
239+
240+
<section class="examples">
241+
242+
### Examples
243+
244+
```c
245+
#include "stdlib/stats/strided/snanmidrange.h"
246+
#include <stdio.h>
247+
248+
int main( void ) {
249+
// Create a strided array:
250+
const float x[] = { 1.0f, -2.0f, -3.0f, 4.0f, -5.0f, -6.0f, 7.0f, 8.0f, 0.0f/0.0f, 0.0f/0.0f };
251+
252+
// Specify the number of elements:
253+
const int N = 5;
254+
255+
// Specify the stride length:
256+
const int strideX = 2;
257+
258+
// Compute the mid-range:
259+
float v = stdlib_strided_snanmidrange( N, x, strideX );
260+
261+
// Print the result:
262+
printf( "mid-range: %f\n", v );
263+
}
264+
```
265+
266+
</section>
267+
268+
<!-- /.examples -->
269+
270+
</section>
271+
272+
<!-- /.c -->
273+
274+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
275+
276+
<section class="related">
277+
278+
</section>
279+
280+
<!-- /.related -->
281+
282+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
283+
284+
<section class="links">
285+
286+
[mid-range]: https://en.wikipedia.org/wiki/Mid-range
287+
288+
[@stdlib/array/float32]: https://github.com/stdlib-js/array-float32
289+
290+
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
291+
292+
</section>
293+
294+
<!-- /.links -->

0 commit comments

Comments
 (0)