mxnet
fill.h
Go to the documentation of this file.
1 
7 #ifndef MSHADOW_EXTENSION_FILL_H_
8 #define MSHADOW_EXTENSION_FILL_H_
9 
10 #include "../extension.h"
11 
12 
13 namespace mshadow {
14 namespace expr {
22 template<typename SrcExp, typename ValExp, typename IndexExp, typename DType>
24  public Exp<MatFillRowElementExp<SrcExp, ValExp, IndexExp, DType>,
25  DType, type::kChainer> {
27  const SrcExp &src_;
28  const ValExp &val_;
30  const IndexExp &index_;
32  MatFillRowElementExp(const SrcExp &src, const ValExp &val, const IndexExp &index)
33  : src_(src), val_(val), index_(index) {}
34 };
35 
36 template<typename SrcExp, typename ValExp, typename IndexExp,
37  typename SDType, typename VDType, typename IDType, int e1, int e2, int e3>
40  const Exp<ValExp, VDType, e2> &val,
41  const Exp<IndexExp, IDType, e3> &index) {
43  && ExpInfo<IndexExp>::kDim == 1>::Error_Expression_Does_Not_Meet_Dimension_Req();
45  val.self(), index.self());
46 }
47 
48 //----------------------
49 // Execution plan
50 //----------------------
51 template<typename SrcExp, typename ValExp, typename IndexExp, typename DType>
52 struct Plan<MatFillRowElementExp<SrcExp, ValExp, IndexExp, DType>, DType> {
53  public:
55  : src_(MakePlan(e.src_)),
56  val_(MakePlan(e.val_)),
57  index_(MakePlan(e.index_)) {
58  }
59  MSHADOW_XINLINE DType Eval(index_t y, index_t x) const {
60  index_t idx = static_cast<index_t>(index_.Eval(0, y));
61  if (idx == x) {
62  return static_cast<DType>(val_.Eval(0, y));
63  } else {
64  return static_cast<DType>(src_.Eval(y, x));
65  }
66  }
67 
68  private:
72 };
73 
74 template<typename SrcExp, typename ValExp, typename IndexExp, typename DType>
78 }
79 
80 template<int dim, typename SrcExp, typename ValExp, typename IndexExp, typename DType>
81 struct ShapeCheck<dim, MatFillRowElementExp<SrcExp, ValExp, IndexExp, DType> > {
82  inline static Shape<dim>
84  CHECK(dim == 2)
85  << "MatFillRowElementExp only support 2 dimension output";
89  CHECK((shape_src[0] == shape_index[0]) && (shape_index[0] == shape_val[0]))
90  << "mat_fill_row_element index length, val length and number of rows in matrix";
91  return shape_src;
92  }
93 };
94 
95 template<typename SrcExp, typename ValExp, typename IndexExp, typename DType>
96 struct ExpInfo<MatFillRowElementExp<SrcExp, ValExp, IndexExp, DType> > {
97  static const int kDim = 2;
98  static const int kDevMask =
100 };
101 } // namespace expr
102 } // namespace mshadow
103 #endif // MSHADOW_EXTENSION_FILL_H_
MatFillRowElementExp(const SrcExp &src, const ValExp &val, const IndexExp &index)
constructor
Definition: fill.h:32
Definition: expr_engine-inl.h:40
used to help static type check
Definition: expr_engine-inl.h:312
const IndexExp & index_
index operand
Definition: fill.h:30
MSHADOW_XINLINE DType Eval(index_t y, index_t x) const
Definition: fill.h:59
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
int32_t index_t
type that will be used for index
Definition: base.h:291
const ValExp & val_
Definition: fill.h:28
Plan(const MatFillRowElementExp< SrcExp, ValExp, IndexExp, DType > &e)
Definition: fill.h:54
runtime shape checking template get the shape of an expression, report error if shape mismatch ...
Definition: expr_engine-inl.h:346
const SrcExp & src_
src operand
Definition: fill.h:27
Set value of a specific element in each line of the data matrix.
Definition: fill.h:23
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
namespace for mshadow
Definition: base.h:282
MatFillRowElementExp< SrcExp, ValExp, IndexExp, SDType > mat_fill_row_element(const Exp< SrcExp, SDType, e1 > &src, const Exp< ValExp, VDType, e2 > &val, const Exp< IndexExp, IDType, e3 > &index)
Definition: fill.h:39
static Shape< dim > Check(const MatFillRowElementExp< SrcExp, ValExp, IndexExp, DType > &t)
Definition: fill.h:83