|
| 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 | +# dnanmaxabs |
| 22 | + |
| 23 | +> Calculate the maximum absolute 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 dnanmaxabs = require( '@stdlib/stats/strided/dnanmaxabs' ); |
| 37 | +``` |
| 38 | + |
| 39 | +#### dnanmaxabs( N, x, strideX ) |
| 40 | + |
| 41 | +Computes the maximum absolute 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 = dnanmaxabs( 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**: stride length for `x`. |
| 57 | + |
| 58 | +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the maximum absolute 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 = dnanmaxabs( 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 = dnanmaxabs( 4, x1, 2 ); |
| 80 | +// returns 4.0 |
| 81 | +``` |
| 82 | + |
| 83 | +#### dnanmaxabs.ndarray( N, x, strideX, offsetX ) |
| 84 | + |
| 85 | +Computes the maximum absolute 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 = dnanmaxabs.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 maximum absolute 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 = dnanmaxabs.ndarray( 4, x, 2, 1 ); |
| 108 | +// returns 4.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 dnanmaxabs = require( '@stdlib/stats/strided/dnanmaxabs' ); |
| 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 = dnanmaxabs( 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/dnanmax.h" |
| 182 | +``` |
| 183 | + |
| 184 | +#### stdlib_strided_dnanmax( N, \*X, strideX ) |
| 185 | + |
| 186 | +Computes the maximum absolute 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_dnanmax( 4, x, 1 ); |
| 192 | +// returns 4.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_dnanmax( const CBLAS_INT N, const double *X, const CBLAS_INT strideX ); |
| 203 | +``` |
| 204 | + |
| 205 | +#### stdlib_strided_dnanmax_ndarray( N, \*X, strideX, offsetX ) |
| 206 | + |
| 207 | +Computes the maximum absolute 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_dnanmax_ndarray( 4, x, 1, 0 ); |
| 213 | +// returns 4.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_dnanmax_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/dnanmaxabs.h" |
| 247 | +#include <stdio.h> |
| 248 | + |
| 249 | +int main( void ) { |
| 250 | + // Create a strided array: |
| 251 | + 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 }; |
| 252 | + |
| 253 | + // Specify the number of elements: |
| 254 | + const int N = 5; |
| 255 | + |
| 256 | + // Specify the stride length: |
| 257 | + const int strideX = 2; |
| 258 | + |
| 259 | + // Compute the maximum absolute value: |
| 260 | + double v = stdlib_strided_dnanmaxabs( N, x, strideX ); |
| 261 | + |
| 262 | + // Print the result: |
| 263 | + printf( "maxabs: %lf\n", v ); |
| 264 | +} |
| 265 | +``` |
| 266 | +
|
| 267 | +</section> |
| 268 | +
|
| 269 | +<!-- /.examples --> |
| 270 | +
|
| 271 | +</section> |
| 272 | +
|
| 273 | +<!-- /.c --> |
| 274 | +
|
| 275 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 276 | +
|
| 277 | +<section class="related"> |
| 278 | +
|
| 279 | +* * * |
| 280 | +
|
| 281 | +## See Also |
| 282 | +
|
| 283 | +- <span class="package-name">[`@stdlib/stats/strided/dmaxabs`][@stdlib/stats/strided/dmaxabs]</span><span class="delimiter">: </span><span class="description">calculate the maximum absolute value of a double-precision floating-point strided array.</span> |
| 284 | +- <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> |
| 285 | +- <span class="package-name">[`@stdlib/stats/base/dnanminabs`][@stdlib/stats/base/dnanminabs]</span><span class="delimiter">: </span><span class="description">calculate the minimum absolute value of a double-precision floating-point strided array, ignoring NaN values.</span> |
| 286 | +- <span class="package-name">[`@stdlib/stats/base/nanmaxabs`][@stdlib/stats/base/nanmaxabs]</span><span class="delimiter">: </span><span class="description">calculate the maximum absolute value of a strided array, ignoring NaN values.</span> |
| 287 | +- <span class="package-name">[`@stdlib/stats/base/snanmaxabs`][@stdlib/stats/base/snanmaxabs]</span><span class="delimiter">: </span><span class="description">calculate the maximum absolute 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/dmaxabs]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/dmaxabs |
| 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/dnanminabs]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/dnanminabs |
| 308 | +
|
| 309 | +[@stdlib/stats/base/nanmaxabs]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/nanmaxabs |
| 310 | +
|
| 311 | +[@stdlib/stats/base/snanmaxabs]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/snanmaxabs |
| 312 | +
|
| 313 | +<!-- </related-links> --> |
| 314 | +
|
| 315 | +</section> |
| 316 | +
|
| 317 | +<!-- /.links --> |
0 commit comments