Go to the documentation of this file.
25 #ifndef MSHADOW_EXTENSION_CROP_H_
26 #define MSHADOW_EXTENSION_CROP_H_
27 #include "../extension.h"
36 template<
typename SrcExp,
typename DType,
int srcdim>
39 SrcExp, srcdim, DType> {
52 CHECK_GE(this->
shape_[srcdim - 2], cshape[0]) <<
"CroppingExp: height requirement not met";
53 CHECK_GE(this->
shape_[srcdim - 1], cshape[1]) <<
"CroppingExp: width requirement not met";
57 this->
shape_[srcdim - 2] = cshape[0];
58 this->
shape_[srcdim - 1] = cshape[1];
65 CHECK_GE(this->
shape_[srcdim - 2], cshape[0] + start_height)
66 <<
"CroppingExp: height requirement not met";
67 CHECK_GE(this->
shape_[srcdim - 1], cshape[1] + start_width)
68 <<
"CroppingExp: width requirement not met";
70 this->
shape_[srcdim - 2] = cshape[0];
71 this->
shape_[srcdim - 1] = cshape[1];
84 template<
typename SrcExp,
typename DType,
int etype>
85 inline CroppingExp<SrcExp, DType, ExpInfo<SrcExp>::kDim>
88 ::Error_Expression_Does_Not_Meet_Dimension_Req();
102 template<
typename SrcExp,
typename DType,
int etype>
103 inline CroppingExp<SrcExp, DType, ExpInfo<SrcExp>::kDim>
107 ::Error_Expression_Does_Not_Meet_Dimension_Req();
109 (src.
self(), oshape, start_height, start_width);
114 template<
typename SrcExp,
typename DType,
int srcdim>
119 pad_height_(e.pad_height_), pad_width_(e.pad_width_),
120 new_height_(e.shape_[srcdim - 2]), src_height_(e.src_height_) {}
123 const index_t y = i % new_height_;
124 const index_t c = i / new_height_;
125 const index_t h = y + pad_height_;
126 const index_t w = x + pad_width_;
127 return src_.Eval(c * src_height_ + h, w);
131 const index_t pad_height_, pad_width_;
137 #endif // MSHADOW_EXTENSION_CROP_H_
const SrcExp & src_
source operand
Definition: crop.h:41
const SubType & self(void) const
Definition: expression.h:82
index_t pad_width_
pad height
Definition: crop.h:45
used to help static type check
Definition: expr_engine-inl.h:330
CroppingExp(const SrcExp &src, Shape< 2 > cshape)
constructor
Definition: crop.h:49
index_t pad_height_
pad height
Definition: crop.h:43
MSHADOW_XINLINE DType Eval(index_t i, index_t j) const
Definition: crop.h:121
crop expression, cut off the boundary region, reverse operation of padding
Definition: crop.h:37
#define MSHADOW_XINLINE
Definition: base.h:228
CroppingExp(const SrcExp &src, Shape< 2 > cshape, index_t start_height, index_t start_width)
constructor
Definition: crop.h:61
CroppingExp< SrcExp, DType, ExpInfo< SrcExp >::kDim > crop(const Exp< SrcExp, DType, etype > &src, Shape< 2 > oshape)
revserse operationg of padding, cut off boundaries, crop output from center of input
Definition: crop.h:86
static Shape< dim > Check(const E &t)
index_t src_height_
src height
Definition: crop.h:47
Plan< BinaryMapExp< OP, TA, TB, DType, etype >, DType > MakePlan(const BinaryMapExp< OP, TA, TB, DType, etype > &e)
Definition: expr_engine-inl.h:239
Shape< dim > shape_
the shape of this expression
Definition: expr_engine-inl.h:47
Plan(const CroppingExp< SrcExp, DType, srcdim > &e)
Definition: crop.h:117
int32_t index_t
type that will be used for index
Definition: base.h:328
Definition: expr_engine-inl.h:58
defines how expression exp can be evaluated and stored into dst
Definition: expression.h:79
overloaded + operator between half_t and bf16_t
Definition: base.h:319
a general class that allows extension that makes tensors of some shape
Definition: expr_engine-inl.h:43