25 #ifndef MSHADOW_EXPRESSION_H_ 26 #define MSHADOW_EXPRESSION_H_ 67 template<
typename Saver,
typename RValue,
typename DType>
78 template<
typename SubType,
typename DType,
int exp_type>
82 inline const SubType&
self(void)
const {
83 return *
static_cast<const SubType*
>(
this);
87 return static_cast<SubType*
>(
this);
94 template<
typename DType>
95 struct ScalarExp:
public Exp<ScalarExp<DType>, DType, type::kMapper> {
102 template<
typename DType>
113 template<
typename DstDType,
typename SrcDType,
typename EType,
int etype>
115 public Exp<TypecastExp<DstDType, SrcDType, EType, etype>,
123 template<
typename DstDType,
typename SrcDType,
124 typename EType,
int etype>
130 template<
typename EType,
typename DType>
132 DType, type::kChainer> {
138 inline const EType &
T(
void)
const {
147 template<
typename Container,
typename DType>
160 return *(this->ptrself());
165 return *(this->ptrself());
170 return *(this->ptrself());
175 return *(this->ptrself());
180 return *(this->ptrself());
183 template<
typename E,
int etype>
186 return *(this->ptrself());
191 template<
typename E,
int etype>
194 return *(this->ptrself());
197 template<
typename E,
int etype>
200 return *(this->ptrself());
203 template<
typename E,
int etype>
206 return *(this->ptrself());
209 template<
typename E,
int etype>
212 return *(this->ptrself());
223 template<
typename TA,
typename TB,
bool ltrans,
bool rtrans,
typename DType>
224 struct DotExp:
public Exp<DotExp<TA, TB, ltrans, rtrans, DType>,
225 DType, type::kComplex> {
233 explicit DotExp(
const TA &lhs,
const TB &rhs, DType scale)
234 : lhs_(lhs), rhs_(rhs), scale_(scale) {}
238 template<
typename TA,
typename TB,
typename DType>
244 template<
typename TA,
typename TB,
typename DType>
250 template<
typename TA,
typename TB,
typename DType>
256 template<
typename TA,
typename TB,
typename DType>
262 template<
bool transpose_left,
bool transpose_right,
typename TA,
typename TB,
typename DType>
266 lhs.
self(), rhs.
self(), DType(1.0f));
278 template<
typename OP,
typename TA,
typename TB,
typename TC,
typename DType,
int etype>
289 :item1_(item1), item2_(item2), item3_(item3) {}
293 template<
typename OP,
typename TA,
typename TB,
typename TC,
typename DType,
int ta,
int tb,
int tc>
317 template<
typename OP,
typename TA,
typename TB,
typename TC,
typename DType,
int ta,
int tb,
int tc>
321 return MakeExp<OP>(item1, item2, item3);
333 template<
typename OP,
typename TA,
typename TB,
typename DType,
int etype>
342 :lhs_(lhs), rhs_(rhs) {}
346 template<
typename OP,
typename TA,
typename TB,
typename DType,
int ta,
int tb>
364 template<
typename OP,
typename TA,
typename TB,
typename DType,
int ta,
int tb>
367 return MakeExp<OP>(lhs, rhs);
371 template<
typename TA,
typename TB,
typename DType,
int ta,
int tb>
374 return MakeExp<op::plus>(lhs, rhs);
377 template<
typename TA,
typename TB,
typename DType,
int ta,
int tb>
380 return MakeExp<op::minus>(lhs, rhs);
383 template<
typename TA,
typename TB,
typename DType,
int ta,
int tb>
386 return MakeExp<op::mul>(lhs, rhs);
389 template<
typename TA,
typename TB,
typename DType,
int ta,
int tb>
392 return MakeExp<op::div>(lhs, rhs);
403 template<
typename OP,
typename TA,
typename DType,
int etype>
413 template<
typename OP,
typename TA,
typename DType,
int ta>
427 template<
typename OP,
typename TA,
typename DType,
int ta>
430 return MakeExp<OP>(src);
434 #endif // MSHADOW_EXPRESSION_H_ const int kRValue
this expression directly correspnds to a data class, can be used to assign data
Definition: expression.h:45
const int kMapper
expression contains element-wise tensor operations, map a expression to same shape ...
Definition: expression.h:50
DotExp< TA, TB, transpose_left, transpose_right, DType > batch_dot(const RValueExp< TA, DType > &lhs, const RValueExp< TB, DType > &rhs)
batch_dot operator def
Definition: expression.h:264
ScalarExp< DType > scalar(DType s)
create an scalar expression
Definition: expression.h:103
BinaryMapExp< op::minus, TA, ScalarExp< MSHADOW_SCALAR_ >, MSHADOW_SCALAR_,(ta|type::kMapper)> operator-(const Exp< TA, MSHADOW_SCALAR_, ta > &lhs, const ScalarExp< MSHADOW_SCALAR_ > &rhs)
operator overload
Definition: expr_scalar-inl.h:101
BinaryMapExp< op::plus, TA, ScalarExp< MSHADOW_SCALAR_ >, MSHADOW_SCALAR_,(ta|type::kMapper)> operator+(const Exp< TA, MSHADOW_SCALAR_, ta > &lhs, const ScalarExp< MSHADOW_SCALAR_ > &rhs)
operator overload
Definition: expr_scalar-inl.h:93
const SubType & self(void) const
Definition: expression.h:82
UnaryMapExp(const TA &src)
constructor
Definition: expression.h:409
const TB & rhs_
right operand
Definition: expression.h:339
SubType * ptrself(void)
Definition: expression.h:86
Container & operator/=(const Exp< E, DType, etype > &exp)
implementation of operator/=
Definition: expression.h:210
const int kComplex
othercase: e.g dot product
Definition: expression.h:58
ternary map expression
Definition: expression.h:279
const EType & T(void) const
transpose expression
Definition: expression.h:138
binary map expression lhs [op] rhs
Definition: expression.h:334
DotExp< TA, TB, false, false, DType > dot(const RValueExp< TA, DType > &lhs, const RValueExp< TB, DType > &rhs)
dot operator def
Definition: expression.h:240
TernaryMapExp(const TA &item1, const TB &item2, const TC &item3)
constructor
Definition: expression.h:288
TypecastExp(const EType &e)
constructor
Definition: expression.h:120
BinaryMapExp(const TA &lhs, const TB &rhs)
constructor
Definition: expression.h:341
TypecastExp< DstDType, SrcDType, EType,(etype|type::kMapper)> tcast(const Exp< EType, SrcDType, etype > &exp)
create an scalar expression
Definition: expression.h:126
Container & operator*=(const Exp< E, DType, etype > &exp)
implementation of operator*=
Definition: expression.h:204
base class of all rvalues
Definition: expression.h:148
DType scalar_
scalar value
Definition: expression.h:97
const TB & rhs_
right operand
Definition: expression.h:229
const EType & exp
expression to be transposed
Definition: expression.h:134
const int kChainer
expression that can be chained with other expressiones Usually it have function Eval(i,j) defined, which pulls the result (i, j) from input expression and output the result at certain position.
Definition: expression.h:56
const TB & item2_
second operand
Definition: expression.h:284
ScalarExp(DType scalar)
implicit constructor, MUST NOT BE explicit
Definition: expression.h:99
Container & operator-=(DType s)
operator overload
Definition: expression.h:163
Container & operator-=(const Exp< E, DType, etype > &exp)
implementation of operator-=
Definition: expression.h:198
BinaryMapExp< OP, TA, ScalarExp< MSHADOW_SCALAR_ >, MSHADOW_SCALAR_,(ta|type::kMapper)> F(const Exp< TA, MSHADOW_SCALAR_, ta > &lhs, const ScalarExp< MSHADOW_SCALAR_ > &rhs)
operator overload for const
Definition: expr_scalar-inl.h:71
DType scale_
scale over result
Definition: expression.h:231
DotExp(const TA &lhs, const TB &rhs, DType scale)
constructor
Definition: expression.h:233
const TransposeExp< Container, DType > T(void) const
transpose of a matrix
Definition: expression.h:154
Container & operator/=(DType s)
operator overload
Definition: expression.h:173
const TA & item1_
first operand
Definition: expression.h:282
typecast expression, cast the type of elements
Definition: expression.h:114
represent a transpose expression of a container
Definition: expression.h:131
Container & operator+=(DType s)
operator overload
Definition: expression.h:158
const TA & src_
source expression
Definition: expression.h:407
unary map expression op(src)
Definition: expression.h:404
matrix multiplication expression dot(lhs[.T], rhs[.T])
Definition: expression.h:224
scalar expression
Definition: expression.h:95
TernaryMapExp< OP, TA, TB, TC, DType,(ta|tb|tc|type::kMapper)> MakeExp(const Exp< TA, DType, ta > &item1, const Exp< TB, DType, tb > &item2, const Exp< TC, DType, tc > &item3)
make expression
Definition: expression.h:295
defines how expression exp can be evaluated and stored into dst
Definition: expression.h:79
const EType & exp
expression to be typecasted
Definition: expression.h:118
const TC & item3_
third operand
Definition: expression.h:286
Container & operator*=(DType s)
operator overload
Definition: expression.h:168
BinaryMapExp< op::div, TA, ScalarExp< MSHADOW_SCALAR_ >, MSHADOW_SCALAR_,(ta|type::kMapper)> operator/(const Exp< TA, MSHADOW_SCALAR_, ta > &lhs, const ScalarExp< MSHADOW_SCALAR_ > &rhs)
operator overload
Definition: expr_scalar-inl.h:117
const TA & lhs_
left operand
Definition: expression.h:227
const TA & lhs_
left operand
Definition: expression.h:337
overloaded + operator between half_t and bf16_t
Definition: base.h:334
DotExp< TA, TB, ltrans, rtrans, MSHADOW_SCALAR_ > operator*(const DotExp< TA, TB, ltrans, rtrans, MSHADOW_SCALAR_ > &lhs, MSHADOW_SCALAR_ rhs)
dot operator def
Definition: expr_scalar-inl.h:40
the engine that dispatches simple operations
Definition: expr_engine-inl.h:460
Container & __assign(DType s)
operator overload
Definition: expression.h:178
Container & operator+=(const Exp< E, DType, etype > &exp)
implementation of operator+=
Definition: expression.h:192
static void Eval(RV *dst, const Exp< E, DType, type::kMapper > &exp)
Definition: expr_engine-inl.h:462
TransposeExp(const EType &e)
constructor
Definition: expression.h:136
Container & __assign(const Exp< E, DType, etype > &exp)
we can not define container = container
Definition: expression.h:184