repl.txt (3281B)
1 2 {{alias}}( N, x, stride, clbk[, thisArg] ) 3 Calculates the maximum value of a strided array via a callback function. 4 5 The `N` and `stride` parameters determine which elements in `x` are accessed 6 at runtime. 7 8 Indexing is relative to the first index. To introduce an offset, use typed 9 array views. 10 11 If `N <= 0`, the function returns `x` unchanged. 12 13 The callback function is provided four arguments: 14 15 - value: array element 16 - aidx: array index 17 - sidx: strided index (offset + aidx*stride) 18 - array: the input array 19 20 The callback function should return a numeric value. 21 22 If the callback function does not return any value (or equivalently, 23 explicitly returns `undefined`), the value is ignored. 24 25 Parameters 26 ---------- 27 N: integer 28 Number of indexed elements. 29 30 x: Array|TypedArray|Object 31 Input array/collection. If provided an object, the object must be array- 32 like (excluding strings and functions). 33 34 stride: integer 35 Index increment for `x`. 36 37 clbk: Function 38 Callback function. 39 40 thisArg: any (optional) 41 Execution context. 42 43 Returns 44 ------- 45 out: number 46 Maximum value. 47 48 Examples 49 -------- 50 // Standard Usage: 51 > function accessor( v ) { return v * 2.0; }; 52 > var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ]; 53 > {{alias}}( x.length, x, 1, accessor ) 54 8.0 55 56 // Using `N` and `stride` parameters: 57 > x = [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ]; 58 > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); 59 > {{alias}}( N, x, 2, accessor ) 60 8.0 61 62 // Using view offsets: 63 > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); 64 > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); 65 > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); 66 > {{alias}}( N, x1, 2, accessor ) 67 -4.0 68 69 {{alias}}.ndarray( N, x, stride, offset, clbk[, thisArg] ) 70 Calculates the maximum value of a strided array via a callback function and 71 using alternative indexing semantics. 72 73 While typed array views mandate a view offset based on the underlying 74 buffer, the `offset` parameter supports indexing semantics based on a 75 starting index. 76 77 Parameters 78 ---------- 79 N: integer 80 Number of indexed elements. 81 82 x: Array|TypedArray|Object 83 Input array/collection. If provided an object, the object must be array- 84 like (excluding strings and functions). 85 86 stride: integer 87 Index increment for `x`. 88 89 offset: integer 90 Starting index of `x`. 91 92 clbk: Function 93 Callback function. 94 95 thisArg: any (optional) 96 Execution context. 97 98 Returns 99 ------- 100 out: number 101 Maximum value. 102 103 Examples 104 -------- 105 // Standard Usage: 106 > function accessor( v ) { return v * 2.0; }; 107 > var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ]; 108 > {{alias}}.ndarray( x.length, x, 1, 0, accessor ) 109 8.0 110 111 // Using an index offset: 112 > x = [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ]; 113 > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); 114 > {{alias}}.ndarray( N, x, 2, 1, accessor ) 115 -4.0 116 117 See Also 118 -------- 119