repl.txt (6637B)
1 2 {{alias}}( [buffer,] [options] ) 3 Returns a multidimensional array. 4 5 Parameters 6 ---------- 7 buffer: Array|TypedArray|Buffer|ndarray (optional) 8 Data source. 9 10 options: Object (optional) 11 Options. 12 13 options.buffer: Array|TypedArray|Buffer|ndarray (optional) 14 Data source. If provided along with a `buffer` argument, the argument 15 takes precedence. 16 17 options.dtype: string (optional) 18 Underlying storage data type. If not specified and a data source is 19 provided, the data type is inferred from the provided data source. If an 20 input data source is not of the same type, this option specifies the 21 data type to which to cast the input data. For non-ndarray generic array 22 data sources, the function casts generic array data elements to the 23 default data type. In order to prevent this cast, the `dtype` option 24 must be explicitly set to `'generic'`. Any time a cast is required, the 25 `copy` option is set to `true`, as memory must be copied from the data 26 source to an output data buffer. Default: 'float64'. 27 28 options.order: string (optional) 29 Specifies the memory layout of the data source as either row-major (C- 30 style) or column-major (Fortran-style). The option may be one of the 31 following values: 32 33 - 'row-major': the order of the returned array is row-major. 34 - 'column-major': the order of the returned array is column-major. 35 - 'any': if a data source is column-major and not row-major, the order 36 of the returned array is column-major; otherwise, the order of the 37 returned array is row-major. 38 - 'same': the order of the returned array matches the order of an input 39 data source. 40 41 Note that specifying an order which differs from the order of a 42 provided data source does *not* entail a conversion from one memory 43 layout to another. In short, this option is descriptive, not 44 prescriptive. Default: 'row-major'. 45 46 options.shape: Array<integer> (optional) 47 Array shape (dimensions). If a shape is not specified, the function 48 attempts to infer a shape based on a provided data source. For example, 49 if provided a nested array, the function resolves nested array 50 dimensions. If provided a multidimensional array data source, the 51 function uses the array's associated shape. For most use cases, such 52 inference suffices. For the remaining use cases, specifying a shape is 53 necessary. For example, provide a shape to create a multidimensional 54 array view over a linear data buffer, ignoring any existing shape meta 55 data associated with a provided data source. 56 57 options.flatten: boolean (optional) 58 Boolean indicating whether to automatically flatten generic array data 59 sources. If an array shape is not specified, the shape is inferred from 60 the dimensions of nested arrays prior to flattening. If a use case 61 requires partial flattening, partially flatten prior to invoking this 62 function and set the option value to `false` to prevent further 63 flattening during invocation. Default: true. 64 65 options.copy: boolean (optional) 66 Boolean indicating whether to (shallow) copy source data to a new data 67 buffer. The function does *not* perform a deep copy. To prevent 68 undesired shared changes in state for generic arrays containing objects, 69 perform a deep copy prior to invoking this function. Default: false. 70 71 options.ndmin: integer (optional) 72 Specifies the minimum number of dimensions. If an array shape has fewer 73 dimensions than required by `ndmin`, the function prepends singleton 74 dimensions to the array shape in order to satisfy the dimensions 75 requirement. Default: 0. 76 77 options.casting: string (optional) 78 Specifies the casting rule used to determine acceptable casts. The 79 option may be one of the following values: 80 81 - 'none': only allow casting between identical types. 82 - 'equiv': allow casting between identical and byte swapped types. 83 - 'safe': only allow "safe" casts. 84 - 'same-kind': allow "safe" casts and casts within the same kind (e.g., 85 between signed integers or between floats). 86 - 'unsafe': allow casting between all types (including between integers 87 and floats). 88 89 Default: 'safe'. 90 91 options.codegen: boolean (optional) 92 Boolean indicating whether to use code generation. Code generation can 93 boost performance, but may be problematic in browser contexts enforcing 94 a strict content security policy (CSP). Default: true. 95 96 options.mode: string (optional) 97 Specifies how to handle indices which exceed array dimensions. The 98 option may be one of the following values: 99 100 - 'throw': an ndarray instance throws an error when an index exceeds 101 array dimensions. 102 - 'wrap': an ndarray instance wraps around indices exceeding array 103 dimensions using modulo arithmetic. 104 - 'clamp', an ndarray instance sets an index exceeding array dimensions 105 to either `0` (minimum index) or the maximum index. 106 107 Default: 'throw'. 108 109 options.submode: Array<string> (optional) 110 Specifies how to handle subscripts which exceed array dimensions. If a 111 mode for a corresponding dimension is equal to 112 113 - 'throw': an ndarray instance throws an error when a subscript exceeds 114 array dimensions. 115 - 'wrap': an ndarray instance wraps around subscripts exceeding array 116 dimensions using modulo arithmetic. 117 - 'clamp': an ndarray instance sets a subscript exceeding array 118 dimensions to either `0` (minimum index) or the maximum index. 119 120 If the number of modes is fewer than the number of dimensions, the 121 function recycles modes using modulo arithmetic. 122 123 Default: [ options.mode ]. 124 125 Returns 126 ------- 127 out: ndarray 128 Multidimensional array. 129 130 Examples 131 -------- 132 // Create a 2x2 matrix: 133 > var arr = {{alias}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ) 134 <ndarray> 135 136 // Get an element using subscripts: 137 > var v = arr.get( 1, 1 ) 138 4.0 139 140 // Get an element using a linear index: 141 > v = arr.iget( 3 ) 142 4.0 143 144 // Set an element using subscripts: 145 > arr.set( 1, 1, 40.0 ); 146 > arr.get( 1, 1 ) 147 40.0 148 149 // Set an element using a linear index: 150 > arr.iset( 3, 99.0 ); 151 > arr.get( 1, 1 ) 152 99.0 153 154 See Also 155 -------- 156