mxnet
Public Member Functions | List of all members
mshadow::TensorContainer< Device, dimension, DType > Class Template Reference

tensor container that does memory allocation and resize like STL, use it to save the lines of FreeSpace in class. Do not abuse it, efficiency can come from pre-allocation and no re-allocation More...

#include <tensor_container.h>

Inheritance diagram for mshadow::TensorContainer< Device, dimension, DType >:
Inheritance graph
Collaboration diagram for mshadow::TensorContainer< Device, dimension, DType >:
Collaboration graph

Public Member Functions

 TensorContainer (bool pad=MSHADOW_ALLOC_PAD)
 constructor More...
 
 TensorContainer (const Shape< dimension > &shape)
 constructor More...
 
 TensorContainer (const Shape< dimension > &shape, DType initv)
 constructor More...
 
 TensorContainer (const TensorContainer< Device, dimension, DType > &src)
 copy constructor More...
 
 ~TensorContainer (void) MSHADOW_THROW_EXCEPTION
 
void Resize (const Shape< dimension > &shape)
 resize the container to given shape, content is NOT preserved More...
 
void Resize (const Shape< dimension > &shape, DType initv)
 resize the container to given shape, and initialize, content is NOT preserved More...
 
void set_pad (bool pad)
 set whether padding is allowed in tensor More...
 
template<typename TStream >
void SaveBinary (TStream &fo) const
 save by binary format More...
 
template<typename TStream >
void LoadBinary (TStream &fi)
 load by binary format, a temp Tensor<cpu,dim> storage will be allocated More...
 
TensorContaineroperator= (const TensorContainer< Device, dimension, DType > &src)
 assign operator from TensorContainer More...
 
Tensor< Device, dimension, DType > & operator= (DType s)
 functions to fit expression template More...
 
template<typename E >
Tensor< Device, dimension, DType > & operator= (const expr::Exp< E, DType, expr::type::kMapper > &exp)
 functions to fit expression template More...
 
template<typename E >
Tensor< Device, dimension, DType > & operator= (const expr::Exp< E, DType, expr::type::kChainer > &exp)
 functions to fit expression template More...
 
template<typename E >
Tensor< Device, dimension, DType > & operator= (const expr::Exp< E, DType, expr::type::kComplex > &exp)
 functions to fit expression template More...
 
void Release (void)
 Release the llocated space, The TensorContainer is still functionable, but will restart allocating space when Resize is called. More...
 
- Public Member Functions inherited from mshadow::Tensor< Device, dimension, DType >
MSHADOW_XINLINE Tensor (void)
 default constructor More...
 
MSHADOW_XINLINE Tensor (const Shape< dimension > &shape)
 constructor from shape More...
 
MSHADOW_XINLINE Tensor (DType *dptr, const Shape< dimension > &shape)
 constructor from data pointer and shape, without stride More...
 
MSHADOW_XINLINE Tensor (DType *dptr, const Shape< dimension > &shape, Stream< Device > *stream)
 constructor from data pointer and shape, without stride More...
 
MSHADOW_XINLINE Tensor (DType *dptr, const Shape< dimension > &shape, index_t stride, Stream< Device > *stream)
 constructor from data pointer and shape More...
 
void set_stream (Stream< Device > *stream)
 set the stream to do computation of current tensor More...
 
MSHADOW_XINLINE index_t MemSize (void) const
 
MSHADOW_XINLINE bool CheckContiguous (void) const
 
MSHADOW_XINLINE index_t MSize (void) const
 
MSHADOW_XINLINE index_t size (int idx) const
 return size of i-th dimension, start counting from highest dimension More...
 
MSHADOW_XINLINE Tensor< Device, 1, DType > FlatTo1D (void) const
 flatten the tensor to 1 dimension More...
 
MSHADOW_XINLINE Tensor< Device, 2, DType > FlatTo2D (void) const
 flatten the tensor to 2 dimension, collapse the higher dimensions together More...
 
MSHADOW_XINLINE Tensor< Device, kSubdim, DType > operator[] (index_t idx) const
 get a element of dimension - 1 More...
 
MSHADOW_XINLINE Tensor< Device, dimension, DType > Slice (index_t begin, index_t end) const
 slice the tensor in highest dimension [begin,end) More...
 
Tensor< Device, dimension, DType > & operator= (const Tensor< Device, dimension, DType > &exp)
 implement the assignment of same type More...
 
Tensor< Device, dimension, DType > & operator= (const expr::Exp< E, DType, etype > &exp)
 functions to fit expression template More...
 
Tensor< Device, dimension, DType > & operator= (const DType &exp)
 functions to fit expression template More...
 
- Public Member Functions inherited from mshadow::expr::RValueExp< Tensor< Device, dimension, DType >, DType >
const TransposeExp< Tensor< Device, dimension, DType >, DType > T (void) const
 transpose of a matrix More...
 
Tensor< Device, dimension, DType > & operator+= (DType s)
 operator overload More...
 
Tensor< Device, dimension, DType > & operator+= (const Exp< E, DType, etype > &exp)
 implementation of operator+= More...
 
Tensor< Device, dimension, DType > & operator-= (DType s)
 operator overload More...
 
Tensor< Device, dimension, DType > & operator-= (const Exp< E, DType, etype > &exp)
 implementation of operator-= More...
 
Tensor< Device, dimension, DType > & operator*= (DType s)
 operator overload More...
 
Tensor< Device, dimension, DType > & operator*= (const Exp< E, DType, etype > &exp)
 implementation of operator*= More...
 
Tensor< Device, dimension, DType > & operator/= (DType s)
 operator overload More...
 
Tensor< Device, dimension, DType > & operator/= (const Exp< E, DType, etype > &exp)
 implementation of operator/= More...
 
Tensor< Device, dimension, DType > & __assign (DType s)
 operator overload More...
 
Tensor< Device, dimension, DType > & __assign (const Exp< E, DType, etype > &exp)
 we can not define container = container More...
 
Tensor< Device, dimension, DType > & __assign (const Exp< Tensor< Device, dimension, DType >, DType, type::kRValue > &exp)
 operator overload, assign More...
 
- Public Member Functions inherited from mshadow::expr::Exp< Tensor< Device, dimension, DType >, DType, type::kRValue >
const Tensor< Device, dimension, DType > & self (void) const
 
Tensor< Device, dimension, DType > * ptrself (void)
 

Additional Inherited Members

- Public Attributes inherited from mshadow::Tensor< Device, dimension, DType >
DType * dptr_
 pointer to the data More...
 
Shape< dimension > shape_
 shape of the tensor More...
 
index_t stride_
 storing the stride information in x dimension this is used to deal with pitch allocation in gpu or sse(align x dimension to 64bit) for efficiency More...
 
Stream< Device > * stream_
 stream where the computation lies stream is a device dependency concept where each computation More...
 
- Static Public Attributes inherited from mshadow::Tensor< Device, dimension, DType >
static const bool kDevCPU
 whether current type lies in cpu More...
 
static const int kSubdim
 dimension of subtype More...
 

Detailed Description

template<typename Device, int dimension, typename DType = default_real_t>
class mshadow::TensorContainer< Device, dimension, DType >

tensor container that does memory allocation and resize like STL, use it to save the lines of FreeSpace in class. Do not abuse it, efficiency can come from pre-allocation and no re-allocation

Template Parameters
Devicewhich device the tensor is on
dimensiondimension of the tensor

Constructor & Destructor Documentation

template<typename Device, int dimension, typename DType = default_real_t>
mshadow::TensorContainer< Device, dimension, DType >::TensorContainer ( bool  pad = MSHADOW_ALLOC_PAD)
inlineexplicit

constructor

Parameters
padwhether use padding alignment in space allocation
template<typename Device, int dimension, typename DType = default_real_t>
mshadow::TensorContainer< Device, dimension, DType >::TensorContainer ( const Shape< dimension > &  shape)
inlineexplicit

