Skip to content

Commit 5506e7f

Browse files
committed
docs: update README
1 parent a019508 commit 5506e7f

File tree

1 file changed

+159
-32
lines changed
  • lib/node_modules/@stdlib/stats/base/dnanmskrange

1 file changed

+159
-32
lines changed

lib/node_modules/@stdlib/stats/base/dnanmskrange/README.md

Lines changed: 159 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var dnanmskrange = require( '@stdlib/stats/base/dnanmskrange' );
4040

4141
#### dnanmskrange( N, x, strideX, mask, strideMask )
4242

43-
Computes the [range][range] of a double-precision floating-point strided array `x` according to a `mask`, ignoring `NaN` values.
43+
Computes the [range][range] of a double-precision floating-point strided array according to a `mask`, ignoring `NaN` values.
4444

4545
```javascript
4646
var Float64Array = require( '@stdlib/array/float64' );
@@ -57,22 +57,20 @@ The function has the following parameters:
5757

5858
- **N**: number of indexed elements.
5959
- **x**: input [`Float64Array`][@stdlib/array/float64].
60-
- **strideX**: index increment for `x`.
60+
- **strideX**: stride length for `x`.
6161
- **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.
6262
- **strideMask**: index increment for `mask`.
6363

64-
The `N` and `stride` parameters determine which elements are accessed at runtime. For example, to compute the [range][range] of every other element in `x`,
64+
The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the [range][range] of every other element in `x`,
6565

6666
```javascript
6767
var Float64Array = require( '@stdlib/array/float64' );
6868
var Uint8Array = require( '@stdlib/array/uint8' );
69-
var floor = require( '@stdlib/math/base/special/floor' );
7069

7170
var x = new Float64Array( [ 1.0, 2.0, -7.0, -2.0, 4.0, 3.0, 5.0, 6.0 ] );
7271
var mask = new Uint8Array( [ 0, 0, 0, 0, 0, 0, 1, 1 ] );
73-
var N = floor( x.length / 2 );
7472

75-
var v = dnanmskrange( N, x, 2, mask, 2 );
73+
var v = dnanmskrange( 4, x, 2, mask, 2 );
7674
// returns 11.0
7775
```
7876

@@ -83,17 +81,14 @@ Note that indexing is relative to the first index. To introduce offsets, use [`t
8381
```javascript
8482
var Float64Array = require( '@stdlib/array/float64' );
8583
var Uint8Array = require( '@stdlib/array/uint8' );
86-
var floor = require( '@stdlib/math/base/special/floor' );
8784

8885
var x0 = new Float64Array( [ 2.0, 1.0, -2.0, -2.0, 3.0, 4.0, 5.0, 6.0 ] );
8986
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
9087

9188
var mask0 = new Uint8Array( [ 0, 0, 0, 0, 0, 0, 1, 1 ] );
9289
var mask1 = new Uint8Array( mask0.buffer, mask0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
9390

94-
var N = floor( x0.length / 2 );
95-
96-
var v = dnanmskrange( N, x1, 2, mask1, 2 );
91+
var v = dnanmskrange( 4, x1, 2, mask1, 2 );
9792
// returns 6.0
9893
```
9994

@@ -117,18 +112,16 @@ The function has the following additional parameters:
117112
- **offsetX**: starting index for `x`.
118113
- **offsetMask**: starting index for `mask`.
119114

120-
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 [range][range] for every other value in `x` starting from the second value
115+
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 [range][range] for every other element in `x` starting from the second element
121116

122117
```javascript
123118
var Float64Array = require( '@stdlib/array/float64' );
124119
var Uint8Array = require( '@stdlib/array/uint8' );
125-
var floor = require( '@stdlib/math/base/special/floor' );
126120

127121
var x = new Float64Array( [ 2.0, 1.0, -2.0, -2.0, 3.0, 4.0, 5.0, 6.0 ] );
128122
var mask = new Uint8Array( [ 0, 0, 0, 0, 0, 0, 1, 1 ] );
129-
var N = floor( x.length / 2 );
130123

131-
var v = dnanmskrange.ndarray( N, x, 2, 1, mask, 2, 1 );
124+
var v = dnanmskrange.ndarray( 4, x, 2, 1, mask, 2, 1 );
132125
// returns 6.0
133126
```
134127

@@ -153,31 +146,28 @@ var v = dnanmskrange.ndarray( N, x, 2, 1, mask, 2, 1 );
153146
<!-- eslint no-undef: "error" -->
154147

