Skip to content

Commit 234bfac

Browse files
committed
feat: add stats/strided/dmskmin
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: passed - task: lint_c_examples status: passed - task: lint_c_benchmarks status: passed - 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 4525270 commit 234bfac

33 files changed

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

0 commit comments

Comments
 (0)