|
| 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 | +# snanmskmax |
| 22 | + |
| 23 | +> Calculate the maximum value of a one-dimensional single-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 snanmskmax = require( '@stdlib/stats/base/ndarray/snanmskmax' ); |
| 37 | +``` |
| 38 | + |
| 39 | +#### snanmskmax( arrays ) |
| 40 | + |
| 41 | +Computes the maximum value of a one-dimensional single-precision floating-point ndarray according to a mask, ignoring `NaN` values. |
| 42 | + |
| 43 | +```javascript |
| 44 | +var Float32Array = require( '@stdlib/array/float32' ); |
| 45 | +var Uint8Array = require( '@stdlib/array/uint8' ); |
| 46 | +var ndarray = require( '@stdlib/ndarray/base/ctor' ); |
| 47 | + |
| 48 | +var xbuf = new Float32Array( [ 1.0, -2.0, 4.0, 2.0 ] ); |
| 49 | +var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); |
| 50 | + |
| 51 | +var maskbuf = new Uint8Array( [ 0, 0, 1, 0 ] ); |
| 52 | +var mask = new ndarray( 'uint8', maskbuf, [ 4 ], [ 1 ], 0, 'row-major' ); |
| 53 | + |
| 54 | +var v = snanmskmax( [ x, mask ] ); |
| 55 | +// returns 2.0 |
| 56 | +``` |
| 57 | + |
| 58 | +The function has the following parameters: |
| 59 | + |
| 60 | +- **arrays**: array-like object containing an input ndarray and a 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 | +</section> |
| 65 | + |
| 66 | +<!-- /.usage --> |
| 67 | + |
| 68 | +<section class="notes"> |
| 69 | + |
| 70 | +## Notes |
| 71 | + |
| 72 | +- If provided an empty ndarray or a mask with all elements set to `1`, the function returns `NaN`. |
| 73 | + |
| 74 | +</section> |
| 75 | + |
| 76 | +<!-- /.notes --> |
| 77 | + |
| 78 | +<section class="examples"> |
| 79 | + |
| 80 | +## Examples |
| 81 | + |
| 82 | +<!-- eslint no-undef: "error" --> |
| 83 | + |
| 84 | +```javascript |
| 85 | +var uniform = require( '@stdlib/random/array/uniform' ); |
| 86 | +var bernoulli = require( '@stdlib/random/array/bernoulli' ); |
| 87 | +var ndarray = require( '@stdlib/ndarray/base/ctor' ); |
| 88 | +var ndarray2array = require( '@stdlib/ndarray/to-array' ); |
| 89 | +var snanmskmax = require( '@stdlib/stats/base/ndarray/snanmskmax' ); |
| 90 | + |
| 91 | +var xbuf = uniform( 10, -50.0, 50.0, { |
| 92 | + 'dtype': 'float32' |
| 93 | +}); |
| 94 | +var x = new ndarray( 'float32', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); |
| 95 | +console.log( ndarray2array( x ) ); |
| 96 | + |
| 97 | +var maskbuf = bernoulli( xbuf.length, 0.2, { |
| 98 | + 'dtype': 'uint8' |
| 99 | +}); |
| 100 | +var mask = new ndarray( 'uint8', maskbuf, [ maskbuf.length ], [ 1 ], 0, 'row-major' ); |
| 101 | +console.log( ndarray2array( mask ) ); |
| 102 | + |
| 103 | +var v = snanmskmax( [ x, mask ] ); |
| 104 | +console.log( v ); |
| 105 | +``` |
| 106 | + |
| 107 | +</section> |
| 108 | + |
| 109 | +<!-- /.examples --> |
| 110 | + |
| 111 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 112 | + |
| 113 | +<section class="related"> |
| 114 | + |
| 115 | +</section> |
| 116 | + |
| 117 | +<!-- /.related --> |
| 118 | + |
| 119 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 120 | + |
| 121 | +<section class="links"> |
| 122 | + |
| 123 | +</section> |
| 124 | + |
| 125 | +<!-- /.links --> |
0 commit comments