UNPKG

@stdlib/array

Version:
61 lines (46 loc) 1.98 kB
{{alias}}( dtype ) Returns an accessor function for setting an element in an array-like object supporting the get/set protocol. An accessor function accepts the following arguments: - arr: input array. - idx: element index. - value: value to set. If provided an unsupported `dtype`, the function returns a default accessor function for accessing elements in any indexed array-like object supporting the get/set protocol. Otherwise, the function returns an accessor function which should *only* be provided an array instance corresponding to `dtype` (e.g., if `dtype` is 'complex64', the returned accessor function should only be provided instances of Complex64Array). Accessor functions do *not* verify that provided input arrays are array instances corresponding to `dtype`, as doing so would introduce performance overhead. If array instances corresponding to other data types are provided to an accessor function, JavaScript runtimes will consider the function polymorphic, potentially triggering de-optimization. In order to ensure maximum performance, *always* ensure that an accessor function is monomorphic. Accessor functions do *not* perform bounds checking. Accessor functions do *not* validate input values. Accessor functions do *not* verify that provided input arrays actually implement the get/set protocol. Parameters ---------- dtype: string Array data type. Returns ------- f: Function Accessor function. Examples -------- > var f = {{alias}}( 'complex64' ); > var x = {{alias:@stdlib/array/complex64}}( [ 1, 2, 3, 4 ] ); > f( x, 1, new {{alias:@stdlib/complex/float32/ctor}}( 10.0, 11.0 ) ); > var v = x.get( 1 ) <Complex64> > var r = {{alias:@stdlib/complex/float32/real}}( v ) 10.0 > var i = {{alias:@stdlib/complex/float32/imag}}( v ) 11.0 See Also --------