repl.txt (1813B)
1 2 {{alias}}( shape, strides, offset, ...subscript, mode ) 3 Converts subscripts to a linear index. 4 5 When provided a stride array containing negative strides, if an `offset` is 6 greater than `0`, the function treats subscripts as mapping to a linear 7 index in an underlying data buffer for the array, thus returning a linear 8 index from the perspective of that buffer. If an `offset` is equal to `0`, 9 the function treats subscripts as mapping to a linear index in an array 10 view, thus returning a linear index from the perspective of that view. In 11 short, from the perspective of a view, view data is always ordered. 12 13 When provided fewer modes than dimensions, the function recycles modes using 14 modulo arithmetic. 15 16 Parameters 17 ---------- 18 shape: ArrayLike 19 Array shape. 20 21 strides: ArrayLike 22 Stride array. 23 24 offset: integer 25 Location of the first indexed value based on the stride array. 26 27 subscript: ...integer 28 Subscripts. 29 30 mode: Array<string> 31 Specifies how to handle subscripts which exceed array dimensions for 32 each dimension. If the mode for a dimension is equal to 'throw', the 33 function throws an error when a subscript exceeds array dimensions. If 34 equal to 'wrap', the function wraps around subscripts exceeding array 35 dimensions using modulo arithmetic. If equal to 'clamp', the function 36 sets subscripts exceeding array dimensions to either `0` (minimum index) 37 or the maximum index along a particular dimension. 38 39 Returns 40 ------- 41 idx: integer 42 Linear index. 43 44 Examples 45 -------- 46 > var d = [ 3, 3, 3 ]; 47 > var s = [ 9, 3, 1 ]; 48 > var o = 0; 49 > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) 50 17 51 52 See Also 53 -------- 54