Class Tensor
Description
N Dimensional data view, that helps create, store, manipulate data.
Params
dtype | string | the data type for tensor instance |
shape | Array.<number> | the list of integers, |
data? | TypedArray | Array | initial data to store |
stride? | Array.<number> | custom mapping from plain to NDArray |
offset? | number | number of data elements to skip |
Methods
get (...x) => number
Get data element by coordinates
x | number | coordinates
Require N number arguments, where n - dimention of a tensor. |
const t = new gm.Tensor('uint8', [2, 3], new Uint8Array([1, 2, 3, 4, 5, 6]));
t.get(0, 0); // 1
t.get(0, 1); // 2
t.get(1, 2); // 6
set (...x, v) => void
Put value to tensor by coordinates
x | number | coordinates |
v | number | value |
const t = new gm.Tensor('uint8', [2, 3], new Uint8Array([1, 2, 3, 4, 5, 6]));
t.set(0, 0, 10); // 1
t.set(0, 1, 15); // 2
t.set(1, 2, 20); // 6
console.log(t.data); // <Uint8Array[10, 15, 3, 4, 5, 20]>
index (...x) => number
Get's index in plain data view of data element specified by coordinates
x | number | coordinates
Require N number arguments, where n - dimention of a tensor. |
const t = new gm.Tensor('uint8', [2, 3], new Uint8Array([1, 2, 3, 4, 5, 6]));
t.index(0, 0); // 0
t.index(0, 1); // 1
t.index(1, 2); // 5
Tensor.assign (data) => Tensor (self)
release () => Tensor (self)
Write zeros into tensor's data
clone () => Tensor (a shallow copy, new instance)
Static IndexToCoord (shape, index) => Array.<number> (coordinets that maps to the entered index)
shape | Array.<number> | |
index | number | |
Static CoordToIndex (shape, coords) => number (index that mapped from entered coords)
shape | Array.<number> | |
coords | Array.<number> | |
Static Malloc (dtype, size) => Tensor
Static DefineType (data) => string
Define data type of an argument
gm.Tensor.DefineType(new Float32Array()); // float32
Static GetTypedArray (dtype, data) => TypedArray | Array
Generate TypedArray
dtype | string | data type of view |
data | TypedArray | Array | initial data |
Static GetSize (shape) => number (Number of elements that described by shape)