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 
26 #ifndef MXNET_CPP_OP_SUPPL_H_
27 #define MXNET_CPP_OP_SUPPL_H_
28 
29 #include <cassert>
30 #include <string>
31 #include <vector>
32 #include "mxnet-cpp/base.h"
33 #include "mxnet-cpp/shape.h"
34 #include "mxnet-cpp/operator.h"
35 #include "mxnet-cpp/MxNetCpp.h"
36 
37 namespace mxnet {
38 namespace cpp {
39 
40 inline Symbol _Plus(Symbol lhs, Symbol rhs) {
41  return Operator("_Plus")(lhs, rhs).CreateSymbol();
42 }
43 inline Symbol _Mul(Symbol lhs, Symbol rhs) {
44  return Operator("_Mul")(lhs, rhs).CreateSymbol();
45 }
46 inline Symbol _Minus(Symbol lhs, Symbol rhs) {
47  return Operator("_Minus")(lhs, rhs).CreateSymbol();
48 }
49 inline Symbol _Div(Symbol lhs, Symbol rhs) {
50  return Operator("_Div")(lhs, rhs).CreateSymbol();
51 }
52 inline Symbol _Mod(Symbol lhs, Symbol rhs) {
53  return Operator("_Mod")(lhs, rhs).CreateSymbol();
54 }
55 inline Symbol _Power(Symbol lhs, Symbol rhs) {
56  return Operator("_Power")(lhs, rhs).CreateSymbol();
57 }
58 inline Symbol _Maximum(Symbol lhs, Symbol rhs) {
59  return Operator("_Maximum")(lhs, rhs).CreateSymbol();
60 }
61 inline Symbol _Minimum(Symbol lhs, Symbol rhs) {
62  return Operator("_Minimum")(lhs, rhs).CreateSymbol();
63 }
65  return Operator("_PlusScalar")(lhs).SetParam("scalar", scalar).CreateSymbol();
66 }
68  return Operator("_MinusScalar")(lhs).SetParam("scalar", scalar).CreateSymbol();
69 }
71  return Operator("_RMinusScalar")(rhs).SetParam("scalar", scalar).CreateSymbol();
72 }
74  return Operator("_MulScalar")(lhs).SetParam("scalar", scalar).CreateSymbol();
75 }
77  return Operator("_DivScalar")(lhs).SetParam("scalar", scalar).CreateSymbol();
78 }
80  return Operator("_RDivScalar")(rhs).SetParam("scalar", scalar).CreateSymbol();
81 }
83  return Operator("_ModScalar")(lhs).SetParam("scalar", scalar).CreateSymbol();
84 }
86  return Operator("_RModScalar")(rhs).SetParam("scalar", scalar).CreateSymbol();
87 }
89  return Operator("_PowerScalar")(lhs).SetParam("scalar", scalar).CreateSymbol();
90 }
92  return Operator("_RPowerScalar")(rhs).SetParam("scalar", scalar).CreateSymbol();
93 }
95  return Operator("_MaximumScalar")(lhs).SetParam("scalar", scalar).CreateSymbol();
96 }
98  return Operator("_MinimumScalar")(lhs).SetParam("scalar", scalar).CreateSymbol();
99 }
100 // TODO(zhangcheng-qinyinghua)
101 // make crop function run in op.h
102 // This function is due to [zhubuntu](https://github.com/zhubuntu)
103 inline Symbol Crop(const std::string& symbol_name,
104  int num_args,
105  Symbol data,
106  Symbol crop_like,
107  Shape offset = Shape(0, 0),
108  Shape h_w = Shape(0, 0),
109  bool center_crop = false) {
110  return Operator("Crop")
111  .SetParam("num_args", num_args)
112  .SetParam("offset", offset)
113  .SetParam("h_w", h_w)
114  .SetParam("center_crop", center_crop)
115  .SetInput("arg0", data)
116  .SetInput("arg1", crop_like)
117  .CreateSymbol(symbol_name);
118 }
119 
129 inline Symbol Activation(const std::string& symbol_name, Symbol data, const std::string& act_type) {
130  assert(act_type == "relu" || act_type == "sigmoid" || act_type == "softrelu" ||
131  act_type == "tanh");
132  return Operator("Activation")
133  .SetParam("act_type", act_type.c_str())
134  .SetInput("data", data)
135  .CreateSymbol(symbol_name);
136 }
137 
138 } // namespace cpp
139 } // namespace mxnet
140 
141 #endif // MXNET_CPP_OP_SUPPL_H_
mxnet::cpp::_Minimum
Symbol _Minimum(Symbol lhs, Symbol rhs)
Definition: op_suppl.h:61
mxnet
namespace of mxnet
Definition: api_registry.h:33
shape.h
definition of shape
mxnet::cpp::_MinusScalar
Symbol _MinusScalar(Symbol lhs, mx_float scalar)
Definition: op_suppl.h:67
mxnet::cpp::Activation
Symbol Activation(const std::string &symbol_name, Symbol data, const std::string &act_type)
Apply activation function to input. Softmax Activation is only available with CUDNN on GPUand will be...
Definition: op_suppl.h:129
mxnet::cpp::Operator::SetInput
Operator & SetInput(const std::string &name, const Symbol &symbol)
add an input symbol
mxnet::cpp::_Minus
Symbol _Minus(Symbol lhs, Symbol rhs)
Definition: op_suppl.h:46
mxnet::cpp::_RMinusScalar
Symbol _RMinusScalar(mx_float scalar, Symbol rhs)
Definition: op_suppl.h:70
mshadow::expr::scalar
ScalarExp< DType > scalar(DType s)
create an scalar expression
Definition: expression.h:103
mxnet::cpp::_Mul
Symbol _Mul(Symbol lhs, Symbol rhs)
Definition: op_suppl.h:43
mxnet::cpp::_Power
Symbol _Power(Symbol lhs, Symbol rhs)
Definition: op_suppl.h:55
MxNetCpp.h
meta include file for mxnet.cpp
mxnet::cpp::_PlusScalar
Symbol _PlusScalar(Symbol lhs, mx_float scalar)
Definition: op_suppl.h:64
mxnet::cpp::_Mod
Symbol _Mod(Symbol lhs, Symbol rhs)
Definition: op_suppl.h:52
mxnet::cpp::Operator
Operator interface.
Definition: operator.h:42
mxnet::cpp::_RDivScalar
Symbol _RDivScalar(mx_float scalar, Symbol rhs)
Definition: op_suppl.h:79
mxnet::cpp::_Plus
Symbol _Plus(Symbol lhs, Symbol rhs)
Definition: op_suppl.h:40
mx_float
float mx_float
manually define float
Definition: c_api.h:67
mxnet::cpp::Operator::SetParam
Operator & SetParam(const std::string &name, const T &value)
set config parameters
Definition: operator.h:57
mxnet::cpp::_MulScalar
Symbol _MulScalar(Symbol lhs, mx_float scalar)
Definition: op_suppl.h:73
mxnet::cpp::Operator::CreateSymbol
Symbol CreateSymbol(const std::string &name="")
create a Symbol from the current operator
mxnet::cpp::_MaximumScalar
Symbol _MaximumScalar(Symbol lhs, mx_float scalar)
Definition: op_suppl.h:94
mxnet::cpp::Shape
dynamic shape class that can hold shape of arbirary dimension
Definition: shape.h:42
mxnet::cpp::Crop
Symbol Crop(const std::string &symbol_name, int num_args, Symbol data, Symbol crop_like, Shape offset=Shape(0, 0), Shape h_w=Shape(0, 0), bool center_crop=false)
Definition: op_suppl.h:103
mxnet::cpp::_ModScalar
Symbol _ModScalar(Symbol lhs, mx_float scalar)
Definition: op_suppl.h:82
mxnet::cpp::_RPowerScalar
Symbol _RPowerScalar(mx_float scalar, Symbol rhs)
Definition: op_suppl.h:91
mxnet::cpp::_DivScalar
Symbol _DivScalar(Symbol lhs, mx_float scalar)
Definition: op_suppl.h:76
mxnet::cpp::_RModScalar
Symbol _RModScalar(mx_float scalar, Symbol rhs)
Definition: op_suppl.h:85
operator.h
definition of io, such as DataIter
mxnet::cpp::_MinimumScalar
Symbol _MinimumScalar(Symbol lhs, mx_float scalar)
Definition: op_suppl.h:97
base.h
base definitions for mxnetcpp
mxnet::cpp::_Maximum
Symbol _Maximum(Symbol lhs, Symbol rhs)
Definition: op_suppl.h:58
mxnet::cpp::_Div
Symbol _Div(Symbol lhs, Symbol rhs)
Definition: op_suppl.h:49
mxnet::cpp::_PowerScalar
Symbol _PowerScalar(Symbol lhs, mx_float scalar)
Definition: op_suppl.h:88
mxnet::cpp::Symbol
Symbol interface.
Definition: symbol.h:73