26 #ifndef MSHADOW_TENSOR_CONTAINER_H_ 27 #define MSHADOW_TENSOR_CONTAINER_H_ 40 template<
typename Device,
int dimension,
typename DType = default_real_t>
62 this->AllocByShape(shape);
72 this->AllocByShape(shape);
88 if (src.
dptr_ != NULL) {
89 this->AllocByShape(src.
shape_);
103 this->AllocByShape(shape);
131 template<
typename TStream>
140 template<
typename TStream>
146 Copy(*
this, tmp, &stream);
156 this->pad_ = src.pad_;
158 if (src.
dptr_ != NULL) {
192 if (data_.
dptr_ != NULL) {
196 this->data_.
shape_[0] = 0;
199 }
catch (
const dmlc::Error &e) {
227 #endif // MSHADOW_TENSOR_CONTAINER_H_ 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:141
void Resize(const Shape< dimension > &shape, DType initv)
resize the container to given shape, and initialize, content is NOT preserved
Definition: tensor_container.h:118
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], and shape[1]
Definition: pad.h:72
Tensor< Device, dimension, DType > & operator=(const expr::Exp< E, DType, expr::type::kComplex > &exp)
functions to fit expression template
Definition: tensor_container.h:183
DType * dptr_
pointer to the data
Definition: tensor.h:435
TensorContainer(const Shape< dimension > &shape, DType initv)
constructor
Definition: tensor_container.h:69
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:126
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:146
shape of a tensor
Definition: tensor.h:54
void set_pad(bool pad)
set whether padding is allowed in tensor
Definition: tensor_container.h:123
Shape< dimension > shape_
shape of the tensor
Definition: tensor.h:437
TensorContainer(bool pad=MSHADOW_ALLOC_PAD)
constructor
Definition: tensor_container.h:47
Tensor< Device, dimension, DType > & operator=(const expr::Exp< E, DType, expr::type::kChainer > &exp)
functions to fit expression template
Definition: tensor_container.h:177
void Release(void)
Release the llocated space, The TensorContainer is still functionable, but will restart allocating sp...
Definition: tensor_container.h:191
MSHADOW_XINLINE Shape< 2 > FlatTo2D(void) const
Definition: tensor.h:133
header file of tensor data structure and functions This lib requires explicit memory allocation and d...
#define MSHADOW_ALLOC_PAD
whether do padding during allocation
Definition: base.h:73
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:117
TensorContainer(const Shape< dimension > &shape)
constructor
Definition: tensor_container.h:59
Tensor< Device, dimension, DType > & operator=(DType s)
functions to fit expression template
Definition: tensor_container.h:165
tensor container that does memory allocation and resize like STL, use it to save the lines of FreeSpa...
Definition: tensor_container.h:41
void SaveBinary(TStream &fo) const
save by binary format
Definition: tensor_container.h:132
index_t shape_[kDimension]
storing the dimension information
Definition: tensor.h:76
~TensorContainer(void) MSHADOW_THROW_EXCEPTION
Definition: tensor_container.h:93
void LoadBinary(TStream &fi)
load by binary format, a temp Tensor<cpu,dim> storage will be allocated
Definition: tensor_container.h:141
defines how expression exp can be evaluated and stored into dst
Definition: expression.h:80
overloaded + operator between half_t and bf16_t
Definition: base.h:327
#define MSHADOW_THROW_EXCEPTION
Definition: base.h:253
MSHADOW_XINLINE index_t size(int idx) const
return size of i-th dimension, start counting from highest dimension
Definition: tensor.h:506
Tensor< Device, dimension, DType > & operator=(const expr::Exp< E, DType, expr::type::kMapper > &exp)
functions to fit expression template
Definition: tensor_container.h:171
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:108
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:442
Tensor< Device, dimension, DType > & __assign(DType s)
operator overload
Definition: expression.h:179
general tensor
Definition: tensor.h:421
void Resize(const Shape< dimension > &shape)
resize the container to given shape, content is NOT preserved
Definition: tensor_container.h:100
Stream< Device > * stream_
stream where the computation lies stream is a device dependency concept where each computation ...
Definition: tensor.h:447
computaion stream structure, used for asynchronous computations
Definition: tensor.h:384