Skip to content

Commit 2fc7683

Browse files
committed
feat: add stats/strided/snanmskmin
Ref: #4797 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: missing_dependencies - task: lint_c_examples status: missing_dependencies - task: lint_c_benchmarks status: missing_dependencies - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent 7b9a2a4 commit 2fc7683

33 files changed

+4024
-0
lines changed
Lines changed: 358 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,358 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2020 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+
<!-- lint disable maximum-heading-length -->
22+
23+
# snanmskmin
24+
25+
> Calculate the minimum value of a single-precision floating-point strided array according to a mask, ignoring `NaN` values.
26+
27+
<section class="intro">
28+
29+
</section>
30+
31+
<!-- /.intro -->
32+
33+
<section class="usage">
34+
35+
## Usage
36+
37+
```javascript
38+
var snanmskmin = require( '@stdlib/stats/strided/snanmskmin' );
39+
```
40+
41+
#### snanmskmin( N, x, strideX, mask, strideMask )
42+
43+
Computes the minimum value of a single-precision floating-point strided array according to a `mask`, ignoring `NaN` values.
44+
45+
```javascript
46+
var Float32Array = require( '@stdlib/array/float32' );
47+
var Uint8Array = require( '@stdlib/array/uint8' );
48+
49+
var x = new Float32Array( [ 1.0, -2.0, -4.0, 2.0, NaN ] );
50+
var mask = new Uint8Array( [ 0, 0, 1, 0, 0 ] );
51+
52+
var v = snanmskmin( x.length, x, 1, mask, 1 );
53+
// returns -2.0
54+
```
55+
56+
The function has the following parameters:
57+
58+
- **N**: number of indexed elements.
59+
- **x**: input [`Float32Array`][@stdlib/array/float32].
60+
- **strideX**: stride length for `x`.
61+
- **mask**: mask [`Uint8Array`][@stdlib/array/uint8]. If a `mask` array element is `0`, the corresponding element in `x` is considered valid and **included** in computation. If a `mask` array element is `1`, the corresponding element in `x` is considered invalid/missing and **excluded** from computation.
62+
- **strideMask**: stride length for `mask`.
63+
64+
The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to compute the minimum value of every other element in `x`,
65+
66+
```javascript
67+
var Float32Array = require( '@stdlib/array/float32' );
68+
var Uint8Array = require( '@stdlib/array/uint8' );
69+
70+
var x = new Float32Array( [ 1.0, 2.0, 7.0, -2.0, -4.0, 3.0, -5.0, -6.0 ] );
71+
var mask = new Uint8Array( [ 0, 0, 0, 0, 0, 0, 1, 1 ] );
72+
73+
var v = snanmskmin( 4, x, 2, mask, 2 );
74+
// returns -4.0
75+
```
76+
77+
Note that indexing is relative to the first index. To introduce offsets, use [`typed array`][mdn-typed-array] views.
78+
79+
<!-- eslint-disable stdlib/capitalized-comments -->
80+
81+
```javascript
82+
var Float32Array = require( '@stdlib/array/float32' );
83+
var Uint8Array = require( '@stdlib/array/uint8' );
84+
85+
var x0 = new Float32Array( [ 2.0, 1.0, -2.0, -2.0, 3.0, 4.0, -5.0, -6.0 ] );
86+
var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
87+
88+
var mask0 = new Uint8Array( [ 0, 0, 0, 0, 0, 0, 1, 1 ] );
89+
var mask1 = new Uint8Array( mask0.buffer, mask0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
90+
91+
var v = snanmskmin( 4, x1, 2, mask1, 2 );
92+
// returns -2.0
93+
```
94+
95+
#### snanmskmin.ndarray( N, x, strideX, offsetX, mask, strideMask, offsetMask )
96+
97+
Computes the minimum value of a single-precision floating-point strided array according to a `mask`, ignoring `NaN` values and using alternative indexing semantics.
98+
99+
```javascript
100+
var Float32Array = require( '@stdlib/array/float32' );
101+
var Uint8Array = require( '@stdlib/array/uint8' );
102+
103+
var x = new Float32Array( [ 1.0, -2.0, -4.0, 2.0, NaN ] );
104+
var mask = new Uint8Array( [ 0, 0, 1, 0, 0 ] );
105+
106+
var v = snanmskmin.ndarray( x.length, x, 1, 0, mask, 1, 0 );
107+
// returns -2.0
108+
```
109+
110+
The function has the following additional parameters:
111+
112+
- **offsetX**: starting index for `x`.
113+
- **offsetMask**: starting index for `mask`.
114+
115+
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, offset parameters support indexing semantics based on starting indices. For example, to calculate the minimum value for every other element in `x` starting from the second element
116+
117+
```javascript
118+
var Float32Array = require( '@stdlib/array/float32' );
119+
var Uint8Array = require( '@stdlib/array/uint8' );
120+
121+
var x = new Float32Array( [ 2.0, 1.0, -2.0, -2.0, 3.0, 4.0, -5.0, -6.0 ] );
122+
var mask = new Uint8Array( [ 0, 0, 0, 0, 0, 0, 1, 1 ] );
123+
124+
var v = snanmskmin.ndarray( 4, x, 2, 1, mask, 2, 1 );
125+
// returns -2.0
126+
```
127+
128+
</section>
129+
130+
<!-- /.usage -->
131+
132+
<section class="notes">
133+
134+
## Notes
135+
136+
- If `N <= 0`, both functions return `NaN`.
137+
138+
</section>
139+
140+
<!-- /.notes -->
141+
142+
<section class="examples">
143+
144+
## Examples
145+
146+
<!-- eslint no-undef: "error" -->
147+
148+
```javascript
149+
var uniform = require( '@stdlib/random/base/uniform' );
150+
var bernoulli = require( '@stdlib/random/base/bernoulli' );
151+
var filledarrayBy = require( '@stdlib/array/filled-by' );
152+
var snanmskmin = require( '@stdlib/stats/strided/snanmskmin' );
153+
154+
function rand() {
155+
if ( bernoulli( 0.8 ) < 1 ) {
156+
return NaN;
157+
}
158+
return uniform( -50.0, 50.0 );
159+
}
160+
161+
var x = filledarrayBy( 10, 'float32', rand );
162+
console.log( x );
163+
164+
var mask = filledarrayBy( x.length, 'uint8', bernoulli.factory( 0.2 ) );
165+
console.log( mask );
166+
167+
var v = snanmskmin( x.length, x, 1, mask, 1 );
168+
console.log( v );
169+
```
170+
171+
</section>
172+
173+
<!-- /.examples -->
174+
175+
<!-- C interface documentation. -->
176+
177+
* * *
178+
179+
<section class="c">
180+
181+
## C APIs
182+
183+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
184+
185+
<section class="intro">
186+
187+
</section>
188+
189+
<!-- /.intro -->
190+
191+
<!-- C usage documentation. -->
192+
193+
<section class="usage">
194+
195+
### Usage
196+
197+
```c
198+
#include "stdlib/stats/strided/snanmskmin.h"
199+
```
200+
201+
#### stdlib_strided_snanmskmin( N, \*X, strideX, \*Mask, strideMask )
202+
203+
Computes the minimum value of a single-precision floating-point strided array according to a `mask`, ignoring `NaN` values.
204+
205+
```c
206+
#include <stdint.h>
207+
208+
const float x[] = { 1.0f, -2.0f, 4.0f, 2.0f, 0.0f/0.0f };
209+
const uint8_t mask[] = { 0, 0, 1, 0, 0 };
210+
211+
float v = stdlib_strided_snanmskmin( 5, x, 1, mask, 1 );
212+
// returns -2.0f
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+
- **Mask**: `[in] uint8_t*` mask array. If a `Mask` array element is `0`, the corresponding element in `X` is considered valid and included in computation. If a `Mask` array element is `1`, the corresponding element in `X` is considered invalid/missing and excluded from computation.
221+
- **strideMask**: `[in] CBLAS_INT` stride length for `Mask`.
222+
223+
```c
224+
float stdlib_strided_snanmskmin( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const uint8_t *Mask, const CBLAS_INT strideMask );
225+
```
226+
227+
#### stdlib_strided_snanmskmin_ndarray( N, \*X, strideX, offsetX, \*Mask, strideMask, offsetMask )
228+
229+
Computes the minimum value of a single-precision floating-point strided array according to a `mask`, ignoring `NaN` values and using alternative indexing semantics.
230+
231+
```c
232+
#include <stdint.h>
233+
234+
const float x[] = { 1.0f, -2.0f, 4.0f, 2.0f, 0.0f/0.0f };
235+
const uint8_t mask[] = { 0, 0, 1, 0, 0 };
236+
237+
float v = stdlib_strided_snanmskmin_ndarray( 5, x, 1, 0, mask, 1, 0 );
238+
// returns -2.0f
239+
```
240+
241+
The function accepts the following arguments:
242+
243+
- **N**: `[in] CBLAS_INT` number of indexed elements.
244+
- **X**: `[in] float*` input array.
245+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
246+
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
247+
- **Mask**: `[in] uint8_t*` mask array. If a `Mask` array element is `0`, the corresponding element in `X` is considered valid and included in computation. If a `Mask` array element is `1`, the corresponding element in `X` is considered invalid/missing and excluded from computation.
248+
- **strideMask**: `[in] CBLAS_INT` stride length for `Mask`.
249+
- **offsetMask**: `[in] CBLAS_INT` starting index for `Mask`.
250+
251+
```c
252+
float stdlib_strided_snanmskmin_ndarray( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const uint8_t *Mask, const CBLAS_INT strideMask, const CBLAS_INT offsetMask );
253+
```
254+
255+
</section>
256+
257+
<!-- /.usage -->
258+
259+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
260+
261+
<section class="notes">
262+
263+
</section>
264+
265+
<!-- /.notes -->
266+
267+
<!-- C API usage examples. -->
268+
269+
<section class="examples">
270+
271+
### Examples
272+
273+
```c
274+
#include "stdlib/stats/strided/snanmskmin.h"
275+
#include <stdint.h>
276+
#include <stdio.h>
277+
278+
int main( void ) {
279+
// Create a strided array:
280+
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 };
281+
282+
// Create a mask array:
283+
const uint8_t mask[] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 };
284+
285+
// Specify the number of elements:
286+
const int N = 5;
287+
288+
// Specify the stride lengths:
289+
const int strideX = 2;
290+
const int strideMask = 2;
291+
292+
// Compute the minimum value:
293+
float v = stdlib_strided_snanmskmin( N, x, strideX, mask, strideMask );
294+
295+
// Print the result:
296+
printf( "min: %f\n", v );
297+
}
298+
```
299+
300+
</section>
301+
302+
<!-- /.examples -->
303+
304+
</section>
305+
306+
<!-- /.c -->
307+
308+
<section class="references">
309+
310+
</section>
311+
312+
<!-- /.references -->
313+
314+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
315+
316+
<section class="related">
317+
318+
* * *
319+
320+
## See Also
321+
322+
- <span class="package-name">[`@stdlib/stats/strided/dnanmskmin`][@stdlib/stats/strided/dnanmskmin]</span><span class="delimiter">: </span><span class="description">calculate the minimum value of a double-precision floating-point strided array according to a mask, ignoring NaN values.</span>
323+
- <span class="package-name">[`@stdlib/stats/base/nanmskmin`][@stdlib/stats/base/nanmskmin]</span><span class="delimiter">: </span><span class="description">calculate the minimum value of a strided array according to a mask, ignoring NaN values.</span>
324+
- <span class="package-name">[`@stdlib/stats/strided/smskmin`][@stdlib/stats/strided/smskmin]</span><span class="delimiter">: </span><span class="description">calculate the minimum value of a single-precision floating-point strided array according to a mask.</span>
325+
- <span class="package-name">[`@stdlib/stats/strided/snanmin`][@stdlib/stats/strided/snanmin]</span><span class="delimiter">: </span><span class="description">calculate the minimum value of a single-precision floating-point strided array, ignoring NaN values.</span>
326+
- <span class="package-name">[`@stdlib/stats/strided/snanmskmax`][@stdlib/stats/strided/snanmskmax]</span><span class="delimiter">: </span><span class="description">calculate the maximum value of a single-precision floating-point strided array according to a mask, ignoring NaN values.</span>
327+
328+
</section>
329+
330+
<!-- /.related -->
331+
332+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
333+
334+
<section class="links">
335+
336+
[@stdlib/array/float32]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/float32
337+
338+
[@stdlib/array/uint8]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/uint8
339+
340+
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
341+
342+
<!-- <related-links> -->
343+
344+
[@stdlib/stats/strided/dnanmskmin]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/dnanmskmin
345+
346+
[@stdlib/stats/base/nanmskmin]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/nanmskmin
347+
348+
[@stdlib/stats/strided/smskmin]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/smskmin
349+
350+
[@stdlib/stats/strided/snanmin]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/snanmin
351+
352+
[@stdlib/stats/strided/snanmskmax]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/snanmskmax
353+
354+
<!-- </related-links> -->
355+
356+
</section>
357+
358+
<!-- /.links -->

0 commit comments

Comments
 (0)