Serializes ndarray meta data.
Serialization is performed according to host byte order (endianness).
Meta data format:
| <endianness> (1 byte) | <dtype> (2 bytes) | <ndims> (8 bytes) | <shape> (ndims*8 bytes) | <strides> (ndims*8 bytes) | <offset> (8 bytes) | <order> (1 byte) | <mode> (1 byte) | <nsubmodes> (8 bytes) | <submodes> (nsubmodes*1 bytes) | <flags> (4 bytes) |
which translates to the following ArrayBuffer layout:
ArrayBuffer
ArrayBuffer[ <endianness>[int8], <dtype>[int16], <ndims>[int64], <shape>[ndims*int64], <strides>[ndims*int64], <offset>[int64], <order>[int8], <mode>[int8], <nsubmodes>[int64], <submodes>[nsubmodes*int8] <flags>[int32] ]
where strides and offset are in units of bytes.
strides
offset
If the endianness is 1, the byte order is little endian. If the endianness is 0, the byte order is big endian.
1
0
Buffer length:
1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes
For example, consider a three-dimensional ndarray with one subscript index mode (submode):
33 + (3*16) + 1 = 82 bytes
Views:
Int8Array( buf, 0, 1 )
Int16Array( buf, 1, 1 )
Int64Array( buf, 3, 1 )
Int64Array( buf, 11, ndims )
Int64Array( buf, 11+(ndims*8), ndims )
Int64Array( buf, 11+(ndims*16), 1 )
Int8Array( buf, 19+(ndims*16), 1 )
Int8Array( buf, 20+(ndims*16), 1 )
Int64Array( buf, 21+(ndims*16), 1 )
Int8Array( buf, 29+(ndims*16), nsubmodes )
Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)
input ndarray
serialized meta data
var array = require( `@stdlib/ndarray/array` ); var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); var dv = serialize( x ); // returns <DataView>
Serializes ndarray meta data.
Notes
Serialization is performed according to host byte order (endianness).
Meta data format:
which translates to the following
ArrayBuffer
layout:where
strides
andoffset
are in units of bytes.If the endianness is
1
, the byte order is little endian. If the endianness is0
, the byte order is big endian.Buffer length:
For example, consider a three-dimensional ndarray with one subscript index mode (submode):
Views:
Int8Array( buf, 0, 1 )
Int16Array( buf, 1, 1 )
Int64Array( buf, 3, 1 )
Int64Array( buf, 11, ndims )
Int64Array( buf, 11+(ndims*8), ndims )
Int64Array( buf, 11+(ndims*16), 1 )
Int8Array( buf, 19+(ndims*16), 1 )
Int8Array( buf, 20+(ndims*16), 1 )
Int64Array( buf, 21+(ndims*16), 1 )
Int8Array( buf, 29+(ndims*16), nsubmodes )
Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)