26 #ifndef MSHADOW_EXTENSION_TAKE_GRAD_H_ 27 #define MSHADOW_EXTENSION_TAKE_GRAD_H_ 29 #include "../extension.h" 40 template<
typename IndexExp,
typename SrcExp,
typename DType>
42 DType, type::kChainer> {
51 : index_(index), src_(src), input_dim_(input_dim) {}
55 template<
typename IndexExp,
72 template<
typename IndexExp,
typename SrcExp,
typename DType>
84 for (
index_t i = 0; i < batch_size_; ++i) {
87 ret +=
static_cast<DType
>(
src_.Eval(i, x));
100 template<
typename IndexExp,
typename SrcExp,
typename DType>
106 template<
int dim,
typename IndexExp,
typename SrcExp,
typename DType>
111 <<
"TakeGradExp only support 2D output";
121 template<
typename IndexExp,
typename SrcExp,
typename DType>
123 static const int kDim = 2;
130 #endif // MSHADOW_EXTENSION_TAKE_GRAD_H_ const IndexExp & index_
index oprand
Definition: take_grad.h:44
Definition: expr_engine-inl.h:59
const SrcExp & src_
out gradient oprand
Definition: take_grad.h:46
static Shape< dim > Check(const E &t)
#define MSHADOW_XINLINE
Definition: base.h:223
static type inference template, used to get the dimension of each expression, if ExpInfo<E>::kDim == ...
Definition: expr_engine-inl.h:263
static Shape< dim > Check(const TakeGradExp< IndexExp, SrcExp, DType > &t)
Definition: take_grad.h:109
int32_t index_t
type that will be used for index
Definition: base.h:336
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:60
runtime shape checking template get the shape of an expression, report error if shape mismatch ...
Definition: expr_engine-inl.h:365
Calculate embedding gradient.
Definition: take_grad.h:41
const index_t input_dim_
batch size
Definition: take_grad.h:48
defines how expression exp can be evaluated and stored into dst
Definition: expression.h:80
const SubType & self(void) const
Definition: expression.h:83
Plan< BinaryMapExp< OP, TA, TB, DType, etype >, DType > MakePlan(const BinaryMapExp< OP, TA, TB, DType, etype > &e)
Definition: expr_engine-inl.h:240
TakeGradExp(const IndexExp &index, const SrcExp &src, const index_t input_dim)
constructor
Definition: take_grad.h:50
MSHADOW_XINLINE DType Eval(index_t y, index_t x) const
Definition: take_grad.h:82
overloaded + operator between half_t and bf16_t
Definition: base.h:327
Plan(const TakeGradExp< IndexExp, SrcExp, DType > &e)
Definition: take_grad.h:75