mxnet
spatial_upsampling_nearest.h
Go to the documentation of this file.
1 
7 #ifndef MSHADOW_EXTENSION_SPATIAL_UPSAMPLING_NEAREST_H_
8 #define MSHADOW_EXTENSION_SPATIAL_UPSAMPLING_NEAREST_H_
9 #include "../extension.h"
10 
11 namespace mshadow {
12 namespace expr {
13 
20 template<typename SrcExp, typename DType, int srcdim>
22  public MakeTensorExp<UpSamplingNearestExp<SrcExp, DType, srcdim>,
23  SrcExp, srcdim, DType> {
25  const SrcExp &src_;
29  UpSamplingNearestExp(const SrcExp &src, index_t scale)
30  : src_(src), scale_(scale) {
32  this->shape_[srcdim - 2] *= scale_;
33  this->shape_[srcdim - 1] *= scale_;
34  }
35 };
36 
37 
38 template<typename SrcExp, typename DType, int etype>
42  ::Error_Expression_Does_Not_Meet_Dimension_Req();
44 }
45 
46 template<typename SrcExp, typename DType, int srcdim>
47 struct Plan<UpSamplingNearestExp<SrcExp, DType, srcdim>, DType> {
48  public:
50  : src_(MakePlan(e.src_)),
51  scale_(e.scale_),
52  new_height_(e.shape_[srcdim - 2]),
53  src_height_(static_cast<index_t>(e.shape_[srcdim - 2] / e.scale_)) {}
54  MSHADOW_XINLINE DType Eval(index_t i, index_t j) const {
55  const index_t x = j;
56  const index_t y = i % new_height_;
57  const index_t c = i / new_height_;
58  const index_t h = static_cast<index_t>(y / scale_);
59  const index_t w = static_cast<index_t>(x / scale_);
60  return src_.Eval(c * src_height_ + h, w);
61  }
62 
63  private:
65  const index_t scale_;
66  const index_t new_height_;
67  const index_t src_height_;
68 };
69 } // namespace expr
70 } // namespace mshadow
71 #endif // MSHADOW_EXTENSION_SPATIAL_UPSAMPLING_NEAREST_H_
Plan(const UpSamplingNearestExp< SrcExp, DType, srcdim > &e)
Definition: spatial_upsampling_nearest.h:49
Definition: expr_engine-inl.h:40
used to help static type check
Definition: expr_engine-inl.h:312
UpSamplingNearestExp< SrcExp, DType, ExpInfo< SrcExp >::kDim > upsampling_nearest(const Exp< SrcExp, DType, etype > &src, index_t scale)
Definition: spatial_upsampling_nearest.h:40
nearest neighboor upsampling out(x, y) = in(int(x / scale_x), int(y / scale_y))
Definition: spatial_upsampling_nearest.h:21
static Shape< dim > Check(const E &t)
MSHADOW_XINLINE DType Eval(index_t i, index_t j) const
Definition: spatial_upsampling_nearest.h:54
#define MSHADOW_XINLINE
Definition: base.h:204
index_t scale_
up sampling scale
Definition: spatial_upsampling_nearest.h:27
int32_t index_t
type that will be used for index
Definition: base.h:291
const SrcExp & src_
source oprand
Definition: spatial_upsampling_nearest.h:25
defines how expression exp can be evaluated and stored into dst
Definition: expression.h:61
const SubType & self(void) const
Definition: expression.h:64
Plan< BinaryMapExp< OP, TA, TB, DType, etype >, DType > MakePlan(const BinaryMapExp< OP, TA, TB, DType, etype > &e)
Definition: expr_engine-inl.h:221
a general class that allows extension that makes tensors of some shape
Definition: expr_engine-inl.h:25
UpSamplingNearestExp(const SrcExp &src, index_t scale)
constructor
Definition: spatial_upsampling_nearest.h:29
namespace for mshadow
Definition: base.h:282
Shape< dim > shape_
the shape of this expression
Definition: expr_engine-inl.h:29