haojin2 commented on a change in pull request #15902: Numpy add numpy op roll URL: https://github.com/apache/incubator-mxnet/pull/15902#discussion_r317276993
########## File path: src/operator/numpy/np_roll_op.cc ########## @@ -0,0 +1,103 @@ +/* + * 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_roll_op.cc + * \brief CPU Implementation of numpy rearranging elements operator + */ +#include "./np_roll_op.h" + +namespace mxnet { +namespace op { + +DMLC_REGISTER_PARAMETER(NumpyRollParam); + + +inline bool NumpyRollShape(const nnvm::NodeAttrs& attrs, + mxnet::ShapeVector *in_attrs, + mxnet::ShapeVector *out_attrs) { + using namespace mshadow; + const NumpyRollParam& param = nnvm::get<NumpyRollParam>(attrs.parsed); + + if (!param.shift.has_value()) { + LOG(FATAL) << "roll missing 1 required positional argument: 'shift'"; + } + if (param.shift.value().ndim() > 1 && + param.axis.has_value() && + param.axis.value().ndim() != param.shift.value().ndim()) { + LOG(FATAL) << "shift and `axis` must be a tuple of the same size,"; + } + if (!param.axis.has_value() && param.shift.has_value() && param.shift.value().ndim() > 1) { + LOG(FATAL) << "shift must be an int"; + } + if (param.axis.has_value()) { + mxnet::TShape axes(param.axis.value()); + const index_t ndim = (*in_attrs)[0].ndim(); + for (index_t i = 0; i < axes.ndim(); i++) { + if (axes[i] < 0) { + axes[i] += ndim; + } + } + std::sort(axes.begin(), axes.end()); + for (index_t i = 1; i < axes.ndim(); i++) { + CHECK_LT(axes[i - 1], axes[i]) + << "axes have duplicates " << axes; + } + CHECK_LT(axes[axes.ndim() - 1], ndim) + << "axis " << axes[axes.ndim() - 1] + << " Exceeds input dimensions " << (*in_attrs)[0]; + CHECK_GE(axes[0], 0) + << "Reduction axis " << param.axis.value() + << " Exceeds input dimensions " << (*in_attrs)[0]; + } + return ElemwiseShape<1, 1>(attrs, in_attrs, out_attrs); +} + + Review comment: 1-line gap between functions in c++ files. ---------------------------------------------------------------- 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: [email protected] With regards, Apache Git Services
