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 | |
---|---|
def tabulate[T::doc:`Type <../typeclasses/type>`](dim0: :doc:`Index <../common/fixpt>`, dim1: :doc:`Index <../common/fixpt>`, dim2: :doc:`Index <../common/fixpt>`)(func: (:doc:`Index <../common/fixpt>`, :doc:`Index <../common/fixpt>`, :doc:`Index <../common/fixpt>`) => T): :doc:`Tensor3 <tensor>`[T]
Returns an immutable Tensor3 with the given dimensions and elements defined by func.
|
|
def fill[T::doc:`Type <../typeclasses/type>`](dim0: :doc:`Index <../common/fixpt>`, dim1: :doc:`Index <../common/fixpt>`, dim2: :doc:`Index <../common/fixpt>`)(func: => T): :doc:`Tensor3 <tensor>`[T]
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 | |
---|---|
def tabulate[T::doc:`Type <../typeclasses/type>`](dim0: :doc:`Index <../common/fixpt>`, dim1: :doc:`Index <../common/fixpt>`, dim2: :doc:`Index <../common/fixpt>`, dim3: :doc:`Index <../common/fixpt>`)(func: (:doc:`Index <../common/fixpt>`, :doc:`Index <../common/fixpt>`, :doc:`Index <../common/fixpt>`, :doc:`Index <../common/fixpt>`) => T): :doc:`Tensor4 <tensor>`[T]
Returns an immutable Tensor4 with the given dimensions and elements defined by func.
|
|
def fill[T::doc:`Type <../typeclasses/type>`](dim0: :doc:`Index <../common/fixpt>`, dim1: :doc:`Index <../common/fixpt>`, dim2: :doc:`Index <../common/fixpt>`, dim3: :doc:`Index <../common/fixpt>`)(func: => T): :doc:`Tensor4 <tensor>`[T]
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 | |
---|---|
def tabulate[T::doc:`Type <../typeclasses/type>`](dim0: :doc:`Index <../common/fixpt>`, dim1: :doc:`Index <../common/fixpt>`, dim2: :doc:`Index <../common/fixpt>`, dim3: :doc:`Index <../common/fixpt>`, dim4: :doc:`Index <../common/fixpt>`)(func: (:doc:`Index <../common/fixpt>`, :doc:`Index <../common/fixpt>`, :doc:`Index <../common/fixpt>`, :doc:`Index <../common/fixpt>`, :doc:`Index <../common/fixpt>`) => T): :doc:`Tensor5 <tensor>`[T]
Returns an immutable Tensor5 with the given dimensions and elements defined by func.
|
|
def fill[T::doc:`Type <../typeclasses/type>`](dim0: :doc:`Index <../common/fixpt>`, dim1: :doc:`Index <../common/fixpt>`, dim2: :doc:`Index <../common/fixpt>`, dim3: :doc:`Index <../common/fixpt>`, dim4: :doc:`Index <../common/fixpt>`)(func: => T): :doc:`Tensor5 <tensor>`[T]
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] | |
---|---|
def dim0: :doc:`Index <../common/fixpt>`
Returns the first dimension of this Tensor3.
|
|
def dim1: :doc:`Index <../common/fixpt>`
Returns the second dimension of this Tensor3.
|
|
def dim2: :doc:`Index <../common/fixpt>`
Returns the third dimension of this Tensor3.
|
|
def apply(i: :doc:`Index <../common/fixpt>`, j: :doc:`Index <../common/fixpt>`, k: :doc:`Index <../common/fixpt>`): T
Returns the element in this Tensor3 at the given 3-dimensional address.
|
|
def update(i: :doc:`Index <../common/fixpt>`, j: :doc:`Index <../common/fixpt>`, k: :doc:`Index <../common/fixpt>`, elem: T): :doc:`Unit <../common/unit>`
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.
|
|
def foreach(func: T => :doc:`Unit <../common/unit>`): :doc:`Unit <../common/unit>`
Applies the function func on each element in this Tensor3.
|
|
def map[R::doc:`Type <../typeclasses/type>`](func: T => R): :doc:`Tensor3 <tensor>`[R]
Returns a new Tensor3 created using the mapping func over each element in this Tensor3.
|
|
def zip[S,R::doc:`Type <../typeclasses/type>`](that: :doc:`Tensor3 <tensor>`[S])(func: (T,S) => R): :doc:`Tensor3 <tensor>`[R]
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] | |
---|---|
def dim0: :doc:`Index <../common/fixpt>`
Returns the first dimension of this Tensor4.
|
|
def dim1: :doc:`Index <../common/fixpt>`
Returns the second dimension of this Tensor4.
|
|
def dim2: :doc:`Index <../common/fixpt>`
Returns the third dimension of this Tensor4.
|
|
def dim3: :doc:`Index <../common/fixpt>`
Returns the fourth dimension of this Tensor4.
|
|
def apply(i: :doc:`Index <../common/fixpt>`, j: :doc:`Index <../common/fixpt>`, k: :doc:`Index <../common/fixpt>`, l: :doc:`Index <../common/fixpt>`): T
Returns the element in this Tensor4 at the given 4-dimensional address.
|
|
def update(i: :doc:`Index <../common/fixpt>`, j: :doc:`Index <../common/fixpt>`, k: :doc:`Index <../common/fixpt>`, l: :doc:`Index <../common/fixpt>`, elem: T): :doc:`Unit <../common/unit>`
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.
|
|
def foreach(func: T => :doc:`Unit <../common/unit>`): :doc:`Unit <../common/unit>`
Applies the function func on each element in this Tensor4.
|
|
def map[R::doc:`Type <../typeclasses/type>`](func: T => R): :doc:`Tensor4 <tensor>`[R]
Returns a new Tensor4 created using the mapping func over each element in this Tensor4.
|
|
def zip[S,R::doc:`Type <../typeclasses/type>`](b: :doc:`Tensor4 <tensor>`[S])(func: (T,S) => R): :doc:`Tensor4 <tensor>`[R]
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] | |
---|---|
def dim0: :doc:`Index <../common/fixpt>`
Returns the first dimension of this Tensor5.
|
|
def dim1: :doc:`Index <../common/fixpt>`
Returns the second dimension of this Tensor5.
|
|
def dim2: :doc:`Index <../common/fixpt>`
Returns the third dimension of this Tensor5.
|
|
def dim3: :doc:`Index <../common/fixpt>`
Returns the fourth dimension of this Tensor5.
|
|
def dim4: :doc:`Index <../common/fixpt>`
Returns the fifth dimension of this Tensor5.
|
|
def apply(i: :doc:`Index <../common/fixpt>`, j: :doc:`Index <../common/fixpt>`, k: :doc:`Index <../common/fixpt>`, l: :doc:`Index <../common/fixpt>`, m: :doc:`Index <../common/fixpt>`): T
Returns the element in this Tensor5 at the given 5-dimensional addreess.
|
|
def update(i: :doc:`Index <../common/fixpt>`, j: :doc:`Index <../common/fixpt>`, k: :doc:`Index <../common/fixpt>`, l: :doc:`Index <../common/fixpt>`, m: :doc:`Index <../common/fixpt>`, elem: T): :doc:`Unit <../common/unit>`
Updates the element at the given 5-dimensional address to elem.
|
|
def flatten: :doc:`Array <array>`[T]
Returns a flattened, immutable :doc:`Array <array>` view of this Tensor5's data.
|
|
def foreach(func: T => :doc:`Unit <../common/unit>`): :doc:`Unit <../common/unit>`
Applies the function func on each element in this Tensor5.
|
|
def map[R::doc:`Type <../typeclasses/type>`](func: T => R): :doc:`Tensor5 <tensor>`[R]
Returns a new Tensor5 created using the mapping func over each element in this Tensor5.
|
|
def zip[S,R::doc:`Type <../typeclasses/type>`](b: :doc:`Tensor5 <tensor>`[S])(func: (T,S) => R): :doc:`Tensor5 <tensor>`[R]
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.
|