mxnet
op_suppl.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 
27 #ifndef MXNET_CPP_OP_SUPPL_H_
28 #define MXNET_CPP_OP_SUPPL_H_
29 
30 #include <cassert>
31 #include <string>
32 #include <vector>
33 #include "mxnet-cpp/base.h"
34 #include "mxnet-cpp/shape.h"
35 #include "mxnet-cpp/operator.h"
36 #include "mxnet-cpp/MxNetCpp.h"
37 
38 namespace mxnet {
39 namespace cpp {
40 
41 inline Symbol _Plus(Symbol lhs, Symbol rhs) {
42  return Operator("_Plus")(lhs, rhs)
43  .CreateSymbol();
44 }
45 inline Symbol _Mul(Symbol lhs, Symbol rhs) {
46  return Operator("_Mul")(lhs, rhs)
47  .CreateSymbol();
48 }
49 inline Symbol _Minus(Symbol lhs, Symbol rhs) {
50  return Operator("_Minus")(lhs, rhs)
51  .CreateSymbol();
52 }
53 inline Symbol _Div(Symbol lhs, Symbol rhs) {
54  return Operator("_Div")(lhs, rhs)
55  .CreateSymbol();
56 }
57 inline Symbol _Mod(Symbol lhs, Symbol rhs) {
58  return Operator("_Mod")(lhs, rhs)
59  .CreateSymbol();
60 }
61 inline Symbol _Power(Symbol lhs, Symbol rhs) {
62  return Operator("_Power")(lhs, rhs)
63  .CreateSymbol();
64 }
65 inline Symbol _Maximum(Symbol lhs, Symbol rhs) {
66  return Operator("_Maximum")(lhs, rhs)
67  .CreateSymbol();
68 }
69 inline Symbol _Minimum(Symbol lhs, Symbol rhs) {
70  return Operator("_Minimum")(lhs, rhs)
71  .CreateSymbol();
72 }
73 inline Symbol _PlusScalar(Symbol lhs, mx_float scalar) {
74  return Operator("_PlusScalar")(lhs)
75  .SetParam("scalar", scalar)
76  .CreateSymbol();
77 }
78 inline Symbol _MinusScalar(Symbol lhs, mx_float scalar) {
79  return Operator("_MinusScalar")(lhs)
80  .SetParam("scalar", scalar)
81  .CreateSymbol();
82 }
83 inline Symbol _RMinusScalar(mx_float scalar, Symbol rhs) {
84  return Operator("_RMinusScalar")(rhs)
85  .SetParam("scalar", scalar)
86  .CreateSymbol();
87 }
88 inline Symbol _MulScalar(Symbol lhs, mx_float scalar) {
89  return Operator("_MulScalar")(lhs)
90  .SetParam("scalar", scalar)
91  .CreateSymbol();
92 }
93 inline Symbol _DivScalar(Symbol lhs, mx_float scalar) {
94  return Operator("_DivScalar")(lhs)
95  .SetParam("scalar", scalar)
96  .CreateSymbol();
97 }
98 inline Symbol _RDivScalar(mx_float scalar, Symbol rhs) {
99  return Operator("_RDivScalar")(rhs)
100  .SetParam("scalar", scalar)
101  .CreateSymbol();
102 }
103 inline Symbol _ModScalar(Symbol lhs, mx_float scalar) {
104  return Operator("_ModScalar")(lhs)
105  .SetParam("scalar", scalar)
106  .CreateSymbol();
107 }
108 inline Symbol _RModScalar(mx_float scalar, Symbol rhs) {
109  return Operator("_RModScalar")(rhs)
110  .SetParam("scalar", scalar)
111  .CreateSymbol();
112 }
113 inline Symbol _PowerScalar(Symbol lhs, mx_float scalar) {
114  return Operator("_PowerScalar")(lhs)
115  .SetParam("scalar", scalar)
116  .CreateSymbol();
117 }
118 inline Symbol _RPowerScalar(mx_float scalar, Symbol rhs) {
119  return Operator("_RPowerScalar")(rhs)
120  .SetParam("scalar", scalar)
121  .CreateSymbol();
122 }
123 inline Symbol _MaximumScalar(Symbol lhs, mx_float scalar) {
124  return Operator("_MaximumScalar")(lhs)
125  .SetParam("scalar", scalar)
126  .CreateSymbol();
127 }
128 inline Symbol _MinimumScalar(Symbol lhs, mx_float scalar) {
129  return Operator("_MinimumScalar")(lhs)
130  .SetParam("scalar", scalar)
131  .CreateSymbol();
132 }
133 // TODO(zhangcheng-qinyinghua)
134 // make crop function run in op.h
135 // This function is due to [zhubuntu](https://github.com/zhubuntu)
136 inline Symbol Crop(const std::string& symbol_name,
137  int num_args,
138  Symbol data,
139  Symbol crop_like,
140  Shape offset = Shape(0, 0),
141  Shape h_w = Shape(0, 0),
142  bool center_crop = false) {
143  return Operator("Crop")
144  .SetParam("num_args", num_args)
145  .SetParam("offset", offset)
146  .SetParam("h_w", h_w)
147  .SetParam("center_crop", center_crop)
148  .SetInput("arg0", data)
149  .SetInput("arg1", crop_like)
150  .CreateSymbol(symbol_name);
151 }
152 
153 
163 inline Symbol Activation(const std::string& symbol_name,
164  Symbol data,
165  const std::string& act_type) {
166  assert(act_type == "relu" ||
167  act_type == "sigmoid" ||
168  act_type == "softrelu" ||
169  act_type == "tanh");
170  return Operator("Activation")
171  .SetParam("act_type", act_type.c_str())
172  .SetInput("data", data)
173  .CreateSymbol(symbol_name);
174 }
175 
176 } // namespace cpp
177 } // namespace mxnet
178 
179 #endif // MXNET_CPP_OP_SUPPL_H_
180 
Symbol Crop(const std::string &symbol_name, const std::vector< Symbol > &data, int num_args, Shape offset=Shape(0, 0), Shape h_w=Shape(0, 0), bool center_crop=false)
Definition: op.h:7153
Symbol _MulScalar(Symbol lhs, mx_float scalar)
Definition: op_suppl.h:88
namespace of mxnet
Definition: base.h:118
Operator & SetInput(const std::string &name, Symbol symbol)
add an input symbol
Symbol _MaximumScalar(Symbol lhs, mx_float scalar)
Definition: op_suppl.h:123
dynamic shape class that can hold shape of arbirary dimension
Definition: shape.h:43
Symbol _RPowerScalar(mx_float scalar, Symbol rhs)
Definition: op_suppl.h:118
Symbol _ModScalar(Symbol lhs, mx_float scalar)
Definition: op_suppl.h:103
Symbol _MinimumScalar(Symbol lhs, mx_float scalar)
Definition: op_suppl.h:128
Symbol _Maximum(Symbol lhs, Symbol rhs)
Definition: op_suppl.h:65
meta include file for mxnet.cpp
Symbol _DivScalar(Symbol lhs, mx_float scalar)
Definition: op_suppl.h:93
Symbol _RModScalar(mx_float scalar, Symbol rhs)
Definition: op_suppl.h:108
Symbol _Div(Symbol lhs, Symbol rhs)
Definition: op_suppl.h:53
Symbol _PowerScalar(Symbol lhs, mx_float scalar)
Definition: op_suppl.h:113
Symbol _Minus(Symbol lhs, Symbol rhs)
Definition: op_suppl.h:49
Symbol _Minimum(Symbol lhs, Symbol rhs)
Definition: op_suppl.h:69
Symbol _Mul(Symbol lhs, Symbol rhs)
Definition: op_suppl.h:45
Symbol _MinusScalar(Symbol lhs, mx_float scalar)
Definition: op_suppl.h:78
Symbol CreateSymbol(const std::string &name="")
create a Symbol from the current operator
Symbol _RMinusScalar(mx_float scalar, Symbol rhs)
Definition: op_suppl.h:83
Operator & SetParam(const std::string &name, const T &value)
set config parameters
Definition: operator.h:58
Symbol _Mod(Symbol lhs, Symbol rhs)
Definition: op_suppl.h:57
Symbol _PlusScalar(Symbol lhs, mx_float scalar)
Definition: op_suppl.h:73
Symbol _Power(Symbol lhs, Symbol rhs)
Definition: op_suppl.h:61
Symbol Activation(const std::string &symbol_name, Symbol data, ActivationActType act_type)
Definition: op.h:4815
float mx_float
manually define float
Definition: c_api.h:60
definition of shape
Symbol _RDivScalar(mx_float scalar, Symbol rhs)
Definition: op_suppl.h:98
Symbol _Plus(Symbol lhs, Symbol rhs)
Definition: op_suppl.h:41
Operator interface.
Definition: operator.h:43
Symbol interface.
Definition: symbol.h:72