Class to represent multidimensional arrays.
More...
#include <tensor.h>
|
void | computeSize () |
| Compute the total size of the tensor based on its shape.
|
|
size_t | findEffectiveAddress (const std::vector< size_t > &index, size_t depth) const |
| Finds the address of an element in the flattened data array given its index in non-flattened tensor. More...
|
|
void | verifyIndex (const std::vector< size_t > &index) const |
| Verify that an index of an element is within the shape of the tensor. More...
|
|
Class to represent multidimensional arrays.
◆ Tensor() [1/3]
Tensor::Tensor |
( |
const Tensor & |
other | ) |
|
The copy constructor.
- Parameters
-
other | The tensor based on which this one should be initialized. |
◆ Tensor() [2/3]
Tensor::Tensor |
( |
std::vector< size_t > |
shape | ) |
|
|
explicit |
Tensor constructor with shape given directly by a vector.
- Parameters
-
shape | The shape of the vector to create. |
◆ Tensor() [3/3]
template<typename... Args>
Tensor::Tensor |
( |
Args... |
args | ) |
|
|
inlineexplicit |
Construct a tensor based on the passed shape.
For example Tensor(2, 2, 3)
will initialize a 3D tensor with two 2x3 matrices.
- Parameters
-
args | The shapes of consecutive dimensions. |
◆ construct1d()
Tensor Tensor::construct1d |
( |
const std::vector< float > & |
data | ) |
|
|
static |
Static method to easily initialize a 1D tensor with given data.
- Parameters
-
data | The data based on which a tensor should be constructed. |
- Returns
- The constructed tensor.
◆ construct2d()
Tensor Tensor::construct2d |
( |
const std::vector< std::vector< float >> & |
data | ) |
|
|
static |
Static method to easily initialize a 2D tensor with given data.
- Parameters
-
data | The data based on which a tensor should be constructed. |
- Returns
- The constructed tensor.
◆ findEffectiveAddress()
size_t Tensor::findEffectiveAddress |
( |
const std::vector< size_t > & |
index, |
|
|
size_t |
depth |
|
) |
| const |
|
private |
Finds the address of an element in the flattened data array given its index in non-flattened tensor.
Since the method works recursively, it also takes the depth
parameter, which provides information about which dimension is currently taken into account when computing the index.
- Parameters
-
index | The multidimensional index of the element to access. |
depth | The dimension that is currently considered in the recursive call. |
- Returns
- The address of the element in the flattened data array.
◆ move()
Move the tensor to the designated destination.
This involves copying the data to the new location and releasing memory from the old location.
- Parameters
-
target | The destination to move the tensor to. |
◆ operator()()
template<typename... Args>
float& Tensor::operator() |
( |
Args... |
args | ) |
|
|
inline |
Method to access an element of the tensor at a specific method.
This method should not be used in performance critical operations. In these cases a direct access to Tensor::data will be more appropriate (as it becomes easier for the compiler to optimize such code).
- Parameters
-
args | The index of the element to access. |
- Returns
- A reference to the requested element.
◆ operator=()
The assignment operator.
This releases all the current memory and copies all the information of the other
tensor.
- Parameters
-
other | The other tensor to assign this one to. |
- Returns
- Assigned tensor. Always returns *this.
◆ verifyIndex()
void Tensor::verifyIndex |
( |
const std::vector< size_t > & |
index | ) |
const |
|
private |
Verify that an index of an element is within the shape of the tensor.
- Parameters
-
index | The index of the element that is being accessed. |
◆ location
The location of the tensor.
Can be either HOST or DEVICE. See DataLocation for more details.
◆ size
Store the total size of the tensor.
The size is equal to the number of elements that can be contained in the tensor. It is computed in the Tensor::computeSize() method.
The documentation for this class was generated from the following files: