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