Go to the documentation of this file.
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>
125 inline TypecastExp<DstDType, SrcDType, EType, (etype|
type::kMapper)>
130 template<
typename EType,
typename DType>
132 DType, type::kChainer> {
138 inline const EType &
T(
void)
const {
147 template<
typename Container,
typename DType>
183 template<
typename E,
int etype>
191 template<
typename E,
int etype>
197 template<
typename E,
int etype>
203 template<
typename E,
int etype>
209 template<
typename E,
int etype>
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)
238 template<
typename TA,
typename TB,
typename DType>
239 inline DotExp<TA, TB, false, false, DType>
244 template<
typename TA,
typename TB,
typename DType>
245 inline DotExp<TA, TB, true, false, DType>
250 template<
typename TA,
typename TB,
typename DType>
251 inline DotExp<TA, TB, false, true, DType>
256 template<
typename TA,
typename TB,
typename DType>
257 inline DotExp<TA, TB, true, true, DType>
262 template<
bool transpose_left,
bool transpose_right,
typename TA,
typename TB,
typename DType>
263 inline DotExp<TA, TB, transpose_left, transpose_right, DType>
266 lhs.
self(), rhs.
self(), DType(1.0f));
278 template<
typename OP,
typename TA,
typename TB,
typename TC,
typename DType,
int etype>
293 template<
typename OP,
typename TA,
typename TB,
typename TC,
typename DType,
int ta,
int tb,
int tc>
294 inline TernaryMapExp<OP, TA, TB, TC, DType, (ta|tb|tc|
type::kMapper)>
317 template<
typename OP,
typename TA,
typename TB,
typename TC,
typename DType,
int ta,
int tb,
int tc>
318 inline TernaryMapExp<OP, TA, TB, TC, DType, (ta|tb|tc|
type::kMapper)>
321 return MakeExp<OP>(item1, item2, item3);
333 template<
typename OP,
typename TA,
typename TB,
typename DType,
int etype>
346 template<
typename OP,
typename TA,
typename TB,
typename DType,
int ta,
int tb>
347 inline BinaryMapExp<OP, TA, TB, DType, (ta|tb|
type::kMapper)>
364 template<
typename OP,
typename TA,
typename TB,
typename DType,
int ta,
int tb>
365 inline BinaryMapExp<OP, TA, TB, DType, (ta|tb|
type::kMapper)>
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 SubType & self(void) const
Definition: expression.h:82
ScalarExp< DType > scalar(DType s)
create an scalar expression
Definition: expression.h:103
const EType & exp
expression to be typecasted
Definition: expression.h:118
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
Container & operator/=(const Exp< E, DType, etype > &exp)
implementation of operator/=
Definition: expression.h:210
const TransposeExp< Container, DType > T(void) const
transpose of a matrix
Definition: expression.h:154
TypecastExp(const EType &e)
constructor
Definition: expression.h:120
SubType * ptrself(void)
Definition: expression.h:86
typecast expression, cast the type of elements
Definition: expression.h:114
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
Container & operator-=(DType s)
operator overload
Definition: expression.h:163
minus operator
Definition: base.h:641
DotExp(const TA &lhs, const TB &rhs, DType scale)
constructor
Definition: expression.h:233
const TA & lhs_
left operand
Definition: expression.h:227
divide operator
Definition: base.h:649
const TC & item3_
third operand
Definition: expression.h:286
the engine that dispatches simple operations
Definition: expr_engine-inl.h:460
ternary map expression
Definition: expression.h:279
const TA & item1_
first operand
Definition: expression.h:282
Container & operator*=(const Exp< E, DType, etype > &exp)
implementation of operator*=
Definition: expression.h:204
BinaryMapExp(const TA &lhs, const TB &rhs)
constructor
Definition: expression.h:341
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
TypecastExp< DstDType, SrcDType, EType,(etype|type::kMapper)> tcast(const Exp< EType, SrcDType, etype > &exp)
create an scalar expression
Definition: expression.h:126
const int kMapper
expression contains element-wise tensor operations, map a expression to same shape
Definition: expression.h:50
binary map expression lhs [op] rhs
Definition: expression.h:334
Container & operator-=(const Exp< E, DType, etype > &exp)
implementation of operator-=
Definition: expression.h:198
const EType & T(void) const
transpose expression
Definition: expression.h:138
DType scale_
scale over result
Definition: expression.h:231
plus operator
Definition: base.h:633
const TB & rhs_
right operand
Definition: expression.h:229
Container & operator/=(DType s)
operator overload
Definition: expression.h:173
const int kComplex
othercase: e.g dot product
Definition: expression.h:58
const TA & src_
source expression
Definition: expression.h:407
const TB & item2_
second operand
Definition: expression.h:284
Container & operator+=(DType s)
operator overload
Definition: expression.h:158
DType scalar_
scalar value
Definition: expression.h:97
ScalarExp(DType scalar)
implicit constructor, MUST NOT BE explicit
Definition: expression.h:99
UnaryMapExp(const TA &src)
constructor
Definition: expression.h:409
const TB & rhs_
right operand
Definition: expression.h:339
base class of all rvalues
Definition: expression.h:148
defines how expression exp can be evaluated and stored into dst
Definition: expression.h:79
Container & __assign(const Exp< E, DType, etype > &exp)
we can not define container = container
Definition: expression.h:184
TransposeExp(const EType &e)
constructor
Definition: expression.h:136
represent a transpose expression of a container
Definition: expression.h:131
const EType & exp
expression to be transposed
Definition: expression.h:134
overloaded + operator between half_t and bf16_t
Definition: base.h:319
const TA & lhs_
left operand
Definition: expression.h:337
static void Eval(RV *dst, const Exp< E, DType, type::kMapper > &exp)
Definition: expr_engine-inl.h:462
Container & __assign(DType s)
operator overload
Definition: expression.h:178
TernaryMapExp(const TA &item1, const TB &item2, const TC &item3)
constructor
Definition: expression.h:288
mul operator
Definition: base.h:625
DotExp< TA, TB, false, false, DType > dot(const RValueExp< TA, DType > &lhs, const RValueExp< TB, DType > &rhs)
dot operator def
Definition: expression.h:240
Container & operator*=(DType s)
operator overload
Definition: expression.h:168
unary map expression op(src)
Definition: expression.h:404
definitions of base types, operators, macros functions
scalar expression
Definition: expression.h:95
const int kRValue
this expression directly correspnds to a data class, can be used to assign data
Definition: expression.h:45
const int kChainer
expression that can be chained with other expressiones Usually it have function Eval(i,...
Definition: expression.h:56
Container & operator+=(const Exp< E, DType, etype > &exp)
implementation of operator+=
Definition: expression.h:192
matrix multiplication expression dot(lhs[.T], rhs[.T])
Definition: expression.h:224