repl.txt (4083B)
1 2 {{alias}}( table ) 3 Returns a function which dispatches to specified functions based on input 4 argument types. 5 6 A `table` resolution object may contain one or more of the following fields: 7 8 - scalar: strided look-up table for scalar arguments. 9 - array: strided look-up table for array-like object arguments. 10 - ndarray: strided look-up table for ndarray arguments. 11 12 Each strided look-up table should be comprised as follows: 13 14 [ <dtype>, <fcn>, <dtype>, <fcn>, ... ] 15 16 If an argument's data type is *not* found in the argument's corresponding 17 look-up table and if a 'generic' data type is present in that same table, 18 the returned dispatch function will resolve the "generic" implementation. In 19 other words, an implementation associated with a 'generic' data type will be 20 treated as the default implementation. 21 22 If unable to resolve an implementation for a provided argument data type, 23 the returned function throws an error. 24 25 If provided a number, the returned function returns a number. 26 27 If provided an ndarray or array-like object, the returned function performs 28 element-wise computation. 29 30 If provided an array-like object, the returned function returns an array- 31 like object having the same length and data type as the provided input 32 argument. 33 34 If provided an ndarray, the returned function returns an ndarray having the 35 same shape and data type as the provided input argument. 36 37 Parameters 38 ---------- 39 table: Object 40 Table resolution object. 41 42 table.scalar: ArrayLikeObject (optional) 43 Strided look-up table for scalar arguments. Supported data types: 44 'number' and 'complex'. 45 46 table.array: ArrayLikeObject (optional) 47 Strided look-up table for array-like object arguments. Implementation 48 functions must follow strided array interface argument conventions: 49 50 fcn( N, x, strideX, y, strideY ) 51 52 where 53 54 - N: number of indexed elements. 55 - x: input strided array. 56 - strideX: index increment for `x`. 57 - y: destination strided array. 58 - strideY: index increment for `y`. 59 60 Supported array data types consist of all supported ndarray data types. 61 62 table.ndarray: ArrayLikeObject (optional) 63 Strided look-up table for ndarray arguments. Implementation functions 64 must follow strided array ndarray interface argument conventions: 65 66 fcn( N, x, strideX, offsetX, y, strideY, offsetY ) 67 68 where 69 70 - N: number of indexed elements. 71 - x: input strided array (i.e., underlying input ndarray buffer). 72 - strideX: index increment for `x`. 73 - offsetX: starting index for `x`. 74 - y: destination strided array (i.e., underlying output ndarray buffer). 75 - strideY: index increment for `y`. 76 - offsetY: starting index for `y`. 77 78 Supported data types consist of all supported ndarray data types. 79 80 Returns 81 ------- 82 fcn: Function 83 Dispatch function. 84 85 Examples 86 -------- 87 > var t = {}; 88 > t.scalar = [ 'number', {{alias:@stdlib/math/base/special/abs}} ]; 89 > t.array = [ 90 ... 'float64', {{alias:@stdlib/math/strided/special/dabs}}, 91 ... 'float32', {{alias:@stdlib/math/strided/special/sabs}}, 92 ... 'generic', {{alias:@stdlib/math/strided/special/abs}} 93 ... ]; 94 > t.ndarray = [ 95 ... 'float64', {{alias:@stdlib/math/strided/special/dabs}}.ndarray, 96 ... 'float32', {{alias:@stdlib/math/strided/special/sabs}}.ndarray, 97 ... 'generic', {{alias:@stdlib/math/strided/special/abs}}.ndarray 98 ... ]; 99 > var fcn = {{alias}}( t ); 100 101 // Provide a number: 102 > var y = fcn( -1.0 ) 103 1.0 104 105 // Provide an array-like object: 106 > var x = new {{alias:@stdlib/array/float64}}( [ -1.0, -2.0 ] ); 107 > y = fcn( x ) 108 <Float64Array>[ 1.0, 2.0 ] 109 110 // Provide an ndarray: 111 > x = {{alias:@stdlib/ndarray/array}}( [ [ -1.0, -2.0 ], [ -3.0, -4.0 ] ] ); 112 > y = fcn( x ) 113 <ndarray> 114 > y.get( 0, 1 ) 115 2.0 116 117 See Also 118 -------- 119