1 #ifndef MSHADOW_TENSOR_CONTAINER_H
2 #define MSHADOW_TENSOR_CONTAINER_H
20 template<
typename Device,
int dimension>
31 this->
shape.stride_ = 0;
32 this->data_.
shape.stride_ = 0;
33 this->data_.
shape[1] = 0;
42 this->AllocByShape( shape );
52 this->AllocByShape( shape );
65 this->AllocByShape( shape );
71 this->shape.
stride_ = this->shape[ 0 ];
93 template<
typename TStream>
102 template<
typename TStream>
116 inline Tensor<Device,dimension>& operator=(
const expr::Exp<E,expr::type::kMapper> &exp ){
120 inline Tensor<Device,dimension>& operator=(
const expr::Exp<E,expr::type::kComplex> &exp ){
127 Tensor<Device, 2> data_;
129 inline void FreeSpace (
void){
130 if( data_.
dptr != NULL ){
135 inline void AllocByShape (
const Shape<dimension>&
shape){
136 if( data_.
dptr != NULL ){
139 data_.
shape = shape.FlatTo2D();
144 this->shape.stride_ = data_.
shape.stride_;
146 this->shape.stride_ = shape[0];
void Resize(const Shape< dimension > &shape, real_t initv)
resize the container to given shape, and initialize, content is NOT preserved
Definition: tensor_container.h:80
void set_pad(bool pad)
set whether padding is allowed in tensor
Definition: tensor_container.h:85
void Resize(const Shape< dimension > &shape)
resize the container to given shape, content is NOT preserved
Definition: tensor_container.h:62
TensorContainer(bool pad=MSHADOW_ALLOC_PAD)
constructor
Definition: tensor_container.h:27
shape of a tensor IMPORTANT NOTE: this shape is different from numpy.shape shape[0] gives the lowest ...
Definition: tensor.h:23
void FreeSpace(Tensor< cpu, dim > &obj)
CPU/GPU: free the space of tensor, will set obj.dptr to NULL.
Definition: tensor_cpu-inl.hpp:36
MSHADOW_XINLINE Shape< 2 > FlatTo2D(void) const
Definition: tensor.h:68
index_t shape_[kMaxShape]
storing the dimension information
Definition: tensor.h:129
void LoadBinary(TStream &fi)
load by binary format, a temp Tensor<cpu,dim> storage will be allocated
Definition: tensor_container.h:103
float real_t
type that will be used for content
Definition: tensor_base.h:118
header file of tensor data structure and functions covention: this lib requires explicit memory alloc...
void SaveBinary(TStream &fo, const Tensor< cpu, dim > &src)
CPU/GPU: save a tensor by binary format, for GPU version, a temp Tensor<cpu,dim> storage will be allo...
Definition: tensor_io.h:92
tensor container that does memory allocation and resize like STL, use it to save the lines of FreeSpa...
Definition: tensor_container.h:21
TensorContainer(const Shape< dimension > &shape, real_t initv)
constructor
Definition: tensor_container.h:49
Tensor< Device, dimension > & __assign(real_t s)
operator overload
Definition: tensor_expr.h:119
#define MSHADOW_ALLOC_PAD
whether do padding during allocation
Definition: tensor_base.h:23
void SaveBinary(TStream &fo) const
save by binary format
Definition: tensor_container.h:94
real_t * dptr
pointer to the data
Definition: tensor.h:215
void Copy(Tensor< cpu, dim > dst, const Tensor< cpu, dim > &src)
copy data from one tensor to another, with same shape
Definition: tensor_cpu-inl.hpp:42
Shape< dimension > shape
shape of the tensor
Definition: tensor.h:217
void AllocSpace(Tensor< cpu, dim > &obj, bool pad=MSHADOW_ALLOC_PAD)
CPU/CPU: allocate space for CTensor, according to the shape in the obj this function is responsible t...
Definition: tensor_cpu-inl.hpp:14
general tensor
Definition: tensor.h:206
PaddingExp< SrcExp, ExpInfo< SrcExp >::kDim > pad(const Exp< SrcExp, etype > &src, index_t pad)
padding expression, pad a image with zeros on boundaries, padding affects shape[0], and shape[1]
Definition: tensor_expr_ext.h:496
TensorContainer(const Shape< dimension > &shape)
constructor
Definition: tensor_container.h:39
void LoadBinary(TStream &fi, Tensor< cpu, dim > &dst, bool pre_alloc)
CPU/GPU: load a tensor by binary format, for GPU version, a temp Tensor<cpu,dim> storage will be allo...
Definition: tensor_io.h:110
index_t stride_
storing the stride information in x dimension this is used to deal with pitch allocation in gpu or ss...
Definition: tensor.h:134
definitions of I/O functions for mshadow tensor