repl.txt (4528B)
1 2 {{alias}}( N, x, sx, y, sy, fcn, clbk[, thisArg] ) 3 Applies a unary function to each element retrieved from a strided input 4 array according to a callback function and assigns each result to an element 5 in a strided output array. 6 7 The `N` and stride parameters determine which elements in `x` and `y` are 8 accessed at runtime. 9 10 Indexing is relative to the first index. To introduce an offset, use typed 11 array views. 12 13 The callback function is provided six arguments: 14 15 - value: array element 16 - idx: iteration index 17 - xi: strided index (offsetX + idx*sx) 18 - yi: strided index (offsetY + idx*sy) 19 - x: the input array 20 - y: the destination array 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 sx: integer 35 Index increment for `x`. 36 37 y: Array|TypedArray|Object 38 Destination array/collection. If provided an object, the object must be 39 array-like (excluding strings and functions). 40 41 sy: integer 42 Index increment for `y`. 43 44 fcn: Function 45 Unary function to apply to callback return values. 46 47 clbk: Function 48 Callback function. 49 50 thisArg: any (optional) 51 Callback execution context. 52 53 Returns 54 ------- 55 y: Array|TypedArray|Object 56 Destination array/collection. 57 58 Examples 59 -------- 60 // Standard usage: 61 > var x = [ 1.0, -2.0, 3.0, -4.0 ]; 62 > var y = [ 0.0, 0.0, 0.0, 0.0 ]; 63 > function clbk( v ) { return v * 2.0; }; 64 > {{alias}}( x.length, x, 1, y, 1, {{alias:@stdlib/math/base/special/abs}}, clbk ) 65 [ 2.0, 4.0, 6.0, 8.0 ] 66 67 // Using `N` and stride parameters: 68 > y = [ 0.0, 0.0, 0.0, 0.0 ]; 69 > {{alias}}( 2, x, 2, y, -1, {{alias:@stdlib/math/base/special/abs}}, clbk ) 70 [ 6.0, 2.0, 0.0, 0.0 ] 71 72 // Using view offsets: 73 > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0 ] ); 74 > var y0 = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] ); 75 > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); 76 > var y1 = new {{alias:@stdlib/array/float64}}( y0.buffer, y0.BYTES_PER_ELEMENT*2 ); 77 > {{alias}}( 2, x1, -2, y1, 1, {{alias:@stdlib/math/base/special/abs}}, clbk ) 78 <Float64Array>[ 8.0, 4.0 ] 79 > y0 80 <Float64Array>[ 0.0, 0.0, 8.0, 4.0 ] 81 82 83 {{alias}}.ndarray( N, x, sx, ox, y, sy, oy, fcn, clbk[, thisArg] ) 84 Applies a unary function to each element retrieved from a strided input 85 array according to a callback function and assigns each result to an element 86 in a strided output array using alternative indexing semantics. 87 88 While typed array views mandate a view offset based on the underlying 89 buffer, the offsest parameters support indexing semantics 90 based on starting indices. 91 92 Parameters 93 ---------- 94 N: integer 95 Number of indexed elements. 96 97 x: Array|TypedArray|Object 98 Input array/collection. If provided an object, the object must be array- 99 like (excluding strings and functions). 100 101 sx: integer 102 Index increment for `x`. 103 104 ox: integer 105 Starting index for `x`. 106 107 y: Array|TypedArray|Object 108 Destination array/collection. If provided an object, the object must be 109 array-like (excluding strings and functions). 110 111 sy: integer 112 Index increment for `y`. 113 114 oy: integer 115 Starting index for `y`. 116 117 fcn: Function 118 Unary function to apply to callback return values. 119 120 clbk: Function 121 Callback function. 122 123 thisArg: any (optional) 124 Callback execution context. 125 126 Returns 127 ------- 128 y: Array|TypedArray|Object 129 Destination array/collection. 130 131 Examples 132 -------- 133 // Standard usage: 134 > var x = [ 1.0, -2.0, 3.0, -4.0 ]; 135 > var y = [ 0.0, 0.0, 0.0, 0.0 ]; 136 > function clbk( v ) { return v * 2.0; }; 137 > {{alias}}.ndarray( x.length, x, 1, 0, y, 1, 0, {{alias:@stdlib/math/base/special/abs}}, clbk ) 138 [ 2.0, 4.0, 6.0, 8.0 ] 139 140 // Advanced indexing: 141 > x = [ 1.0, -2.0, 3.0, -4.0 ]; 142 > y = [ 0.0, 0.0, 0.0, 0.0 ]; 143 > {{alias}}.ndarray( 2, x, 2, 1, y, -1, y.length-1, {{alias:@stdlib/math/base/special/abs}}, clbk ) 144 [ 0.0, 0.0, 8.0, 4.0 ] 145 146 See Also 147 -------- 148