README.md (5962B)
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 # dnanmskmin 22 23 > Calculate the minimum value of a double-precision floating-point strided array according to a mask, 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 dnanmskmin = require( '@stdlib/stats/base/dnanmskmin' ); 37 ``` 38 39 #### dnanmskmin( N, x, strideX, mask, strideMask ) 40 41 Computes the minimum value of a double-precision floating-point strided array `x` according to a `mask`, ignoring `NaN` values. 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, NaN ] ); 48 var mask = new Uint8Array( [ 0, 0, 1, 0, 0 ] ); 49 50 var v = dnanmskmin( 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**: index increment 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**: index increment for `mask`. 61 62 The `N` and `stride` parameters determine which elements 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 var floor = require( '@stdlib/math/base/special/floor' ); 68 69 var x = new Float64Array( [ 1.0, 2.0, 7.0, -2.0, -4.0, 3.0, -5.0, -6.0 ] ); 70 var mask = new Uint8Array( [ 0, 0, 0, 0, 0, 0, 1, 1 ] ); 71 var N = floor( x.length / 2 ); 72 73 var v = dnanmskmin( N, 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 Float64Array = require( '@stdlib/array/float64' ); 83 var Uint8Array = require( '@stdlib/array/uint8' ); 84 var floor = require( '@stdlib/math/base/special/floor' ); 85 86 var x0 = new Float64Array( [ 2.0, 1.0, -2.0, -2.0, 3.0, 4.0, -5.0, -6.0 ] ); 87 var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element 88 89 var mask0 = new Uint8Array( [ 0, 0, 0, 0, 0, 0, 1, 1 ] ); 90 var mask1 = new Uint8Array( mask0.buffer, mask0.BYTES_PER_ELEMENT*1 ); // start at 2nd element 91 92 var N = floor( x0.length / 2 ); 93 94 var v = dnanmskmin( N, x1, 2, mask1, 2 ); 95 // returns -2.0 96 ``` 97 98 #### dnanmskmin.ndarray( N, x, strideX, offsetX, mask, strideMask, offsetMask ) 99 100 Computes the minimum value of a double-precision floating-point strided array according to a `mask`, ignoring `NaN` values and using alternative indexing semantics. 101 102 ```javascript 103 var Float64Array = require( '@stdlib/array/float64' ); 104 var Uint8Array = require( '@stdlib/array/uint8' ); 105 106 var x = new Float64Array( [ 1.0, -2.0, -4.0, 2.0, NaN ] ); 107 var mask = new Uint8Array( [ 0, 0, 1, 0, 0 ] ); 108 109 var v = dnanmskmin.ndarray( x.length, x, 1, 0, mask, 1, 0 ); 110 // returns -2.0 111 ``` 112 113 The function has the following additional parameters: 114 115 - **offsetX**: starting index for `x`. 116 - **offsetMask**: starting index for `mask`. 117 118 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 value in `x` starting from the second value 119 120 ```javascript 121 var Float64Array = require( '@stdlib/array/float64' ); 122 var Uint8Array = require( '@stdlib/array/uint8' ); 123 var floor = require( '@stdlib/math/base/special/floor' ); 124 125 var x = new Float64Array( [ 2.0, 1.0, -2.0, -2.0, 3.0, 4.0, -5.0, -6.0 ] ); 126 var mask = new Uint8Array( [ 0, 0, 0, 0, 0, 0, 1, 1 ] ); 127 var N = floor( x.length / 2 ); 128 129 var v = dnanmskmin.ndarray( N, x, 2, 1, mask, 2, 1 ); 130 // returns -2.0 131 ``` 132 133 </section> 134 135 <!-- /.usage --> 136 137 <section class="notes"> 138 139 ## Notes 140 141 - If `N <= 0`, both functions return `NaN`. 142 143 </section> 144 145 <!-- /.notes --> 146 147 <section class="examples"> 148 149 ## Examples 150 151 <!-- eslint no-undef: "error" --> 152 153 ```javascript 154 var randu = require( '@stdlib/random/base/randu' ); 155 var round = require( '@stdlib/math/base/special/round' ); 156 var Float64Array = require( '@stdlib/array/float64' ); 157 var Uint8Array = require( '@stdlib/array/uint8' ); 158 var dnanmskmin = require( '@stdlib/stats/base/dnanmskmin' ); 159 160 var mask; 161 var x; 162 var i; 163 164 x = new Float64Array( 10 ); 165 mask = new Uint8Array( x.length ); 166 for ( i = 0; i < x.length; i++ ) { 167 if ( randu() < 0.2 ) { 168 mask[ i ] = 1; 169 } else { 170 mask[ i ] = 0; 171 } 172 if ( randu() < 0.1 ) { 173 x[ i ] = NaN; 174 } else { 175 x[ i ] = round( (randu()*100.0) - 50.0 ); 176 } 177 } 178 console.log( x ); 179 console.log( mask ); 180 181 var v = dnanmskmin( x.length, x, 1, mask, 1 ); 182 console.log( v ); 183 ``` 184 185 </section> 186 187 <!-- /.examples --> 188 189 <section class="links"> 190 191 [@stdlib/array/float64]: https://www.npmjs.com/package/@stdlib/array-float64 192 193 [@stdlib/array/uint8]: https://www.npmjs.com/package/@stdlib/array-uint8 194 195 [mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray 196 197 </section> 198 199 <!-- /.links -->