MagmaDNN  1.0
c++NeuralNetworkFramework
magmadnn::Tensor< T > Class Template Reference

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)
 
get (const std::vector< int > &idx) const
 
get (const std::vector< unsigned int > &idx) const
 
get (const std::initializer_list< int > &idx) const
 
get (const std::initializer_list< unsigned int > &idx) const
 
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)
 

Constructor & Destructor Documentation

◆ Tensor() [1/6]

template<typename T >
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.

Parameters
shapea vector of axis sizes

◆ Tensor() [2/6]

template<typename T >
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.

Parameters
shape
mem_type

◆ Tensor() [3/6]

template<typename T >
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.

Parameters
shapea vector of axis sizes
devicethe type of device
device_idthe id of the device to be used

◆ Tensor() [4/6]

template<typename T >
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.

Parameters
shapea vector of axis sizes
fillvalue to set every element of tensor

◆ Tensor() [5/6]

template<typename T >
magmadnn::Tensor< T >::Tensor ( std::vector< unsigned int >  shape,
tensor_filler_t< T >  filler,
memory_t  mem_type 
)
Parameters
shape
fill
mem_type

◆ Tensor() [6/6]

template<typename T >
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.

Parameters
shapea vector of axis sizes
fillvalue to set every element of tensor
devicedevice type tensor will use
device_idid of device to use

◆ ~Tensor()

template<typename T >
magmadnn::Tensor< T >::~Tensor ( )

Free tensor memory

Member Function Documentation

◆ copy_from() [1/3]

template<typename T >
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.

Parameters
src
begin_idx
size
Returns
magmadnn_error_t non-zero if error
Here is the call graph for this function:
Here is the caller graph for this function:

◆ copy_from() [2/3]

template<typename T >
magmadnn_error_t magmadnn::Tensor< T >::copy_from ( const Tensor< T > &  src)

Copies the tensor src into this tensor.

Parameters
src
Returns
magmadnn_error_t non-zero if error.
Here is the call graph for this function:

◆ copy_from() [3/3]

template<typename T >
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

Parameters
src
dimsshould have same size as src.get_shape()
Returns
magmadnn_error_t non-zero if error
Here is the call graph for this function:

◆ get() [1/5]

template<typename T >
T magmadnn::Tensor< T >::get ( const std::vector< int > &  idx) const

gets the value at the given index.

Parameters
idxindices to retreive value from
Returns
the value at idx
Here is the caller graph for this function:

◆ get() [2/5]

template<typename T >
T magmadnn::Tensor< T >::get ( const std::vector< unsigned int > &  idx) const

gets the value at the given index.

Parameters
idxindices to retrieve value from
Returns
T the value at idx

◆ get() [3/5]

template<typename T >
T magmadnn::Tensor< T >::get ( const std::initializer_list< int > &  idx) const

gets the value at the given index.

Parameters
idxindices to retrieve value from
Returns
T the value at idx

◆ get() [4/5]

template<typename T >
T magmadnn::Tensor< T >::get ( const std::initializer_list< unsigned int > &  idx) const

gets the value at the given index.

Parameters
idxindices to retrieve value from
Returns
T the value at idx

◆ get() [5/5]

template<typename T >
T magmadnn::Tensor< T >::get ( unsigned int  flattened_idx) const

gets the value at the given index.

Parameters
idxindices to retreive value from
Returns
the value at idx

◆ get_device_id()

template<typename T>
device_t magmadnn::Tensor< T >::get_device_id ( ) const
inline

The device id used by this tensor.

Returns
device_t
Here is the call graph for this function:

◆ get_memory_manager()

template<typename T>
MemoryManager<T>* magmadnn::Tensor< T >::get_memory_manager ( ) const
inline

Returns the memory manager used by this tensor

Returns
MemoryManager<T>*
Here is the caller graph for this function:

◆ get_memory_type()

template<typename T>
memory_t magmadnn::Tensor< T >::get_memory_type ( ) const
inline

returns the memory type of this tensor

Returns
memory_t
Here is the caller graph for this function:

◆ get_ptr()

template<typename T>
T* magmadnn::Tensor< T >::get_ptr ( )
inline

returns the pointer used by the memory manager.

Returns
T*

◆ get_shape() [1/2]

template<typename T>
std::vector<unsigned int> magmadnn::Tensor< T >::get_shape ( ) const
inline

returns a copy of the shape of this tensor.

Returns
std::vector<int>
Here is the caller graph for this function:

◆ get_shape() [2/2]

template<typename T >
unsigned int magmadnn::Tensor< T >::get_shape ( unsigned int  idx) const

returns the axis size at idx of shape (i.e. shape[idx])

Parameters
idx
Returns
unsigned int

◆ get_size()

template<typename T>
unsigned int magmadnn::Tensor< T >::get_size ( ) const
inline

returns the number of elements in tensor

Returns
unsigned int total number of elements in tensor
Here is the caller graph for this function:

◆ operator[]()

template<typename T >
const T magmadnn::Tensor< T >::operator[] ( unsigned int  idx) const

Gets the value at the given index.

Parameters
idx
Returns
const T

◆ reshape()

template<typename T >
void magmadnn::Tensor< T >::reshape ( const std::vector< unsigned int > &  dims)

changes shape of tensor to match dims

Parameters
dimsshould have the same size as this->size
Here is the caller graph for this function:

◆ set() [1/5]

template<typename T >
void magmadnn::Tensor< T >::set ( const std::vector< int > &  idx,
val 
)

sets the value at the given index.

Parameters
idxindices to set value at
valvalue to write into idx

◆ set() [2/5]

template<typename T >
void magmadnn::Tensor< T >::set ( const std::vector< unsigned int > &  idx,
val 
)

sets the value at the given index.

Parameters
idxindices to set value at
valvalue to write into idx

◆ set() [3/5]

template<typename T >
void magmadnn::Tensor< T >::set ( const std::initializer_list< int > &  idx,
val 
)

sets the value at the given index.

Parameters
idxindices to set value at
valvalue to write into idx

◆ set() [4/5]

template<typename T >
void magmadnn::Tensor< T >::set ( const std::initializer_list< unsigned int > &  idx,
val 
)

sets the value at the given index.

Parameters
idxindices to set value at
valvalue to write into idx

◆ set() [5/5]

template<typename T >
void magmadnn::Tensor< T >::set ( unsigned int  flattened_idx,
val 
)

sets the value at the given index.

Parameters
idxindices to set value at
valvalue to write into idx

◆ squeeze()

template<typename T >
void magmadnn::Tensor< T >::squeeze ( )

removes axes with length 1

Here is the caller graph for this function:

◆ unsqueeze()

template<typename T >
void magmadnn::Tensor< T >::unsqueeze ( unsigned int  dim = 0)

adds a dimension with length 1 along axis dim

Parameters
dim
Here is the caller graph for this function:

The documentation for this class was generated from the following files: