mxnet
Public Member Functions | Public Attributes | Friends | List of all members
mxnet::TBlob Class Reference

tensor blob class that can be used to hold tensor of any dimension, any device and any data type, This is a weak type that can be used to transfer data through interface TBlob itself do not involve any arithmentic operations, but it can be converted to tensor of fixed dimension for further operations More...

#include <tensor_blob.h>

Collaboration diagram for mxnet::TBlob:
Collaboration graph

Public Member Functions

 TBlob (void)
 default constructor, default copy assign will work More...
 
template<typename DType >
 TBlob (DType *dptr, const mxnet::TShape &shape, int dev_mask, int dev_id=-1)
 constructor that construct TBlob from contiguous memory More...
 
 TBlob (void *dptr, const mxnet::TShape &shape, int dev_mask, int type_flag, int dev_id=-1)
 constructor that construct TBlob from contiguous memory More...
 
 TBlob (const DLTensor &dltensor)
 constructor that construct TBlob from DLTensor More...
 
template<typename Device , int dim, typename DType >
 TBlob (const mshadow::Tensor< Device, dim, DType > &src)
 constructor from tensor More...
 
template<typename Device , int dim, typename DType >
TBloboperator= (const mshadow::Tensor< Device, dim, DType > &src)
 assignment from tensor More...
 
bool CheckContiguous (void) const
 
TBlob reshape (const mxnet::TShape &shape) const
 reshape to shape More...
 
template<typename Device , typename DType >
mshadow::Tensor< Device, 2, DType > FlatTo2D (mshadow::Stream< Device > *stream=NULL) const
 flatten the tensor to 2 dimension, collapse the higher dimensions together More...
 
template<typename Device , typename DType >
mshadow::Tensor< Device, 1, DType > FlatTo1D (mshadow::Stream< Device > *stream=NULL) const
 flatten the tensor to 1 dimension, collapse all the dimensions together. More...
 
int ndim (void) const
 return number of dimension of the tensor inside More...
 
index_t size (index_t idx) const
 return size of i-th dimension, start counting from highest dimension. return type needs to be a signed integer. More...
 
size_t Size (void) const
 total number of elements in the tensor More...
 
template<typename DType >
DType * dptr () const
 get pointer in dtype More...
 
int dev_mask () const
 device mask of the corresponding device More...
 
int dev_id () const
 device index of the corresponding device More...
 
const DLTensor & dltensor () const
 return the corresponding DLTensor More...
 
template<typename Device , int dim, typename DType >
mshadow::Tensor< Device, dim, DType > get (mshadow::Stream< Device > *stream=NULL) const
 fetch the tensor, with respect to specific dimension if dim do not match the stored dimension, an error will be issued More...
 
template<typename Device , int dim, typename DType >
mshadow::Tensor< Device, dim, DType > get_with_shape (const mshadow::Shape< dim > &shape, mshadow::Stream< Device > *stream=NULL) const
 fetch a tensor in given shape If size do not match the stored size, an error will be issued More...
 
template<typename Device , typename DType >
mshadow::Tensor< Device, 3, DType > FlatTo3D (int axis, mshadow::Stream< Device > *stream=NULL) const
 flatten the tensor to 3 dimension, collapse the dimension before and after specified axis. More...
 
template<typename Device , typename DType >
mshadow::Tensor< Device, 3, DType > FlatTo3D (int axis_begin, int axis_end, mshadow::Stream< Device > *stream=NULL) const
 flatten the tensor to 3 dimension, collapse the dimension: [0, axis_begin), [axis_begin, axis_end], (axis_end, ndim). More...
 
template<typename Device , int dim, typename DType >
mshadow::Tensor< Device, dim, DType > FlatToKD (mshadow::Stream< Device > *stream=NULL) const
 flatten the tensor to specified number of dimensions, collapse the highest dimensions or pad with higher dimensions More...
 

Public Attributes

void * dptr_
 pointer to the data More...
 
mxnet::TShape shape_
 shape of the tensor More...
 
int type_flag_
 type flag of the tensor blob More...
 

Friends

class NDArray
 

Detailed Description

tensor blob class that can be used to hold tensor of any dimension, any device and any data type, This is a weak type that can be used to transfer data through interface TBlob itself do not involve any arithmentic operations, but it can be converted to tensor of fixed dimension for further operations

Like tensor, this data structure is like a pointer class and do not implicit allocated, de-allocate space. This data structure can be helpful to hold tensors of different dimensions and wait for further processing

Constructor & Destructor Documentation

mxnet::TBlob::TBlob ( void  )
inline

default constructor, default copy assign will work

template<typename DType >
mxnet::TBlob::TBlob ( DType *  dptr,
const mxnet::TShape shape,
int  dev_mask,
int  dev_id = -1 
)
inline

constructor that construct TBlob from contiguous memory

Parameters
dptrthe pointer to the memory
shapethe shape of the data
dev_maskthe device mask, can be cpu::kDevMask or gpu::kDevMask
dev_idthe device id
mxnet::TBlob::TBlob ( void *  dptr,
const mxnet::TShape shape,
int  dev_mask,
int  type_flag,
int  dev_id = -1 
)
inline

constructor that construct TBlob from contiguous memory

Parameters
dptrthe pointer to the memory
shapethe shape of the data
dev_maskthe device mask, can be cpu::kDevMask or gpu::kDevMask
type_flagthe type flag. Can be one of enum mshadow::dtype
dev_idthe device id
mxnet::TBlob::TBlob ( const DLTensor &  dltensor)
inlineexplicit

constructor that construct TBlob from DLTensor

Parameters
DLTensorObject
template<typename Device , int dim, typename DType >
mxnet::TBlob::TBlob ( const mshadow::Tensor< Device, dim, DType > &  src)
inline

constructor from tensor

Parameters
srcsource tensor
Template Parameters
Devicewhich device the tensor is on
dimtensor dimension
DTypethe type of elements in the tensor

Member Function Documentation

bool mxnet::TBlob::CheckContiguous ( void  ) const
inline
Returns
whether the tensor's memory is continuous
int mxnet::TBlob::dev_id ( ) const
inline

device index of the corresponding device

int mxnet::TBlob::dev_mask ( ) const
inline

device mask of the corresponding device

const DLTensor& mxnet::TBlob::dltensor ( ) const
inline

return the corresponding DLTensor

Returns
the address of internal DLTensor
template<typename DType >
DType* mxnet::TBlob::dptr ( ) const
inline

get pointer in dtype

template<typename Device , typename DType >
mshadow::Tensor<Device, 1, DType> mxnet::TBlob::FlatTo1D ( mshadow::Stream< Device > *  stream = NULL) const
inline

flatten the tensor to 1 dimension, collapse all the dimensions together.

Parameters
streamthe possible stream target tensor should reside on
Template Parameters
Devicewhich device the tensor is on
DTypethe type of elements in the tensor
Returns
tensor after flatten
template<typename Device , typename DType >
mshadow::Tensor<Device, 2, DType> mxnet::TBlob::FlatTo2D ( mshadow::Stream< Device > *  stream = NULL) const
inline

flatten the tensor to 2 dimension, collapse the higher dimensions together

Parameters
streamthe possible stream target tensor should reside on
Template Parameters
Devicewhich device the tensor is on
DTypethe type of elements in the tensor
Returns
tensor after flatten
template<typename Device , typename DType >
mshadow::Tensor<Device, 3, DType> mxnet::TBlob::FlatTo3D ( int  axis,
mshadow::Stream< Device > *  stream = NULL 
) const
inline

flatten the tensor to 3 dimension, collapse the dimension before and after specified axis.

Parameters
axisThe axis specified.
streamthe possible stream target tensor should reside on
Template Parameters
Devicewhich device the tensor is on
DTypethe type of elements in the tensor
Returns
tensor after flatten
template<typename Device , typename DType >
mshadow::Tensor<Device, 3, DType> mxnet::TBlob::FlatTo3D ( int  axis_begin,
int  axis_end,
mshadow::Stream< Device > *  stream = NULL 
) const
inline

flatten the tensor to 3 dimension, collapse the dimension: [0, axis_begin), [axis_begin, axis_end], (axis_end, ndim).

Parameters
axis_beginThe beginning axis specified.
axis_endThe ending axis specified.
streamthe possible stream target tensor should reside on
Template Parameters
Devicewhich device the tensor is on
DTypethe type of elements in the tensor
Returns
tensor after flatten
template<typename Device , int dim, typename DType >
mshadow::Tensor<Device, dim, DType> mxnet::TBlob::FlatToKD ( mshadow::Stream< Device > *  stream = NULL) const
inline

flatten the tensor to specified number of dimensions, collapse the highest dimensions or pad with higher dimensions

Parameters
streamthe possible stream target tensor should reside on
Template Parameters
Devicewhich device the tensor is on
dimdesired number of dimensions of returned tensor
DTypethe type of elements in the tensor
Returns
tensor after flatten
template<typename Device , int dim, typename DType >
mshadow::Tensor<Device, dim, DType> mxnet::TBlob::get ( mshadow::Stream< Device > *  stream = NULL) const
inline

fetch the tensor, with respect to specific dimension if dim do not match the stored dimension, an error will be issued

Returns
the tensor requested
Parameters
streamthe possible stream target tensor should reside on
Template Parameters
Devicewhich device the tensor is on
dimdimension of the tensor
DTypethe type of elements in the tensor
template<typename Device , int dim, typename DType >
mshadow::Tensor<Device, dim, DType> mxnet::TBlob::get_with_shape ( const mshadow::Shape< dim > &  shape,
mshadow::Stream< Device > *  stream = NULL 
) const
inline

fetch a tensor in given shape If size do not match the stored size, an error will be issued

Returns
the tensor requested
Parameters
shapethe shape required
streamthe possible stream target tensor should reside on
Template Parameters
Devicewhich device the tensor is on
dimdimension of the tensor
DTypethe type of elements in the tensor
int mxnet::TBlob::ndim ( void  ) const
inline

return number of dimension of the tensor inside

template<typename Device , int dim, typename DType >
TBlob& mxnet::TBlob::operator= ( const mshadow::Tensor< Device, dim, DType > &  src)
inline

assignment from tensor

Parameters
srcsource tensor
Template Parameters
Devicewhich device the tensor is on
dimtensor dimension
DTypethe type of elements in the tensor
Returns
reference of self
TBlob mxnet::TBlob::reshape ( const mxnet::TShape shape) const
inline

reshape to shape

Parameters
shapedesired shape
Returns
reshaped blob
index_t mxnet::TBlob::size ( index_t  idx) const
inline

return size of i-th dimension, start counting from highest dimension. return type needs to be a signed integer.

Parameters
idxthe dimension count from the highest dimensin
Returns
the size. -1 means unknown size to support zero-size tensor.
size_t mxnet::TBlob::Size ( void  ) const
inline

total number of elements in the tensor

Friends And Related Function Documentation

friend class NDArray
friend

Member Data Documentation

void* mxnet::TBlob::dptr_

pointer to the data

mxnet::TShape mxnet::TBlob::shape_

shape of the tensor

int mxnet::TBlob::type_flag_

type flag of the tensor blob


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