1 #ifndef MSHADOW_TENSOR_EXPR_H
2 #define MSHADOW_TENSOR_EXPR_H
33 template<
typename Saver,
typename Container>
35 template<
typename EType>
36 inline static void Eval( Container& dst,
const EType &exp );
39 template<
typename Container>
48 template<
typename SubType,
int exp_type>
52 inline const SubType&
self( void )
const{
53 return *
static_cast<const SubType*
>(
this);
57 return *
static_cast<SubType*
>(
this);
70 template<
typename EType>
78 inline const EType &
T(
void )
const{
87 template<
typename Container>
88 class ContainerExp:
public Exp< Container, type::kContainer >{
137 template<
typename E,
int etype>
143 template<
typename E,
int etype>
149 template<
typename E,
int etype>
155 template<
typename E,
int etype>
171 template<
typename TA,
typename TB,
bool ltrans,
bool rtrans>
172 struct DotExp:
public Exp< DotExp<TA,TB,ltrans,rtrans>, type::kComplex >{
185 template<
typename TA,
typename TB>
190 template<
typename TA,
typename TB>
195 template<
typename TA,
typename TB>
200 template<
typename TA,
typename TB>
205 template<
typename TA,
typename TB,
bool ltrans,
bool rtrans >
210 template<
typename TA,
typename TB,
bool ltrans,
bool rtrans >
224 template<
typename OP,
typename TA,
typename TB,
int etype >
236 template<
typename OP,
typename TA,
typename TB,
int ta,
int tb>
252 template<
typename OP,
typename TA,
typename TB,
int ta,
int tb>
254 return MakeExp<OP>( lhs, rhs );
257 template<
typename OP,
typename TA,
int ta>
259 return MakeExp<OP>( lhs, rhs );
262 template<
typename OP,
typename TB,
int tb>
264 return MakeExp<OP>( lhs, rhs );
269 template<
typename TA,
typename TB,
int ta,
int tb>
271 return MakeExp<op::plus>( lhs, rhs );
274 template<
typename TA,
typename TB,
int ta,
int tb>
276 return MakeExp<op::minus>( lhs, rhs );
279 template<
typename TA,
typename TB,
int ta,
int tb>
281 return MakeExp<op::mul>( lhs, rhs );
284 template<
typename TA,
typename TB,
int ta,
int tb>
286 return MakeExp<op::div>( lhs, rhs );
290 template<
typename TA,
int ta>
292 return MakeExp<op::plus>( lhs, rhs );
295 template<
typename TA,
int ta>
297 return MakeExp<op::minus>( lhs, rhs );
300 template<
typename TA,
int ta>
302 return MakeExp<op::mul>( lhs, rhs );
305 template<
typename TA,
int ta>
307 return MakeExp<op::div>( lhs, rhs );
311 template<
typename TB,
int tb>
313 return MakeExp<op::plus>( lhs, rhs );
316 template<
typename TB,
int tb>
318 return MakeExp<op::minus>( lhs, rhs );
321 template<
typename TB,
int tb>
323 return MakeExp<op::mul>( lhs, rhs );
326 template<
typename TB,
int tb>
328 return MakeExp<op::div>( lhs, rhs );
339 template<
typename OP,
typename TA,
int etype >
348 template<
typename OP,
typename TA,
int ta>
361 template<
typename OP,
typename TA,
int ta>
363 return MakeExp<OP>(src);
DotExp< TA, TB, false, false > dot(const ContainerExp< TA > &lhs, const ContainerExp< TB > &rhs)
dot operator def
Definition: tensor_expr.h:186
DotExp< TA, TB, ltrans, rtrans > operator*(const DotExp< TA, TB, ltrans, rtrans > &lhs, real_t rhs)
dot operator def
Definition: tensor_expr.h:206
const int kMapper
this only contains element-wise vector operations
Definition: tensor_expr.h:24
SubType & refself(void)
Definition: tensor_expr.h:56
Container & operator/=(real_t s)
operator overload
Definition: tensor_expr.h:114
const int kComplex
othercase: e.g dot product
Definition: tensor_expr.h:26
binary map expression lhs [op] rhs
Definition: tensor_expr.h:225
Container & operator-=(const Exp< E, etype > &exp)
implementation of operator-=
Definition: tensor_expr.h:144
Container & operator-=(real_t s)
operator overload
Definition: tensor_expr.h:104
BinaryMapExp< OP, TA, TB,(ta|tb|type::kMapper) > F(const Exp< TA, ta > &lhs, const Exp< TB, tb > &rhs)
short hand for MakeExp, usage F<op>(lhs, rhs). create a binary operation expression ...
Definition: tensor_expr.h:253
float real_t
type that will be used for content
Definition: tensor_base.h:118
TransposeExp(const EType &e)
constructor
Definition: tensor_expr.h:76
const SubType & self(void) const
Definition: tensor_expr.h:52
BinaryMapExp< OP, TA, TB,(ta|tb|type::kMapper) > MakeExp(const Exp< TA, ta > &lhs, const Exp< TB, tb > &rhs)
make expression
Definition: tensor_expr.h:237
const int kContainer
this expression directly correspnds to a data class
Definition: tensor_expr.h:22
Container & operator+=(const Exp< E, etype > &exp)
implementation of operator+=
Definition: tensor_expr.h:138
const TA & src_
source expression
Definition: tensor_expr.h:342
BinaryMapExp< op::minus, TA, TB,(ta|tb|type::kMapper) > operator-(const Exp< TA, ta > &lhs, const Exp< TB, tb > &rhs)
operator overload
Definition: tensor_expr.h:275
const EType & T(void) const
transpose expression
Definition: tensor_expr.h:78
DotExp(const TA &lhs, const TB &rhs, real_t scale)
constructor
Definition: tensor_expr.h:180
BinaryMapExp< op::div, TA, TB,(ta|tb|type::kMapper) > operator/(const Exp< TA, ta > &lhs, const Exp< TB, tb > &rhs)
operator overload
Definition: tensor_expr.h:285
Container & operator+=(real_t s)
operator overload
Definition: tensor_expr.h:99
const TransposeExp< Container > T(void) const
transpose of a matrix
Definition: tensor_expr.h:94
Container & __assign(real_t s)
operator overload
Definition: tensor_expr.h:119
ScalarExp(real_t scalar)
constructor
Definition: tensor_expr.h:66
represent a transpose expression of a container
Definition: tensor_expr.h:71
Container & __assign(const Exp< E, type::kComplex > &exp)
implementation of operator=, note that we can not define container = container
Definition: tensor_expr.h:132
definitions of base types, macros functions
Container & operator*=(const Exp< E, etype > &exp)
implementation of operator*=
Definition: tensor_expr.h:150
unary map expression op(src)
Definition: tensor_expr.h:340
matrix multiplication expression dot( lhs[.T], rhs[.T] )
Definition: tensor_expr.h:172
Container & __assign(const Exp< E, type::kMapper > &exp)
implementation of operator=, note that we can not define container = container
Definition: tensor_expr.h:126
scalar expression
Definition: tensor_expr.h:62
Container & operator*=(real_t s)
operator overload
Definition: tensor_expr.h:109
base class for expression
Definition: tensor_expr.h:49
const TB & rhs_
right operand
Definition: tensor_expr.h:176
const TA & lhs_
left operand
Definition: tensor_expr.h:227
UnaryMapExp(const TA &src)
constructor
Definition: tensor_expr.h:344
base class of all variables, that can be assigned to values
Definition: tensor_expr.h:40
expression engine that actually interprets these expressions this is a function template that needed ...
Definition: tensor_expr.h:34
BinaryMapExp(const TA &lhs, const TB &rhs)
constructor
Definition: tensor_expr.h:231
real_t scale_
scale over result
Definition: tensor_expr.h:178
real_t scalar_
scalar value
Definition: tensor_expr.h:64
const TA & lhs_
left operand
Definition: tensor_expr.h:174
const TB & rhs_
right operand
Definition: tensor_expr.h:229
BinaryMapExp< op::plus, TA, TB,(ta|tb|type::kMapper) > operator+(const Exp< TA, ta > &lhs, const Exp< TB, tb > &rhs)
operator overload
Definition: tensor_expr.h:270
const EType & exp
expression to be transposed
Definition: tensor_expr.h:74
Container & operator/=(const Exp< E, etype > &exp)
implementation of operator/=
Definition: tensor_expr.h:156