|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2025 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 | +# dnanmskmax |
| 22 | + |
| 23 | +> Compute the maximum value of a double-precision floating-point ndarray 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 dnanmskmax = require( '@stdlib/stats/base/ndarray/dnanmskmax' ); |
| 37 | +``` |
| 38 | + |
| 39 | +#### dnanmskmax( arrays ) |
| 40 | + |
| 41 | +Computes the maximum value of a double-precision floating-point ndarray 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 | +var ndarray = require( '@stdlib/ndarray/base/ctor' ); |
| 47 | + |
| 48 | +var xbuf = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); |
| 49 | +var x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); |
| 50 | + |
| 51 | +var maskbuf = new Uint8Array( [ 0, 0, 0, 0 ] ); |
| 52 | +var mask = new ndarray( 'uint8', maskbuf, [ 4 ], [ 1 ], 0, 'row-major' ); |
| 53 | + |
| 54 | +var v = dnanmskmax( [ x, mask ] ); |
| 55 | +// returns 2.0 |
| 56 | +``` |
| 57 | + |
| 58 | +The function has the following parameters: |
| 59 | + |
| 60 | +- **arrays**: array-like object containing a one-dimensional input ndarray and a one-dimensional mask ndarray. |
| 61 | + |
| 62 | +If a `mask` array element is `0`, the corresponding element in the input ndarray is considered valid and **included** in computation. If a `mask` array element is `1`, the corresponding element in the input ndarray is considered invalid/missing and **excluded** from computation. |
| 63 | + |
| 64 | + |
| 65 | +</section> |
| 66 | + |
| 67 | +<!-- /.usage --> |
| 68 | + |
| 69 | +<section class="notes"> |
| 70 | + |
| 71 | +## Notes |
| 72 | + |
| 73 | +- If provided an empty ndarray or a mask with all elements set to `1`, the function returns `NaN`. |
| 74 | + |
| 75 | +</section> |
| 76 | + |
| 77 | +<!-- /.notes --> |
| 78 | + |
| 79 | +<section class="examples"> |
| 80 | + |
| 81 | +## Examples |
| 82 | + |
| 83 | +<!-- eslint no-undef: "error" --> |
| 84 | + |
| 85 | +```javascript |
| 86 | +var uniform = require( '@stdlib/random/base/uniform' ); |
| 87 | +var filledarrayBy = require( '@stdlib/array/filled-by' ); |
| 88 | +var bernoulli = require( '@stdlib/random/base/bernoulli' ); |
| 89 | +var ndarray = require( '@stdlib/ndarray/base/ctor' ); |
| 90 | +var ndarray2array = require( '@stdlib/ndarray/to-array' ); |
| 91 | +var dnanmskmax = require( '@stdlib/stats/base/ndarray/dnanmskmax' ); |
| 92 | + |
| 93 | +function rand() { |
| 94 | + if ( bernoulli( 0.8 ) < 1 ) { |
| 95 | + return NaN; |
| 96 | + } |
| 97 | + return uniform( -50.0, 50.0 ); |
| 98 | +} |
| 99 | + |
| 100 | +function randMask() { |
| 101 | + if ( bernoulli( 0.1 ) < 1 ) { |
| 102 | + return 1; |
| 103 | + } |
| 104 | + return 0; |
| 105 | +} |
| 106 | + |
| 107 | +var xbuf = filledarrayBy( 10, 'float64', rand ); |
| 108 | +var x = new ndarray( 'float64', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); |
| 109 | +console.log( ndarray2array( x ) ); |
| 110 | + |
| 111 | +var maskbuf = filledarrayBy( xbuf.length, 'uint8', randMask ); |
| 112 | +var mask = new ndarray( 'uint8', maskbuf, [ maskbuf.length ], [ 1 ], 0, 'row-major' ); |
| 113 | +console.log( ndarray2array( mask ) ); |
| 114 | + |
| 115 | +var v = dnanmskmax( [ x, mask ] ); |
| 116 | +console.log( v ); |
| 117 | +``` |
| 118 | + |
| 119 | +</section> |
| 120 | + |
| 121 | +<!-- /.examples --> |
| 122 | + |
| 123 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 124 | + |
| 125 | +<section class="related"> |
| 126 | + |
| 127 | +</section> |
| 128 | + |
| 129 | +<!-- /.related --> |
| 130 | + |
| 131 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 132 | + |
| 133 | +<section class="links"> |
| 134 | + |
| 135 | +</section> |
| 136 | + |
| 137 | +<!-- /.links --> |
0 commit comments