The tensor module contains a simple ndimensional array type which is stored in host memory. e.g.
Example:
import nimxla/tensor import math var t = toTensor[float32](1..6).reshape(2, 3) for i in 0 ..< t.dims[0]: t[i, 0] = sqrt(t[i, 0]) echo t
Procs
proc approxEqual[T: ElemType](t1, t2: Tensor[T]; eps = 0.000001): bool
- Checks have same shape and abs(diff) < eps for each element Source Edit
proc readTensor[T: ElemType](filename: string): Tensor[T]
- Read tensor attributes and data from a file as per using the stream read function. Source Edit
proc readTensor[T: ElemType](s: Stream): Tensor[T]
- Read tensor attributes and data from a stream. This will parse data written by write and should also handle other data as long as it is in NPY v1 or v2 format and the data type is supported. Will raise an IOError exception if the data cannot be read. Source Edit
proc reshape[T: ElemType](t: Tensor[T]; dims: varargs[int]): Tensor[T]
- Returns a view of the same tensor with the shape changed. Number of elements in the tensor must be unchanged or will raise an exception. If one of the dimensions is -1 then this value is inferred from the total number of elements. Source Edit
proc setPrintOpts(minWidth = 8; precision = 6; floatMode = ffDefault; threshold = 1000; edgeitems = 4) {....raises: [], tags: [], forbids: [].}
- Set the formatting options for printing the tensor data with the $ operator similar to numpy.set_printoptions. See the strutils package for details of the floatMode option. Source Edit
proc toTensor(values: openArray[int]): Tensor[int64] {....raises: [], tags: [], forbids: [].}
- Create a new 1D int64 tensor from an array of int values Source Edit
proc toTensor[T: ElemType](slice: HSlice[int, int]): Tensor[T]
- Create a new 1D tensor of given type with elements set to the values from iterating over the slice. Source Edit