README.md (4419B)
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 # dmaxsorted 22 23 > Calculate the maximum value of a sorted double-precision floating-point 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 dmaxsorted = require( '@stdlib/stats/base/dmaxsorted' ); 37 ``` 38 39 #### dmaxsorted( N, x, stride ) 40 41 Computes the maximum value of a sorted double-precision floating-point strided array `x`. 42 43 ```javascript 44 var Float64Array = require( '@stdlib/array/float64' ); 45 46 var x = new Float64Array( [ 1.0, 2.0, 3.0 ] ); 47 var N = x.length; 48 49 var v = dmaxsorted( N, x, 1 ); 50 // returns 3.0 51 52 x = new Float64Array( [ 3.0, 2.0, 1.0 ] ); 53 N = x.length; 54 55 v = dmaxsorted( N, x, 1 ); 56 // returns 3.0 57 ``` 58 59 The function has the following parameters: 60 61 - **N**: number of indexed elements. 62 - **x**: sorted input [`Float64Array`][@stdlib/array/float64]. 63 - **stride**: index increment for `x`. 64 65 The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to compute the maximum value of every other element in `x`, 66 67 ```javascript 68 var Float64Array = require( '@stdlib/array/float64' ); 69 var floor = require( '@stdlib/math/base/special/floor' ); 70 71 var x = new Float64Array( [ 1.0, 2.0, 2.0, -7.0, 3.0, 3.0, 4.0, 2.0 ] ); 72 var N = floor( x.length / 2 ); 73 74 var v = dmaxsorted( N, x, 2 ); 75 // returns 4.0 76 ``` 77 78 Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. 79 80 <!-- eslint-disable stdlib/capitalized-comments --> 81 82 ```javascript 83 var Float64Array = require( '@stdlib/array/float64' ); 84 var floor = require( '@stdlib/math/base/special/floor' ); 85 86 var x0 = new Float64Array( [ 2.0, 1.0, 2.0, 2.0, -2.0, 2.0, 3.0, 4.0 ] ); 87 var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element 88 89 var N = floor( x0.length / 2 ); 90 91 var v = dmaxsorted( N, x1, 2 ); 92 // returns 4.0 93 ``` 94 95 #### dmaxsorted.ndarray( N, x, stride, offset ) 96 97 Computes the maximum value of a sorted double-precision floating-point strided array using alternative indexing semantics. 98 99 ```javascript 100 var Float64Array = require( '@stdlib/array/float64' ); 101 102 var x = new Float64Array( [ 1.0, 2.0, 3.0 ] ); 103 var N = x.length; 104 105 var v = dmaxsorted.ndarray( N, x, 1, 0 ); 106 // returns 3.0 107 ``` 108 109 The function has the following additional parameters: 110 111 - **offset**: starting index for `x`. 112 113 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 value for every other value in `x` starting from the second value 114 115 ```javascript 116 var Float64Array = require( '@stdlib/array/float64' ); 117 var floor = require( '@stdlib/math/base/special/floor' ); 118 119 var x = new Float64Array( [ 2.0, 1.0, 2.0, 2.0, -2.0, 2.0, 3.0, 4.0 ] ); 120 var N = floor( x.length / 2 ); 121 122 var v = dmaxsorted.ndarray( N, x, 2, 1 ); 123 // returns 4.0 124 ``` 125 126 </section> 127 128 <!-- /.usage --> 129 130 <section class="notes"> 131 132 ## Notes 133 134 - If `N <= 0`, both functions return `NaN`. 135 - The input strided array must be sorted in either **strictly** ascending or descending order. 136 137 </section> 138 139 <!-- /.notes --> 140 141 <section class="examples"> 142 143 ## Examples 144 145 <!-- eslint no-undef: "error" --> 146 147 ```javascript 148 var Float64Array = require( '@stdlib/array/float64' ); 149 var dmaxsorted = require( '@stdlib/stats/base/dmaxsorted' ); 150 151 var x; 152 var i; 153 154 x = new Float64Array( 10 ); 155 for ( i = 0; i < x.length; i++ ) { 156 x[ i ] = i - 5.0; 157 } 158 console.log( x ); 159 160 var v = dmaxsorted( x.length, x, 1 ); 161 console.log( v ); 162 ``` 163 164 </section> 165 166 <!-- /.examples --> 167 168 <section class="links"> 169 170 [@stdlib/array/float64]: https://www.npmjs.com/package/@stdlib/array-float64 171 172 [mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray 173 174 </section> 175 176 <!-- /.links -->