zheng-da commented on a change in pull request #8302: Refactor operators
URL: https://github.com/apache/incubator-mxnet/pull/8302#discussion_r150124188
 
 

 ##########
 File path: src/operator/nn/activation-inl.h
 ##########
 @@ -0,0 +1,172 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * \file activation-inl.h
+ * \brief Activation operator
+ * \author Bing Xu, Da Zheng
+*/
+#ifndef MXNET_OPERATOR_NN_ACTIVATION_INL_H_
+#define MXNET_OPERATOR_NN_ACTIVATION_INL_H_
+
+#include <dmlc/logging.h>
+#include <dmlc/parameter.h>
+#include <mxnet/operator.h>
+#include <cstring>
+#include <map>
+#include <string>
+#include <vector>
+#include <utility>
+#include "../operator_common.h"
+#include "../mshadow_op.h"
+
+namespace mxnet {
+namespace op {
+// Declare enumeration of input order to make code more intuitive.
+// // These enums are only visible within this header
+namespace activation {
+enum ActivationOpInputs {kData};
+enum ActivationOpOutputs {kOut};
+enum ActivationOpType {kReLU, kSigmoid, kTanh, kSoftReLU};
+}  // activation
+
+struct ActivationParam : public dmlc::Parameter<ActivationParam> {
+  // use int for enumeration
+  int act_type;
+  DMLC_DECLARE_PARAMETER(ActivationParam) {
+    DMLC_DECLARE_FIELD(act_type)
+    .add_enum("relu", activation::kReLU)
+    .add_enum("sigmoid", activation::kSigmoid)
+    .add_enum("tanh", activation::kTanh)
+    .add_enum("softrelu", activation::kSoftReLU)
+    .describe("Activation function to be applied.");
+  }
+};
+
+/**
+ * \brief This is the implementation of activation operator.
+ * \tparam xpu The device that the op will be executed on.
+ */
+template<typename xpu, typename ForwardOp, typename BackwardOp, typename DType>
+class ActivationOp {
+ public:
+  virtual void Forward(const OpContext &ctx, const TBlob &in_data,
+                       const OpReqType &req, const TBlob &out_data) {
+    using namespace mshadow;
+    using namespace mshadow::expr;
+    Stream<xpu> *s = ctx.get_stream<xpu>();
+    Tensor<xpu, 2, DType> data = in_data.FlatTo2D<xpu, DType>(s);
+    Tensor<xpu, 2, DType> out = out_data.FlatTo2D<xpu, DType>(s);
+    Assign(out, req, F<ForwardOp>(data));
 
 Review comment:
   I'll rebase the code to the new master branch

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to