155148
```javascript
156-
var randu = require( '@stdlib/random/base/randu' );
157-
var round = require( '@stdlib/math/base/special/round' );
158-
var Float64Array = require( '@stdlib/array/float64' );
159-
var Uint8Array = require( '@stdlib/array/uint8' );
149+
var uniform = require( '@stdlib/random/base/uniform' );
150+
var filledarrayBy = require( '@stdlib/array/filled-by' );
151+
var bernoulli = require( '@stdlib/random/base/bernoulli' );
152+
var uint8Array = require( '@stdlib/random/array/bernoulli' );
160153
var dnanmskrange = require( '@stdlib/stats/base/dnanmskrange' );
161154

162155
var mask;
163156
var x;
164-
var i;
165-
166-
x = new Float64Array( 10 );
167-
mask = new Uint8Array( x.length );
168-
for ( i = 0; i < x.length; i++ ) {
169-
if ( randu() < 0.2 ) {
170-
mask[ i ] = 1;
171-
} else {
172-
mask[ i ] = 0;
173-
}
174-
if ( randu() < 0.1 ) {
175-
x[ i ] = NaN;
176-
} else {
177-
x[ i ] = round( (randu()*100.0) - 50.0 );
157+
158+
function rand() {
159+
if ( bernoulli( 0.8 ) < 1 ) {
160+
return NaN;
178161
}
162+
return uniform( -50.0, 50.0 );
179163
}
164+
165+
x = filledarrayBy( 10, 'float64', rand );
180166
console.log( x );
167+
168+
mask = uint8Array( x.length, 0.2, {
169+
'dtype': 'uint8'
170+
});
181171
console.log( mask );
182172

183173
var v = dnanmskrange( x.length, x, 1, mask, 1 );
@@ -188,6 +178,143 @@ console.log( v );
188178

189179
<!-- /.examples -->
190180

181+
<!-- C interface documentation. -->
182+
183+
* * *
184+
185+
<section class="c">
186+
187+
## C APIs
188+
189+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
190+
191+
<section class="intro">
192+
193+
</section>
194+
195+
<!-- /.intro -->
196+
197+
<!-- C usage documentation. -->
198+
199+
<section class="usage">
200+
201+
### Usage
202+
203+
```c
204+
#include "stdlib/stats/base/dnanmskrange.h"
205+
```
206+
207+
#### stdlib_strided_dnanmskrange( N, \*X, strideX, \*Mask, strideMask )
208+
209+
Computes the [range][range] of a double-precision floating-point strided array according to a `mask`, ignoring `NaN` values.
210+
211+
```c
212+
#include <stdint.h>
213+
214+
const double x[] = { 1.0, -2.0, 4.0, 2.0, 0.0/0.0 };
215+
const uint8_t mask[] = { 0, 0, 1, 0, 0 };
216+
217+
double v = stdlib_strided_dnanmskrange( 5, x, 1, mask, 1 );
218+
// returns 4.0
219+
```
220+
221+
The function accepts the following arguments:
222+
223+
- **N**: `[in] CBLAS_INT` number of indexed elements.
224+
- **X**: `[in] double*` input array.
225+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
226+
- **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.
227+
- **strideMask**: `[in] CBLAS_INT` stride length for `Mask`.
228+
229+
```c
230+
double stdlib_strided_dnanmskrange( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const uint8_t *Mask, const CBLAS_INT strideMask );
231+
```
232+
233+
#### stdlib_strided_dnanmskrange_ndarray( N, \*X, strideX, offsetX, \*Mask, strideMask, offsetMask )
234+
235+
Computes the [range][range] of a double-precision floating-point strided array according to a `mask`, ignoring `NaN` values and using alternative indexing semantics.
236+
237+
```c
238+
const double x[] = { 1.0, -2.0, 4.0, 2.0, 0.0/0.0 };
239+
const uint8_t mask[] = { 0, 0, 1, 0, 0 };
240+
241+
double v = stdlib_strided_dnanmskrange_ndarray( 5, x, 1, 0, mask, 1, 0 );
242+
// returns 4.0
243+
```
244+
245+
The function accepts the following arguments:
246+
247+
- **N**: `[in] CBLAS_INT` number of indexed elements.
248+
- **X**: `[in] double*` input array.
249+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
250+
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
251+
- **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.
252+
- **strideMask**: `[in] CBLAS_INT` stride length for `Mask`.
253+
- **offsetMask**: `[in] CBLAS_INT` starting index for `Mask`.
254+
255+
```c
256+
double stdlib_strided_dnanmskrange_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 );
257+
```
258+
259+
</section>
260+
261+
<!-- /.usage -->
262+
263+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
264+
265+
<section class="notes">
266+
267+
</section>
268+
269+
<!-- /.notes -->
270+
271+
<!-- C API usage examples. -->
272+
273+
<section class="examples">
274+
275+
### Examples
276+
277+
```c
278+
#include "stdlib/stats/base/dnanmskrange.h"
279+
#include <stdint.h>
280+
#include <stdio.h>
281+
282+
int main( void ) {
283+
// Create a strided array:
284+
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 };
285+
286+
// Create a mask array:
287+
const uint8_t mask[] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 };
288+
289+
// Specify the number of elements:
290+
const int N = 5;
291+
292+
// Specify the stride lengths:
293+
const int strideX = 2;
294+
const int strideMask = 2;
295+
296+
// Compute the range:
297+
double v = stdlib_strided_dnanmskrange( N, x, strideX, mask, strideMask );
298+
299+
// Print the result:
300+
printf( "range: %lf\n", v );
301+
}
302+
```
303+
304+
</section>
305+
306+
<!-- /.examples -->
307+
308+
</section>
309+
310+
<!-- /.c -->
311+
312+
<section class="references">
313+
314+
</section>
315+
316+
<!-- /.references -->
317+
191318
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
192319
193320
<section class="related">

0 commit comments

Comments
 (0)