mxnet
reduceto1d.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
25 #ifndef MSHADOW_EXTENSION_REDUCETO1D_H_
26 #define MSHADOW_EXTENSION_REDUCETO1D_H_
27 #include "../extension.h"
28 namespace mshadow {
29 namespace expr {
40 template<typename SrcExp, typename DType, typename Reducer, int m_dimkeep>
42  public Exp<ReduceTo1DExp<SrcExp, DType, Reducer, m_dimkeep>,
43  DType, type::kComplex> {
45  const SrcExp &src_;
47  DType scale_;
49  ReduceTo1DExp(const SrcExp& src, DType scale) : src_(src), scale_(scale) {}
50 };
59 template<int dimkeep, typename SrcExp, typename DType, int etype>
60 inline ReduceTo1DExp<SrcExp, DType, red::sum,
61  ExpInfo<SrcExp>::kDim - dimkeep>
63  return ReduceTo1DExp<SrcExp, DType, red::sum,
64  ExpInfo<SrcExp>::kDim - dimkeep>(exp.self(), DType(1));
65 }
74 template<int dimkeep, typename Reducer, typename SrcExp, typename DType, int etype>
75 inline ReduceTo1DExp<SrcExp, DType, Reducer,
76  ExpInfo<SrcExp>::kDim - dimkeep>
78  return ReduceTo1DExp<SrcExp, DType, Reducer,
79  ExpInfo<SrcExp>::kDim - dimkeep>(exp.self(), DType(1));
80 }
88 template<typename SrcExp, typename DType, int etype>
89 inline ReduceTo1DExp<SrcExp, DType, red::sum, 1>
92  ::Error_Expression_Does_Not_Meet_Dimension_Req();
93  return sumall_except_dim<1>(exp);
94 }
95 template<typename SV, typename Device, typename DType,
96  typename SrcExp, typename Reducer, int m_dimkeep>
97 struct ExpComplexEngine<SV,
98  Tensor<Device, 1, DType>,
99  ReduceTo1DExp<SrcExp, DType, Reducer, m_dimkeep>,
100  DType> {
101  static const int dimkeep = ExpInfo<SrcExp>::kDim - m_dimkeep;
102  inline static void Eval(Tensor<Device, 1, DType> *dst,
103  const ReduceTo1DExp<SrcExp, DType,
104  Reducer, m_dimkeep> &exp) {
107  MapReduceKeepHighDim<SV, Reducer, dimkeep>(dst, exp.src_, exp.scale_);
108  }
109 };
110 template<typename SV, typename Device, typename DType,
111  typename SrcExp, typename Reducer>
113  Tensor<Device, 1, DType>,
114  ReduceTo1DExp<SrcExp, DType, Reducer, 1>, DType> {
115  inline static void Eval(Tensor<Device, 1, DType> *dst,
117  MapReduceKeepLowest<SV, Reducer>(dst, exp.src_, exp.scale_);
118  }
119 };
120 } // namespace expr
121 } // namespace mshadow
122 #endif // MSHADOW_EXTENSION_REDUCETO1D_H_
mshadow::expr::ReduceTo1DExp::ReduceTo1DExp
ReduceTo1DExp(const SrcExp &src, DType scale)
construct a repmat expression from src and nrow
Definition: reduceto1d.h:49
mshadow::expr::Exp::self
const SubType & self(void) const
Definition: expression.h:82
mshadow::expr::TypeCheckPass
used to help static type check
Definition: expr_engine-inl.h:330
mshadow::expr::ReduceTo1DExp::src_
const SrcExp & src_
source operand
Definition: reduceto1d.h:45
mshadow::expr::ReduceTo1DExp::scale_
DType scale_
source operand, scale of the
Definition: reduceto1d.h:47
mshadow::Tensor
general tensor
Definition: tensor.h:525
mshadow::red::sum
sum reducer
Definition: base.h:987
mshadow::expr::reduce_except_dim
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:77
mshadow::expr::ExpInfo
static type inference template, used to get the dimension of each expression, if ExpInfo<E>::kDim == ...
Definition: expr_engine-inl.h:262
mshadow::expr::ExpInfo::kDim
static const int kDim
Definition: expr_engine-inl.h:263
mshadow::expr::ExpComplexEngine
some engine that evaluate complex expression
Definition: expr_engine-inl.h:455
mshadow::expr::ReduceTo1DExp
reduction to 1 dimension tensor input: Tensor<Device,k>: ishape output: Tensor<Device,...
Definition: reduceto1d.h:41
mshadow::expr::Exp
defines how expression exp can be evaluated and stored into dst
Definition: expression.h:79
mshadow::Tensor< Device, 1, DType >
Definition: tensor.h:673
mshadow
overloaded + operator between half_t and bf16_t
Definition: base.h:319
mshadow::expr::ExpComplexEngine< SV, Tensor< Device, 1, DType >, ReduceTo1DExp< SrcExp, DType, Reducer, 1 >, DType >::Eval
static void Eval(Tensor< Device, 1, DType > *dst, const ReduceTo1DExp< SrcExp, DType, Reducer, 1 > &exp)
Definition: reduceto1d.h:115
mshadow::expr::sumall_except_dim
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:62
mshadow::expr::ExpComplexEngine< SV, Tensor< Device, 1, DType >, ReduceTo1DExp< SrcExp, DType, Reducer, m_dimkeep >, DType >::Eval
static void Eval(Tensor< Device, 1, DType > *dst, const ReduceTo1DExp< SrcExp, DType, Reducer, m_dimkeep > &exp)
Definition: reduceto1d.h:102
mshadow::expr::sum_rows
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:90