strided2object

Convert a strided array and associated metadata to an object likely to have the same "shape".

Usage

var strided2object = require( '@stdlib/wasm/base/strided2object' );

strided2object( N, x, stride, offset )

Converts a strided array and associated metadata to an object likely to have the same "shape".

var obj = strided2object( 4, [ 1, 2, 3, 4 ], 1, 0 );
// returns {...}

Notes

  • The returned object has the following properties:

    • data: reference to the input array.
    • dtype: input array data type. If unable to resolve the data type of the input array, the property value is null.
    • wdtype: WebAssembly data type.
    • length: number of indexed elements.
    • stride: index increment.
    • offset: starting index.
    • accessorProtocol: boolean indicating whether the input uses accessors for getting and setting elements.
    • accessors: a two-element array whose first element is an accessor for retrieving an array element (i.e., a getter) and whose second element is an accessor for setting an array element (i.e., a setter).
  • The getter accessor accepts two arguments:

    • data: input array.
    • idx: element index.
  • The setter accessor accepts three arguments:

    • data: input array.
    • idx: element index.
    • value: value to set.
  • This function is intended as a potential performance optimization. In V8, for example, even if two objects share common properties, if those properties were added in different orders or if one object has additional properties not shared by the other object, then those objects will have different "hidden" classes. If a function is provided many objects having different "shapes", some JavaScript VMs (e.g., V8) will consider the function "megamorphic" and fail to perform various runtime optimizations. Accordingly, the intent of this function is to standardize the "shape" of the object holding strided array metadata to ensure that internal functions operating on strided arrays are provided consistent argument "shapes".

Examples

var Complex64Array = require( '@stdlib/array/complex64' );
var strided2object = require( '@stdlib/wasm/base/strided2object' );

// Create an array:
var x = new Complex64Array( 10 );

// Convert to a standardized object:
var obj = strided2object( x.length, x, 1, 0 );
// returns {...}

console.log( obj );
Did you find this page helpful?