Skip to content

Latest commit

 

History

History
226 lines (181 loc) · 37 KB

tensor.rst

File metadata and controls

226 lines (181 loc) · 37 KB

Tensor

Tensors are multi-dimension, dense arrays with more than 2 dimensions. Currently 3 - 5 dimension Tensors are supported.

Like :doc:`Array <array>` and :doc:`Matrix <matrix>`, Tensors can only be used in host code. In accelerator code, use :doc:`DRAM <../hw/offchip/dram>` (for off-chip) or :doc:`SRAM <../hw/onchip/sram>` (on-chip) memories for multi-dimensional array support.


Constructors

Spatial includes syntax for constructing Tensor instances from indexed functions.

The following returns a 16 x 32 x 8 Tensor3, with elements defined by func(i,j,k):

(0::16, 0::32, 0::8){(i,j,k) => func(i,j,k) }

A Tensor4 can be constructed in a similar way:

(0::4, 0::16, 0::8, 0::32){(a,b,c,d) => func(a,b,c,d) }

As can a Tensor5:

(0::2, 0::4, 0::5, 0::3, 0::32){(a,b,c,d,e) => func(a,b,c,d,e) }

More general :doc:`Range <../common/range>` forms can also be used, including strided (e.g. 0::2::8) and offset (e.g. 32::64). Iterators (e.g. i, j, k in the above examples) will iterate over all values in their respective ranges.


Static methods

object Tensor3
Returns an immutable Tensor3 with the given dimensions and elements defined by func.
Note that while func does not depend on the index, it is still executed multiple times.
object Tensor4
Returns an immutable Tensor4 with the given dimensions and elements defined by func.
Note that while func does not depend on the index, it is still executed multiple times.
object Tensor5
Returns an immutable Tensor5 with the given dimensions and elements defined by func.
Note that while func does not depend on the index, it is still executed multiple times.

Infix methods

class Tensor3[T]
Returns the first dimension of this Tensor3.
Returns the second dimension of this Tensor3.
Returns the third dimension of this Tensor3.
Returns the element in this Tensor3 at the given 3-dimensional address.
Updates the element at the given 3-dimensional address to elem.
def flatten: :doc:`Array <array>`[T]
Returns a flattened, immutable :doc:`Array <array>` view of this Tensor3's data.
Applies the function func on each element in this Tensor3.
Returns a new Tensor3 created using the mapping func over each element in this Tensor3.
Returns a new Tensor3 created using the pairwise mapping func over each element in this Tensor3
and the corresponding element in that.
def reduce(rfunc: (T,T) => T): T
Reduces the elements in this Tensor3 into a single element using associative function rfunc.
class Tensor4[T]
Returns the first dimension of this Tensor4.
Returns the second dimension of this Tensor4.
Returns the third dimension of this Tensor4.
Returns the fourth dimension of this Tensor4.
Returns the element in this Tensor4 at the given 4-dimensional address.
Updates the element at the given 4-dimensional address to elem.
def flatten: :doc:`Array <array>`[T]
Returns a flattened, immutable :doc:`Array <array>` view of this Tensor4's data.
Applies the function func on each element in this Tensor4.
Returns a new Tensor4 created using the mapping func over each element in this Tensor4.
Returns a new Tensor4 created using the pairwise mapping func over each element in this Tensor4
and the corresponding element in that.
def reduce(rfunc: (T,T) => T): T
Reduces the elements in this Tensor4 into a single element using associative function rfunc.
class Tensor5[T]
Returns the first dimension of this Tensor5.
Returns the second dimension of this Tensor5.
Returns the third dimension of this Tensor5.
Returns the fourth dimension of this Tensor5.
Returns the fifth dimension of this Tensor5.
Returns the element in this Tensor5 at the given 5-dimensional addreess.
def flatten: :doc:`Array <array>`[T]
Returns a flattened, immutable :doc:`Array <array>` view of this Tensor5's data.
Applies the function func on each element in this Tensor5.
Returns a new Tensor5 created using the mapping func over each element in this Tensor5.
Returns a new Tensor5 created using the pairwise mapping func over each element in this Tensor5
and the corresponding element in that.
def reduce(rfunc: (T,T) => T): T
Reduces the elements in this Tensor5 into a single element using associative function rfunc.