mxnet
choose.h
Go to the documentation of this file.
1 
7 #ifndef MSHADOW_EXTENSION_CHOOSE_H_
8 #define MSHADOW_EXTENSION_CHOOSE_H_
9 
10 #include "../extension.h"
11 
12 namespace mshadow {
13 namespace expr {
20 template<typename SrcExp, typename IndexExp, typename DType>
22  public Exp<MatChooseRowElementExp<SrcExp, IndexExp, DType>,
23  DType, type::kChainer> {
25  const SrcExp &src_;
27  const IndexExp &index_;
29  MatChooseRowElementExp(const SrcExp &src, const IndexExp &index)
30  : src_(src), index_(index) {}
31 };
32 
33 template<typename SrcExp, typename IndexExp,
34  typename DType, typename IDType, int e1, int e2>
37  const Exp<IndexExp, IDType, e2> &index) {
39  ::Error_Expression_Does_Not_Meet_Dimension_Req();
41 }
42 
43 //----------------------
44 // Execution plan
45 //----------------------
46 template<typename SrcExp, typename IndexExp, typename DType>
47 struct Plan<MatChooseRowElementExp<SrcExp, IndexExp, DType>, DType> {
48  public:
50  : src_(MakePlan(e.src_)),
51  index_(MakePlan(e.index_)) {
52  }
53  MSHADOW_XINLINE DType Eval(index_t y, index_t x) const {
54  index_t idx = static_cast<index_t>(index_.Eval(0, x));
55  return src_.Eval(x, idx);
56  }
57 
58  private:
61 };
62 
63 template<typename SrcExp, typename IndexExp, typename DType>
67 }
68 
69 template<int dim, typename SrcExp, typename IndexExp, typename DType>
70 struct ShapeCheck<dim, MatChooseRowElementExp<SrcExp, IndexExp, DType> > {
71  inline static Shape<dim>
73  CHECK(dim == 1)
74  << "MatChooseRowElementExp only support 1 dimension output";
77  CHECK_EQ(shape1[0], shape2[0])
78  << "mat_choose_row_element index length and number of rows in matrix";
79  return shape2;
80  }
81 };
82 
83 template<typename SrcExp, typename IndexExp, typename DType>
84 struct ExpInfo<MatChooseRowElementExp<SrcExp, IndexExp, DType> > {
85  static const int kDim = 1;
87 };
88 } // namespace expr
89 } // namespace mshadow
90 #endif // MSHADOW_EXTENSION_CHOOSE_H_
Make a choice of index in the lowest changing dimension.
Definition: choose.h:21
Definition: expr_engine-inl.h:40
used to help static type check
Definition: expr_engine-inl.h:312
const IndexExp & index_
index operand
Definition: choose.h:27
static Shape< dim > Check(const E &t)
#define MSHADOW_XINLINE
Definition: base.h:204
static type inference template, used to get the dimension of each expression, if ExpInfo<E>::kDim == ...
Definition: expr_engine-inl.h:244
MSHADOW_XINLINE DType Eval(index_t y, index_t x) const
Definition: choose.h:53
const SrcExp & src_
source operand
Definition: choose.h:25
int32_t index_t
type that will be used for index
Definition: base.h:291
static Shape< dim > Check(const MatChooseRowElementExp< SrcExp, IndexExp, DType > &t)
Definition: choose.h:72
MatChooseRowElementExp< SrcExp, IndexExp, DType > mat_choose_row_element(const Exp< SrcExp, DType, e1 > &src, const Exp< IndexExp, IDType, e2 > &index)
Definition: choose.h:36
runtime shape checking template get the shape of an expression, report error if shape mismatch ...
Definition: expr_engine-inl.h:346
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
MatChooseRowElementExp(const SrcExp &src, const IndexExp &index)
constructor
Definition: choose.h:29
namespace for mshadow
Definition: base.h:282
Plan(const MatChooseRowElementExp< SrcExp, IndexExp, DType > &e)
Definition: choose.h:49