Public Member Functions | |
Tensor (std::vector< unsigned int > shape) | |
Tensor (std::vector< unsigned int > shape, memory_t mem_type) | |
Tensor (std::vector< unsigned int > shape, memory_t mem_type, device_t device_id) | |
Tensor (std::vector< unsigned int > shape, tensor_filler_t< T > filler) | |
Tensor (std::vector< unsigned int > shape, tensor_filler_t< T > filler, memory_t mem_type) | |
Tensor (std::vector< unsigned int > shape, tensor_filler_t< T > filler, memory_t mem_type, device_t device_id) | |
~Tensor () | |
magmadnn_error_t | copy_from (const Tensor< T > &src, unsigned int begin_idx, unsigned int size) |
magmadnn_error_t | copy_from (const Tensor< T > &src) |
magmadnn_error_t | copy_from (const Tensor< T > &src, const std::vector< unsigned int > &dims) |
T | get (const std::vector< int > &idx) const |
T | get (const std::vector< unsigned int > &idx) const |
T | get (const std::initializer_list< int > &idx) const |
T | get (const std::initializer_list< unsigned int > &idx) const |
T | get (unsigned int flattened_idx) const |
const T | operator[] (unsigned int idx) const |
const T | operator[] (const std::initializer_list< unsigned int > &idx) |
void | set (const std::vector< int > &idx, T val) |
void | set (const std::vector< unsigned int > &idx, T val) |
void | set (const std::initializer_list< int > &idx, T val) |
void | set (const std::initializer_list< unsigned int > &idx, T val) |
void | set (unsigned int flattened_idx, T val) |
MemoryManager< T > * | get_memory_manager () const |
std::vector< unsigned int > | get_shape () const |
unsigned int | get_shape (unsigned int idx) const |
unsigned int | get_size () const |
T * | get_ptr () |
memory_t | get_memory_type () const |
device_t | get_device_id () const |
void | reshape (const std::vector< unsigned int > &dims) |
void | squeeze () |
void | unsqueeze (unsigned int dim=0) |
magmadnn::Tensor< T >::Tensor | ( | std::vector< unsigned int > | shape | ) |
Initializes tensor with the given shape. Creates a new memory manager for this tensor. Defaults to the cpu.
shape | a vector of axis sizes |
magmadnn::Tensor< T >::Tensor | ( | std::vector< unsigned int > | shape, |
memory_t | mem_type | ||
) |
Initializes tensor with the given shape. Creates a new memory manager for this tensor.
shape | |
mem_type |
magmadnn::Tensor< T >::Tensor | ( | std::vector< unsigned int > | shape, |
memory_t | mem_type, | ||
device_t | device_id | ||
) |
Initializes tensor with the given shape. Creates a new memory manager for this tensor. Uses the given device type and device id.
shape | a vector of axis sizes |
device | the type of device |
device_id | the id of the device to be used |
magmadnn::Tensor< T >::Tensor | ( | std::vector< unsigned int > | shape, |
tensor_filler_t< T > | filler | ||
) |
Initializes tensor with the given shape. Creates a new memory manager for this tensor. Sets every value of tensor to fill.
shape | a vector of axis sizes |
fill | value to set every element of tensor |
magmadnn::Tensor< T >::Tensor | ( | std::vector< unsigned int > | shape, |
tensor_filler_t< T > | filler, | ||
memory_t | mem_type | ||
) |
shape | |
fill | |
mem_type |
magmadnn::Tensor< T >::Tensor | ( | std::vector< unsigned int > | shape, |
tensor_filler_t< T > | filler, | ||
memory_t | mem_type, | ||
device_t | device_id | ||
) |
Initializes tensor with the given shape, fill, device, and device id. Creates a new memory manager.
shape | a vector of axis sizes |
fill | value to set every element of tensor |
device | device type tensor will use |
device_id | id of device to use |
magmadnn::Tensor< T >::~Tensor | ( | ) |
Free tensor memory
magmadnn_error_t magmadnn::Tensor< T >::copy_from | ( | const Tensor< T > & | src, |
unsigned int | begin_idx, | ||
unsigned int | size | ||
) |
Copies data from src[begin_idx] to src[begin_idx+size] into this tensor.
src | |
begin_idx | |
size |
magmadnn_error_t magmadnn::Tensor< T >::copy_from | ( | const Tensor< T > & | src | ) |
Copies the tensor src into this tensor.
src |
magmadnn_error_t magmadnn::Tensor< T >::copy_from | ( | const Tensor< T > & | src, |
const std::vector< unsigned int > & | dims | ||
) |
Truncates the tensor src to match the dimensions in dims
src | |
dims | should have same size as src.get_shape() |
T magmadnn::Tensor< T >::get | ( | const std::vector< int > & | idx | ) | const |
gets the value at the given index.
idx | indices to retreive value from |
T magmadnn::Tensor< T >::get | ( | const std::vector< unsigned int > & | idx | ) | const |
gets the value at the given index.
idx | indices to retrieve value from |
T magmadnn::Tensor< T >::get | ( | const std::initializer_list< int > & | idx | ) | const |
gets the value at the given index.
idx | indices to retrieve value from |
T magmadnn::Tensor< T >::get | ( | const std::initializer_list< unsigned int > & | idx | ) | const |
gets the value at the given index.
idx | indices to retrieve value from |
T magmadnn::Tensor< T >::get | ( | unsigned int | flattened_idx | ) | const |
gets the value at the given index.
idx | indices to retreive value from |
|
inline |
The device id used by this tensor.
|
inline |
Returns the memory manager used by this tensor
|
inline |
returns the memory type of this tensor
|
inline |
returns the pointer used by the memory manager.
|
inline |
returns a copy of the shape of this tensor.
unsigned int magmadnn::Tensor< T >::get_shape | ( | unsigned int | idx | ) | const |
returns the axis size at idx of shape (i.e. shape[idx])
idx |
|
inline |
returns the number of elements in tensor
const T magmadnn::Tensor< T >::operator[] | ( | unsigned int | idx | ) | const |
Gets the value at the given index.
idx |
void magmadnn::Tensor< T >::reshape | ( | const std::vector< unsigned int > & | dims | ) |
changes shape of tensor to match dims
dims | should have the same size as this->size |
void magmadnn::Tensor< T >::set | ( | const std::vector< int > & | idx, |
T | val | ||
) |
sets the value at the given index.
idx | indices to set value at |
val | value to write into idx |
void magmadnn::Tensor< T >::set | ( | const std::vector< unsigned int > & | idx, |
T | val | ||
) |
sets the value at the given index.
idx | indices to set value at |
val | value to write into idx |
void magmadnn::Tensor< T >::set | ( | const std::initializer_list< int > & | idx, |
T | val | ||
) |
sets the value at the given index.
idx | indices to set value at |
val | value to write into idx |
void magmadnn::Tensor< T >::set | ( | const std::initializer_list< unsigned int > & | idx, |
T | val | ||
) |
sets the value at the given index.
idx | indices to set value at |
val | value to write into idx |
void magmadnn::Tensor< T >::set | ( | unsigned int | flattened_idx, |
T | val | ||
) |
sets the value at the given index.
idx | indices to set value at |
val | value to write into idx |
void magmadnn::Tensor< T >::squeeze | ( | ) |
removes axes with length 1
void magmadnn::Tensor< T >::unsqueeze | ( | unsigned int | dim = 0 | ) |
adds a dimension with length 1 along axis dim
dim |