Go to the documentation of this file.
25 #ifndef MSHADOW_EXTENSION_SPATIAL_POOL_H_
26 #define MSHADOW_EXTENSION_SPATIAL_POOL_H_
28 #include "../extension.h"
38 template<
typename Reducer,
typename SrcExp,
typename DType,
int srcdim>
40 public MakeTensorExp<PoolingExp<Reducer, SrcExp, DType, srcdim>,
41 SrcExp, srcdim, DType> {
62 CHECK(sshape[srcdim - 1] >= ksize_x && sshape[srcdim - 2] >= ksize_y)
63 <<
"PoolingExp: kernel must be smaller than image";
64 this->src_height_ = sshape[srcdim - 2];
65 this->src_width_ = sshape[srcdim - 1];
76 CHECK(sshape[srcdim - 1] >= ksize_x && sshape[srcdim - 2] >= ksize_y)
77 <<
"PoolingExp: kernel must be smaller than image";
78 this->src_height_ = sshape[srcdim - 2];
79 this->src_width_ = sshape[srcdim - 1];
81 this->
shape_[srcdim - 2] = pshape[0];
82 this->
shape_[srcdim - 1] = pshape[1];
98 template<
typename Reducer,
typename SrcExp,
typename DType,
int etype>
99 inline PoolingExp<Reducer, SrcExp, DType, ExpInfo<SrcExp>::kDim>
103 ::Error_Expression_Does_Not_Meet_Dimension_Req();
105 (src.
self(), ksize_y, ksize_x, kstride_y, kstride_x);
121 template<
typename Reducer,
typename SrcExp,
122 typename DType,
int etype>
123 inline PoolingExp<Reducer, SrcExp, DType, ExpInfo<SrcExp>::kDim>
127 ::Error_Expression_Does_Not_Meet_Dimension_Req();
129 (src.
self(), pshape, ksize_y, ksize_x, kstride_y, kstride_x);
134 template<
typename Reducer,
typename SrcExp,
typename DType,
int srcdim>
139 ksize_y_(e.ksize_y_), ksize_x_(e.ksize_x_),
140 kstride_y_(e.kstride_y_), kstride_x_(e.kstride_x_),
141 src_height_(e.src_height_), src_width_(e.src_width_),
142 new_height_(e.shape_[srcdim - 2]) {}
145 const index_t py = i % new_height_;
146 const index_t y_start = py * kstride_y_;
147 const index_t y_end = min(y_start + ksize_y_, src_height_);
149 const index_t x_start = px * kstride_x_;
150 const index_t x_end = min(x_start + ksize_x_, src_width_);
151 const index_t c = i / new_height_;
153 DType res; Reducer::SetInitValue(res);
154 for (
index_t y = y_start; y < y_end; ++y) {
155 for (
index_t x = x_start; x < x_end; ++x) {
156 Reducer::Reduce(res, src_.Eval(c * src_height_ + y, x));
164 const index_t ksize_y_, ksize_x_, kstride_y_, kstride_x_;
165 const index_t src_height_, src_width_;
170 #endif // MSHADOW_EXTENSION_SPATIAL_POOL_H_
pooling expression, do reduction over local patches of a image
Definition: spatial_pool.h:39
const SubType & self(void) const
Definition: expression.h:82
index_t kstride_y_
kernel stride in y directory
Definition: spatial_pool.h:49
used to help static type check
Definition: expr_engine-inl.h:330
#define MSHADOW_XINLINE
Definition: base.h:228
index_t ksize_y_
kernel size in height
Definition: spatial_pool.h:45
static Shape< dim > Check(const E &t)
PoolingExp(const SrcExp &src, index_t ksize_y, index_t ksize_x, index_t kstride_y, index_t kstride_x)
constructor
Definition: spatial_pool.h:57
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
index_t src_height_
source height shape[1]
Definition: spatial_pool.h:53
int32_t index_t
type that will be used for index
Definition: base.h:328
Definition: expr_engine-inl.h:58
const SrcExp & src_
source operand
Definition: spatial_pool.h:43
defines how expression exp can be evaluated and stored into dst
Definition: expression.h:79
index_t src_width_
source width shape[0]
Definition: spatial_pool.h:55
PoolingExp< Reducer, SrcExp, DType, ExpInfo< SrcExp >::kDim > pool(const Exp< SrcExp, DType, etype > &src, index_t ksize_y, index_t ksize_x, index_t kstride_y, index_t kstride_x)
pooling subregion results together
Definition: spatial_pool.h:100
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
Definition: optional.h:251
index_t kstride_x_
kernel stride in x directory
Definition: spatial_pool.h:51
Plan(const PoolingExp< Reducer, SrcExp, DType, srcdim > &e)
Definition: spatial_pool.h:137
index_t ksize_x_
kernel size in width
Definition: spatial_pool.h:47
MSHADOW_XINLINE DType Eval(index_t i, index_t j) const
Definition: spatial_pool.h:143
PoolingExp(const SrcExp &src, Shape< 2 > pshape, index_t ksize_y, index_t ksize_x, index_t kstride_y, index_t kstride_x)
constructor, specify shape
Definition: spatial_pool.h:71