Go to the documentation of this file.
25 #ifndef MSHADOW_EXTENSION_TAKE_GRAD_H_
26 #define MSHADOW_EXTENSION_TAKE_GRAD_H_
28 #include "../extension.h"
39 template<
typename IndexExp,
typename SrcExp,
typename DType>
41 DType, type::kChainer> {
54 template<
typename IndexExp,
58 inline TakeGradExp<IndexExp, SrcExp, DType>
71 template<
typename IndexExp,
typename SrcExp,
typename DType>
77 batch_size_(
ShapeCheck<1, IndexExp>::Check(e.index_)[0]) {
83 for (
index_t i = 0; i < batch_size_; ++i) {
86 ret +=
static_cast<DType
>(src_.Eval(i, x));
99 template<
typename IndexExp,
typename SrcExp,
typename DType>
100 inline Plan<TakeGradExp<IndexExp, SrcExp, DType>, DType>
105 template<
int dim,
typename IndexExp,
typename SrcExp,
typename DType>
110 <<
"TakeGradExp only support 2D output";
120 template<
typename IndexExp,
typename SrcExp,
typename DType>
129 #endif // MSHADOW_EXTENSION_TAKE_GRAD_H_
static const int kDevMask
Definition: expr_engine-inl.h:264
const SubType & self(void) const
Definition: expression.h:82
#define MSHADOW_XINLINE
Definition: base.h:228
Calculate embedding gradient.
Definition: take_grad.h:40
runtime shape checking template get the shape of an expression, report error if shape mismatch
Definition: expr_engine-inl.h:364
MSHADOW_XINLINE DType Eval(index_t y, index_t x) const
Definition: take_grad.h:81
static Shape< dim > Check(const E &t)
const index_t input_dim_
batch size
Definition: take_grad.h:47
static type inference template, used to get the dimension of each expression, if ExpInfo<E>::kDim == ...
Definition: expr_engine-inl.h:262
Plan< BinaryMapExp< OP, TA, TB, DType, etype >, DType > MakePlan(const BinaryMapExp< OP, TA, TB, DType, etype > &e)
Definition: expr_engine-inl.h:239
static const int kDim
Definition: expr_engine-inl.h:263
static Shape< dim > Check(const TakeGradExp< IndexExp, SrcExp, DType > &t)
Definition: take_grad.h:108
int32_t index_t
type that will be used for index
Definition: base.h:328
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:59
Definition: expr_engine-inl.h:58
defines how expression exp can be evaluated and stored into dst
Definition: expression.h:79
Plan(const TakeGradExp< IndexExp, SrcExp, DType > &e)
Definition: take_grad.h:74
overloaded + operator between half_t and bf16_t
Definition: base.h:319
const IndexExp & index_
index oprand
Definition: take_grad.h:43
TakeGradExp(const IndexExp &index, const SrcExp &src, const index_t input_dim)
constructor
Definition: take_grad.h:49
const SrcExp & src_
out gradient oprand
Definition: take_grad.h:45