haojin2 commented on a change in pull request #17328: [numpy] add op pad
URL: https://github.com/apache/incubator-mxnet/pull/17328#discussion_r367146521
 
 

 ##########
 File path: src/operator/numpy/np_pad_op-inl.h
 ##########
 @@ -0,0 +1,735 @@
+/*
+ * 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.
+ */
+
+/*!
+ *  Copyright (c) 2019 by Contributors
+ * \file np_pad_op-inl.h
+ * \brief Function definition of matrix related operators
+ */
+#ifndef MXNET_OPERATOR_NUMPY_NP_PAD_OP_INL_H_
+#define MXNET_OPERATOR_NUMPY_NP_PAD_OP_INL_H_
+
+#include <vector>
+#include <algorithm>
+#include <string>
+#include <utility>
+#include "../tensor/matrix_op-inl.h"
+#include "../nn/concat-inl.h"
+#include "../../common/utils.h"
+#include "../mxnet_op.h"
+#include "../operator_common.h"
+#include "../elemwise_op_common.h"
+#include "../tensor/broadcast_reduce_op.h"
+
+namespace mxnet {
+namespace op {
+
+template <size_t ndim, typename xpu>
+MSHADOW_XINLINE index_t rravel(const mshadow::Shape<ndim>& coord,
+                               const mshadow::Tensor<xpu, 1, index_t>& shape) {
+  index_t ret = 0;
+  #pragma unroll
+  for (int i = 0; i < ndim; ++i) {
+    ret = ret * shape[i] + (shape[i] > coord[i]) * coord[i];
+  }
+  return ret;
+}
+
+template<size_t ndim, typename xpu>
+MSHADOW_XINLINE mshadow::Shape<ndim> uunravel(index_t idx,
+                                              const mshadow::Tensor<xpu, 1, 
index_t>& shape) {
+  mshadow::Shape<ndim> ret;
+  #pragma unroll
+  for (index_t i = ndim-1, j = idx; i >=0; --i) {
+    auto tmp = j / shape[i];
+    ret[i] = j - tmp*shape[i];
+    j = tmp;
+  }
+  return ret;
+}
+
+struct NumpyPadParam : public dmlc::Parameter<NumpyPadParam> {
+  mxnet::Tuple<Tuple<int>> pad_width;
+  int mode;
+  std::string reflect_type;
+  double constant_value;
+  DMLC_DECLARE_PARAMETER(NumpyPadParam) {
+    DMLC_DECLARE_FIELD(pad_width)
+        .describe("Number of values padded to the edges of each axis. "
+                  "((before_1, after_1), … (before_N,"
+                  "after_N)) unique pad widths for each axis. ((before, 
after),) "
+                  "yields same before and"
+                  "after pad for each axis. "
+                  "(pad,) or int is a shortcut for before = after = pad width 
for all"
+                  "axes.");
+    DMLC_DECLARE_FIELD(mode)
+        .set_default(1)
+        .describe("str or function, optional");
+    DMLC_DECLARE_FIELD(reflect_type)
+        .set_default("even")
 
 Review comment:
   2-space indentation.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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