Go to the documentation of this file.
25 #ifndef MSHADOW_TENSOR_CONTAINER_H_
26 #define MSHADOW_TENSOR_CONTAINER_H_
39 template<
typename Device,
int dimension,
typename DType = default_real_t>
48 this->
dptr_ = data_.dptr_ = NULL;
51 this->data_.stride_ = 0;
52 this->data_.shape_[0] = 0;
61 this->AllocByShape(shape);
71 this->AllocByShape(shape);
81 this->
dptr_ = data_.dptr_ = NULL;
84 this->data_.stride_ = 0;
85 this->data_.shape_[0] = 0;
87 if (src.
dptr_ != NULL) {
88 this->AllocByShape(src.
shape_);
101 if (s2.
shape_[1] > data_.stride_ || s2.
shape_[0] > data_.size(0)) {
102 this->AllocByShape(shape);
130 template<
typename TStream>
139 template<
typename TStream>
145 Copy(*
this, tmp, &stream);
155 this->pad_ = src.pad_;
157 if (src.
dptr_ != NULL) {
191 if (data_.dptr_ != NULL) {
194 this->data_.stride_ = 0;
195 this->data_.shape_[0] = 0;
198 }
catch (
const dmlc::Error &e) {
199 this->
dptr_ = data_.dptr_ = NULL;
202 this->
dptr_ = data_.dptr_ = NULL;
226 #endif // MSHADOW_TENSOR_CONTAINER_H_
#define MSHADOW_THROW_EXCEPTION
Definition: base.h:250
void LoadBinary(TStream &fi, Tensor< cpu, dim, DType > *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: io.h:125
computaion stream structure, used for asynchronous computations
Definition: tensor.h:488
definitions of I/O functions for mshadow tensor
void Copy(Tensor< cpu, dim, DType > dst, const Tensor< cpu, dim, DType > &src, Stream< cpu > *stream=NULL)
copy data from one tensor to another, with same shape
Definition: tensor_cpu-inl.h:145
void FreeSpace(Tensor< cpu, dim, DType > *obj)
CPU/GPU: free the space of tensor, will set obj.dptr to NULL.
Definition: tensor_cpu-inl.h:140
general tensor
Definition: tensor.h:525
void LoadBinary(TStream &fi)
load by binary format, a temp Tensor<cpu,dim> storage will be allocated
Definition: tensor_container.h:140
~TensorContainer(void) MSHADOW_THROW_EXCEPTION
Definition: tensor_container.h:92
void Resize(const Shape< dimension > &shape, DType initv)
resize the container to given shape, and initialize, content is NOT preserved
Definition: tensor_container.h:117
Tensor< Device, dimension, DType > & operator=(DType s)
functions to fit expression template
Definition: tensor_container.h:164
TensorContainer(const Shape< dimension > &shape)
constructor
Definition: tensor_container.h:58
header file of tensor data structure and functions This lib requires explicit memory allocation and d...
TensorContainer(const Shape< dimension > &shape, DType initv)
constructor
Definition: tensor_container.h:68
Tensor< Device, dimension, DType > & operator=(const expr::Exp< E, DType, expr::type::kMapper > &exp)
functions to fit expression template
Definition: tensor_container.h:170
index_t shape_[kDimension]
storing the dimension information
Definition: tensor.h:86
Stream< Device > * stream_
stream where the computation lies stream is a device dependency concept where each computation
Definition: tensor.h:551
void SaveBinary(TStream &fo) const
save by binary format
Definition: tensor_container.h:131
MSHADOW_XINLINE Shape< 2 > FlatTo2D(void) const
Definition: tensor.h:146
void Release(void)
Release the llocated space, The TensorContainer is still functionable, but will restart allocating sp...
Definition: tensor_container.h:190
Tensor< Device, dimension, DType > & operator=(const expr::Exp< E, DType, expr::type::kChainer > &exp)
functions to fit expression template
Definition: tensor_container.h:176
Shape< dimension > shape_
shape of the tensor
Definition: tensor.h:541
void Resize(const Shape< dimension > &shape)
resize the container to given shape, content is NOT preserved
Definition: tensor_container.h:99
#define MSHADOW_ALLOC_PAD
whether do padding during allocation
Definition: base.h:73
TensorContainer(bool pad=MSHADOW_ALLOC_PAD)
constructor
Definition: tensor_container.h:46
defines how expression exp can be evaluated and stored into dst
Definition: expression.h:79
PaddingExp< SrcExp, DType, ExpInfo< SrcExp >::kDim > pad(const Exp< SrcExp, DType, etype > &src, index_t pad)
padding expression, pad a image with zeros on boundaries, padding affects shape[0],...
Definition: pad.h:71
void AllocSpace(Tensor< cpu, dim, DType > *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.h:116
overloaded + operator between half_t and bf16_t
Definition: base.h:319
Tensor< Device, dimension, DType > & operator=(const expr::Exp< E, DType, expr::type::kComplex > &exp)
functions to fit expression template
Definition: tensor_container.h:182
tensor container that does memory allocation and resize like STL, use it to save the lines of FreeSpa...
Definition: tensor_container.h:40
shape of a tensor
Definition: tensor.h:64
DType * dptr_
pointer to the data
Definition: tensor.h:539
void SaveBinary(TStream &fo, const Tensor< cpu, dim, DType > &src)
CPU/GPU: save a tensor by binary format, for GPU version, a temp Tensor<cpu,dim> storage will be allo...
Definition: io.h:107
MSHADOW_XINLINE index_t size(int idx) const
return size of i-th dimension, start counting from highest dimension
Definition: tensor.h:610
Tensor< Device, dimension, DType > & __assign(DType s)
operator overload
Definition: expression.h:178
void set_pad(bool pad)
set whether padding is allowed in tensor
Definition: tensor_container.h:122
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:546