7 #ifndef MSHADOW_EXTENSION_TAKE_GRAD_H_ 8 #define MSHADOW_EXTENSION_TAKE_GRAD_H_ 10 #include "../extension.h" 21 template<
typename IndexExp,
typename SrcExp,
typename DType>
23 DType, type::kChainer> {
32 : index_(index), src_(src), input_dim_(input_dim) {}
36 template<
typename IndexExp,
53 template<
typename IndexExp,
typename SrcExp,
typename DType>
65 for (
index_t i = 0; i < batch_size_; ++i) {
68 ret +=
static_cast<DType
>(
src_.Eval(i, x));
81 template<
typename IndexExp,
typename SrcExp,
typename DType>
87 template<
int dim,
typename IndexExp,
typename SrcExp,
typename DType>
92 <<
"TakeGradExp only support 2D output";
102 template<
typename IndexExp,
typename SrcExp,
typename DType>
104 static const int kDim = 2;
111 #endif // MSHADOW_EXTENSION_TAKE_GRAD_H_ const IndexExp & index_
index oprand
Definition: take_grad.h:25
Definition: expr_engine-inl.h:40
const SrcExp & src_
out gradient oprand
Definition: take_grad.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
static Shape< dim > Check(const TakeGradExp< IndexExp, SrcExp, DType > &t)
Definition: take_grad.h:90
int32_t index_t
type that will be used for index
Definition: base.h:291
TakeGradExp< IndexExp, SrcExp, DType > take_grad(const Exp< IndexExp, DType, e1 > &index, const Exp< SrcExp, DType, e2 > &src, const index_t input_dim)
Definition: take_grad.h:41
runtime shape checking template get the shape of an expression, report error if shape mismatch ...
Definition: expr_engine-inl.h:346
Calculate embedding gradient.
Definition: take_grad.h:22
const index_t input_dim_
batch size
Definition: take_grad.h:29
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
TakeGradExp(const IndexExp &index, const SrcExp &src, const index_t input_dim)
constructor
Definition: take_grad.h:31
MSHADOW_XINLINE DType Eval(index_t y, index_t x) const
Definition: take_grad.h:63
namespace for mshadow
Definition: base.h:282
Plan(const TakeGradExp< IndexExp, SrcExp, DType > &e)
Definition: take_grad.h:56