You need to enable JavaScript to run this app.Tensor - GammaCV
GammaCV Logo
DocsExamplesGitHub

Class Tensor

Description

N Dimensional data view, that helps create, store, manipulate data.

Params
dtypestringthe data type for tensor instance
shapeArray.<number>the list of integers,
data?TypedArray | Arrayinitial data to store
stride?Array.<number>custom mapping from plain to NDArray
offset?numbernumber of data elements to skip
Methods

get (...x) => number

Get data element by coordinates

xnumbercoordinates

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

xnumbercoordinates
vnumbervalue
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

xnumbercoordinates

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)

dataTypedArray | Array

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)

shapeArray.<number>
indexnumber

Static CoordToIndex (shape, coords) => number (index that mapped from entered coords)

shapeArray.<number>
coordsArray.<number>

Static Malloc (dtype, size) => Tensor

dtypestring
sizenumber

Static DefineType (data) => string

Define data type of an argument

dataTypedArray | Array
gm.Tensor.DefineType(new Float32Array()); // float32

Static GetTypedArray (dtype, data) => TypedArray | Array

Generate TypedArray

dtypestringdata type of view
dataTypedArray | Arrayinitial data

Static GetSize (shape) => number (Number of elements that described by shape)

shapeArray.<number>