mxnet
mirror.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_MIRROR_H_
26 #define MSHADOW_EXTENSION_MIRROR_H_
27 #include "../extension.h"
28 namespace mshadow {
29 namespace expr {
36 template<typename SrcExp, typename DType, int srcdim>
37 struct MirroringExp:
38  public MakeTensorExp<MirroringExp<SrcExp, DType, srcdim>,
39  SrcExp, srcdim, DType> {
41  const SrcExp &src_;
43  explicit MirroringExp(const SrcExp &src) : src_(src) {
45  }
46 };
55 template<typename SrcExp, typename DType, int etype>
56 inline MirroringExp<SrcExp, DType, ExpInfo<SrcExp>::kDim>
59  ::Error_Expression_Does_Not_Meet_Dimension_Req();
61 }
62 //----------------------
63 // Execution plan
64 //----------------------
65 template<typename SrcExp, typename DType, int srcdim>
66 struct Plan<MirroringExp<SrcExp, DType, srcdim>, DType> {
67  public:
69  : src_(MakePlan(e.src_)), width_(e.shape_[srcdim - 1]) {}
70  MSHADOW_XINLINE DType Eval(index_t i, index_t j) const {
71  return src_.Eval(i, width_ - j - 1);
72  }
73 
74  private:
76  const index_t width_;
77 };
78 } // namespace expr
79 } // namespace mshadow
80 #endif // MSHADOW_EXTENSION_MIRROR_H_
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::MirroringExp::MirroringExp
MirroringExp(const SrcExp &src)
constructor
Definition: mirror.h:43
mshadow::expr::Plan< MirroringExp< SrcExp, DType, srcdim >, DType >::Eval
MSHADOW_XINLINE DType Eval(index_t i, index_t j) const
Definition: mirror.h:70
MSHADOW_XINLINE
#define MSHADOW_XINLINE
Definition: base.h:228
mshadow::expr::ShapeCheck::Check
static Shape< dim > Check(const E &t)
mshadow::expr::MakePlan
Plan< BinaryMapExp< OP, TA, TB, DType, etype >, DType > MakePlan(const BinaryMapExp< OP, TA, TB, DType, etype > &e)
Definition: expr_engine-inl.h:239
mshadow::expr::MakeTensorExp< MirroringExp< SrcExp, DType, srcdim >, SrcExp, srcdim, DType >::shape_
Shape< dim > shape_
the shape of this expression
Definition: expr_engine-inl.h:47
mshadow::expr::mirror
MirroringExp< SrcExp, DType, ExpInfo< SrcExp >::kDim > mirror(const Exp< SrcExp, DType, etype > &src)
mirroring expression, mirror images in width
Definition: mirror.h:57
mshadow::index_t
int32_t index_t
type that will be used for index
Definition: base.h:328
mshadow::expr::Plan
Definition: expr_engine-inl.h:58
mshadow::expr::MirroringExp
mirror expression, mirror a image in width
Definition: mirror.h:37
mshadow::expr::Exp
defines how expression exp can be evaluated and stored into dst
Definition: expression.h:79
mshadow
overloaded + operator between half_t and bf16_t
Definition: base.h:319
mshadow::expr::MakeTensorExp
a general class that allows extension that makes tensors of some shape
Definition: expr_engine-inl.h:43
mshadow::expr::MirroringExp::src_
const SrcExp & src_
source operand
Definition: mirror.h:41
mshadow::expr::Plan< MirroringExp< SrcExp, DType, srcdim >, DType >::Plan
Plan(const MirroringExp< SrcExp, DType, srcdim > &e)
Definition: mirror.h:68