mxnet
reduceto1d.h
Go to the documentation of this file.
1 
7 #ifndef MSHADOW_EXTENSION_REDUCETO1D_H_
8 #define MSHADOW_EXTENSION_REDUCETO1D_H_
9 #include "../extension.h"
10 namespace mshadow {
11 namespace expr {
22 template<typename SrcExp, typename DType, typename Reducer, int m_dimkeep>
24  public Exp<ReduceTo1DExp<SrcExp, DType, Reducer, m_dimkeep>,
25  DType, type::kComplex> {
27  const SrcExp &src_;
29  DType scale_;
31  ReduceTo1DExp(const SrcExp& src, DType scale) : src_(src), scale_(scale) {}
32 };
41 template<int dimkeep, typename SrcExp, typename DType, int etype>
42 inline ReduceTo1DExp<SrcExp, DType, red::sum,
43  ExpInfo<SrcExp>::kDim - dimkeep>
45  return ReduceTo1DExp<SrcExp, DType, red::sum,
46  ExpInfo<SrcExp>::kDim - dimkeep>(exp.self(), DType(1));
47 }
56 template<int dimkeep, typename Reducer, typename SrcExp, typename DType, int etype>
57 inline ReduceTo1DExp<SrcExp, DType, Reducer,
58  ExpInfo<SrcExp>::kDim - dimkeep>
60  return ReduceTo1DExp<SrcExp, DType, Reducer,
61  ExpInfo<SrcExp>::kDim - dimkeep>(exp.self(), DType(1));
62 }
70 template<typename SrcExp, typename DType, int etype>
74  ::Error_Expression_Does_Not_Meet_Dimension_Req();
75  return sumall_except_dim<1>(exp);
76 }
77 template<typename SV, typename Device, typename DType,
78  typename SrcExp, typename Reducer, int m_dimkeep>
79 struct ExpComplexEngine<SV,
80  Tensor<Device, 1, DType>,
81  ReduceTo1DExp<SrcExp, DType, Reducer, m_dimkeep>,
82  DType> {
83  static const int dimkeep = ExpInfo<SrcExp>::kDim - m_dimkeep;
84  inline static void Eval(Tensor<Device, 1, DType> *dst,
85  const ReduceTo1DExp<SrcExp, DType,
86  Reducer, m_dimkeep> &exp) {
89  MapReduceKeepHighDim<SV, Reducer, dimkeep>(dst, exp.src_, exp.scale_);
90  }
91 };
92 template<typename SV, typename Device, typename DType,
93  typename SrcExp, typename Reducer>
94 struct ExpComplexEngine<SV,
95  Tensor<Device, 1, DType>,
96  ReduceTo1DExp<SrcExp, DType, Reducer, 1>, DType> {
97  inline static void Eval(Tensor<Device, 1, DType> *dst,
99  MapReduceKeepLowest<SV, Reducer>(dst, exp.src_, exp.scale_);
100  }
101 };
102 } // namespace expr
103 } // namespace mshadow
104 #endif // MSHADOW_EXTENSION_REDUCETO1D_H_
static void Eval(Tensor< Device, 1, DType > *dst, const ReduceTo1DExp< SrcExp, DType, Reducer, m_dimkeep > &exp)
Definition: reduceto1d.h:84
const SrcExp & src_
source operand
Definition: reduceto1d.h:27
ReduceTo1DExp(const SrcExp &src, DType scale)
construct a repmat expression from src and nrow
Definition: reduceto1d.h:31
used to help static type check
Definition: expr_engine-inl.h:312
ReduceTo1DExp< SrcExp, DType, Reducer, ExpInfo< SrcExp >::kDim-dimkeep > reduce_except_dim(const Exp< SrcExp, DType, etype > &exp)
reduce over all dimensions, except dimkeep
Definition: reduceto1d.h:59
DType scale_
source operand, scale of the
Definition: reduceto1d.h:29
reduction to 1 dimension tensor input: Tensor<Device,k>: ishape output: Tensor<Device,1> shape[0] = ishape[dimkeep];
Definition: reduceto1d.h:23
static type inference template, used to get the dimension of each expression, if ExpInfo<E>::kDim == ...
Definition: expr_engine-inl.h:244
static void Eval(Tensor< Device, 1, DType > *dst, const ReduceTo1DExp< SrcExp, DType, Reducer, 1 > &exp)
Definition: reduceto1d.h:97
some engine that evaluate complex expression
Definition: expr_engine-inl.h:437
sum reducer
Definition: base.h:816
defines how expression exp can be evaluated and stored into dst
Definition: expression.h:61
const SubType & self(void) const
Definition: expression.h:64
Definition: tensor.h:550
namespace for mshadow
Definition: base.h:282
general tensor
Definition: tensor.h:402
ReduceTo1DExp< SrcExp, DType, red::sum, 1 > sum_rows(const Exp< SrcExp, DType, etype > &exp)
a expression that sum over rows of a matrix
Definition: reduceto1d.h:72
ReduceTo1DExp< SrcExp, DType, red::sum, ExpInfo< SrcExp >::kDim-dimkeep > sumall_except_dim(const Exp< SrcExp, DType, etype > &exp)
a sum over all dimensions, except dimkeep
Definition: reduceto1d.h:44