repl.txt (2864B)
1 2 {{alias}}( fcns, types, data, nargs, nin, nout ) 3 Returns an ndarray function interface which performs multiple dispatch. 4 5 An ndarray function interface has the following signature: 6 7 f( x, y, ... ) 8 9 where 10 11 - x: ndarray. 12 - y: ndarray. 13 - ...: additional ndarrays. 14 15 The number of parameters is derived from `nargs`, the number of input 16 ndarrays is derived from `nin`, and the number of output ndarrays is derived 17 from `nout`. 18 19 Parameters 20 ---------- 21 fcns: Function|ArrayLikeObject<Function> 22 List of ndarray functions. An ndarray function should have the following 23 signature: 24 25 f( arrays, data ) 26 27 where 28 29 - arrays: array containing input and output ndarrays. 30 - data: ndarray function data (e.g., a callback). 31 32 For convenience, a single ndarray function may be provided which will be 33 invoked whenever the ndarray argument data types match a sequence of 34 types in `types`. Providing a single ndarray function is particularly 35 convenient for the case where, regardless of array data types, 36 traversing arrays remains the same, but the ndarray function `data` 37 differs (e.g., callbacks which differ based on the array data types). 38 39 types: ArrayLikeObject<string> 40 One-dimensional list of ndarray argument data types. 41 42 data: ArrayLikeObject|null 43 ndarray function data (e.g., callbacks). If `null`, a returned ndarray 44 function interface does **not** provide a `data` argument to an invoked 45 ndarray function. 46 47 nargs: integer 48 Total number of ndarray function interface arguments. 49 50 nin: integer 51 Number of input ndarrays. 52 53 nout: integer 54 Number of output ndarrays. 55 56 Returns 57 ------- 58 fcn: Function 59 ndarray function interface. 60 61 Examples 62 -------- 63 // Define ndarray argument data types: 64 > var t = [ 'float64', 'float64', 'float32', 'float32' ]; 65 66 // Define a list of ndarray function data (callbacks): 67 > var d = [ {{alias:@stdlib/math/base/special/abs}}, {{alias:@stdlib/math/base/special/absf}} ]; 68 69 // Create an ndarray function interface for applying unary callbacks: 70 > var f = {{alias}}( {{alias:@stdlib/ndarray/base/unary}}, t, d, 2, 1, 1 ); 71 72 // Create an input ndarray: 73 > var xbuf = new {{alias:@stdlib/array/float64}}( [ -1.0, -2.0, -3.0, -4.0 ] ); 74 > var x = {{alias:@stdlib/ndarray/ctor}}( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); 75 76 // Create an output ndarray: 77 > var ybuf = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] ); 78 > var y = {{alias:@stdlib/ndarray/ctor}}( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); 79 80 // Compute the element-wise absolute value: 81 > f( x, y ); 82 > ybuf 83 <Float64Array>[ 1.0, 2.0, 3.0, 4.0 ] 84 85 See Also 86 -------- 87