constructor

Parameters
shapeintial shape
template<typename Device, int dimension, typename DType = default_real_t>
mshadow::TensorContainer< Device, dimension, DType >::TensorContainer ( const Shape< dimension > &  shape,
DType  initv 
)
inlineexplicit

constructor

Parameters
shapeintial shape
initvintial value
template<typename Device, int dimension, typename DType = default_real_t>
mshadow::TensorContainer< Device, dimension, DType >::TensorContainer ( const TensorContainer< Device, dimension, DType > &  src)
inline

copy constructor

Parameters
srcsource value
template<typename Device, int dimension, typename DType = default_real_t>
mshadow::TensorContainer< Device, dimension, DType >::~TensorContainer ( void  )
inline

Member Function Documentation

template<typename Device, int dimension, typename DType = default_real_t>
template<typename TStream >
void mshadow::TensorContainer< Device, dimension, DType >::LoadBinary ( TStream &  fi)
inline

load by binary format, a temp Tensor<cpu,dim> storage will be allocated

Parameters
fiinput binary stream
Template Parameters
TStreamtype of stream, need to support Read, Write, one example is utils::IStream.
template<typename Device, int dimension, typename DType = default_real_t>
TensorContainer& mshadow::TensorContainer< Device, dimension, DType >::operator= ( const TensorContainer< Device, dimension, DType > &  src)
inline

assign operator from TensorContainer

Parameters
srcsource value
Returns
reference of self
template<typename Device, int dimension, typename DType = default_real_t>
Tensor<Device, dimension, DType>& mshadow::TensorContainer< Device, dimension, DType >::operator= ( DType  s)
inline

functions to fit expression template

template<typename Device, int dimension, typename DType = default_real_t>
template<typename E >
Tensor<Device, dimension, DType>& mshadow::TensorContainer< Device, dimension, DType >::operator= ( const expr::Exp< E, DType, expr::type::kMapper > &  exp)
inline

functions to fit expression template

template<typename Device, int dimension, typename DType = default_real_t>
template<typename E >
Tensor<Device, dimension, DType>& mshadow::TensorContainer< Device, dimension, DType >::operator= ( const expr::Exp< E, DType, expr::type::kChainer > &  exp)
inline

functions to fit expression template

template<typename Device, int dimension, typename DType = default_real_t>
template<typename E >
Tensor<Device, dimension, DType>& mshadow::TensorContainer< Device, dimension, DType >::operator= ( const expr::Exp< E, DType, expr::type::kComplex > &  exp)
inline

functions to fit expression template

template<typename Device, int dimension, typename DType = default_real_t>
void mshadow::TensorContainer< Device, dimension, DType >::Release ( void  )
inline

Release the llocated space, The TensorContainer is still functionable, but will restart allocating space when Resize is called.

template<typename Device, int dimension, typename DType = default_real_t>
void mshadow::TensorContainer< Device, dimension, DType >::Resize ( const Shape< dimension > &  shape)
inline

resize the container to given shape, content is NOT preserved

Parameters
shapetarget shape
template<typename Device, int dimension, typename DType = default_real_t>
void mshadow::TensorContainer< Device, dimension, DType >::Resize ( const Shape< dimension > &  shape,
DType  initv 
)
inline

resize the container to given shape, and initialize, content is NOT preserved

Parameters
shapetarget shape
initvinitialization value
template<typename Device, int dimension, typename DType = default_real_t>
template<typename TStream >
void mshadow::TensorContainer< Device, dimension, DType >::SaveBinary ( TStream &  fo) const
inline

save by binary format

Parameters
fooutput binary stream
Template Parameters
TStreamtype of stream, need to support Read, Write, one example is utils::IStream.
template<typename Device, int dimension, typename DType = default_real_t>
void mshadow::TensorContainer< Device, dimension, DType >::set_pad ( bool  pad)
inline

set whether padding is allowed in tensor


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