Skip to content

Commit 9f6d0db

Browse files
aayush0325kgryte
authored andcommitted
feat: add stats/strided/dnanmin
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 ef90f52 commit 9f6d0db

33 files changed

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

0 commit comments

Comments
 (0)