|
| 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 | +# maxabs |
| 22 | + |
| 23 | +> Calculate the maximum absolute value of a strided array. |
| 24 | +
|
| 25 | +<section class="intro"> |
| 26 | + |
| 27 | +</section> |
| 28 | + |
| 29 | +<!-- /.intro --> |
| 30 | + |
| 31 | +<section class="usage"> |
| 32 | + |
| 33 | +## Usage |
| 34 | + |
| 35 | +```javascript |
| 36 | +var maxabs = require( '@stdlib/stats/strided/maxabs' ); |
| 37 | +``` |
| 38 | + |
| 39 | +#### maxabs( N, x, strideX ) |
| 40 | + |
| 41 | +Computes the maximum absolute value of a strided array `x`. |
| 42 | + |
| 43 | +```javascript |
| 44 | +var x = [ 1.0, -2.0, 2.0 ]; |
| 45 | + |
| 46 | +var v = maxabs( x.length, x, 1 ); |
| 47 | +// returns 2.0 |
| 48 | +``` |
| 49 | + |
| 50 | +The function has the following parameters: |
| 51 | + |
| 52 | +- **N**: number of indexed elements. |
| 53 | +- **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. |
| 54 | +- **strideX**: stride length for `x`. |
| 55 | + |
| 56 | +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`, |
| 57 | + |
| 58 | +```javascript |
| 59 | +var x = [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ]; |
| 60 | + |
| 61 | +var v = maxabs( 4, x, 2 ); |
| 62 | +// returns 4.0 |
| 63 | +``` |
| 64 | + |
| 65 | +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. |
| 66 | + |
| 67 | +<!-- eslint-disable stdlib/capitalized-comments --> |
| 68 | + |
| 69 | +```javascript |
| 70 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 71 | + |
| 72 | +var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); |
| 73 | +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element |
| 74 | + |
| 75 | +var v = maxabs( 4, x1, 2 ); |
| 76 | +// returns 4.0 |
| 77 | +``` |
| 78 | + |
| 79 | +#### maxabs.ndarray( N, x, strideX, offsetX ) |
| 80 | + |
| 81 | +Computes the maximum absolute value of a strided array using alternative indexing semantics. |
| 82 | + |
| 83 | +```javascript |
| 84 | +var x = [ 1.0, -2.0, 2.0 ]; |
| 85 | + |
| 86 | +var v = maxabs.ndarray( x.length, x, 1, 0 ); |
| 87 | +// returns 2.0 |
| 88 | +``` |
| 89 | + |
| 90 | +The function has the following additional parameters: |
| 91 | + |
| 92 | +- **offsetX**: starting index for `x`. |
| 93 | + |
| 94 | +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 |
| 95 | + |
| 96 | +```javascript |
| 97 | +var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; |
| 98 | + |
| 99 | +var v = maxabs.ndarray( 4, x, 2, 1 ); |
| 100 | +// returns 4.0 |
| 101 | +``` |
| 102 | + |
| 103 | +</section> |
| 104 | + |
| 105 | +<!-- /.usage --> |
| 106 | + |
| 107 | +<section class="notes"> |
| 108 | + |
| 109 | +## Notes |
| 110 | + |
| 111 | +- If `N <= 0`, both functions return `NaN`. |
| 112 | +- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). |
| 113 | +- Depending on the environment, the typed versions ([`dmaxabs`][@stdlib/stats/strided/dmaxabs], [`smaxabs`][@stdlib/stats/strided/smaxabs], etc.) are likely to be significantly more performant. |
| 114 | + |
| 115 | +</section> |
| 116 | + |
| 117 | +<!-- /.notes --> |
| 118 | + |
| 119 | +<section class="examples"> |
| 120 | + |
| 121 | +## Examples |
| 122 | + |
| 123 | +<!-- eslint no-undef: "error" --> |
| 124 | + |
| 125 | +```javascript |
| 126 | +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); |
| 127 | +var maxabs = require( '@stdlib/stats/strided/maxabs' ); |
| 128 | + |
| 129 | +var x = discreteUniform( 10, -50, 50, { |
| 130 | + 'dtype': 'float64' |
| 131 | +}); |
| 132 | +console.log( x ); |
| 133 | + |
| 134 | +var v = maxabs( x.length, x, 1 ); |
| 135 | +console.log( v ); |
| 136 | +``` |
| 137 | + |
| 138 | +</section> |
| 139 | + |
| 140 | +<!-- /.examples --> |
| 141 | + |
| 142 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 143 | + |
| 144 | +<section class="related"> |
| 145 | + |
| 146 | +* * * |
| 147 | + |
| 148 | +## See Also |
| 149 | + |
| 150 | +- <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> |
| 151 | +- <span class="package-name">[`@stdlib/stats/base/max`][@stdlib/stats/base/max]</span><span class="delimiter">: </span><span class="description">calculate the maximum value of a strided array.</span> |
| 152 | +- <span class="package-name">[`@stdlib/stats/base/minabs`][@stdlib/stats/base/minabs]</span><span class="delimiter">: </span><span class="description">calculate the minimum absolute value of a strided array.</span> |
| 153 | +- <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> |
| 154 | +- <span class="package-name">[`@stdlib/stats/strided/smaxabs`][@stdlib/stats/strided/smaxabs]</span><span class="delimiter">: </span><span class="description">calculate the maximum absolute value of a single-precision floating-point strided array.</span> |
| 155 | + |
| 156 | +</section> |
| 157 | + |
| 158 | +<!-- /.related --> |
| 159 | + |
| 160 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 161 | + |
| 162 | +<section class="links"> |
| 163 | + |
| 164 | +[mdn-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array |
| 165 | + |
| 166 | +[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray |
| 167 | + |
| 168 | +[@stdlib/array/base/accessor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/accessor |
| 169 | + |
| 170 | +<!-- <related-links> --> |
| 171 | + |
| 172 | +[@stdlib/stats/strided/dmaxabs]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/dmaxabs |
| 173 | + |
| 174 | +[@stdlib/stats/base/max]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/max |
| 175 | + |
| 176 | +[@stdlib/stats/base/minabs]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/minabs |
| 177 | + |
| 178 | +[@stdlib/stats/base/nanmaxabs]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/nanmaxabs |
| 179 | + |
| 180 | +[@stdlib/stats/strided/smaxabs]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/smaxabs |
| 181 | + |
| 182 | +<!-- </related-links> --> |
| 183 | + |
| 184 | +</section> |
| 185 | + |
| 186 | +<!-- /.links --> |
0 commit comments