You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2020/03/17 06:48:23 UTC

[GitHub] [incubator-mxnet] AntiZpvoh opened a new pull request #17854: [Numpy] FFI: random.choice, take and clip

AntiZpvoh opened a new pull request #17854: [Numpy] FFI: random.choice, take and clip
URL: https://github.com/apache/incubator-mxnet/pull/17854
 
 
   ## Description ##
   Add FFI support of 
   
   - random.choice
   
   - take
   
   - clip
   
     | Old FFI (ctypes) (us) | New FFI (cython) (us)
   -- | -- | --
   random.choice | 70.73 | 23.31
   take | 61.6 | 29.95
   clip | 31.95 | 11.44
   
   
   
   ## Checklist ##
   ### Essentials ###
   Please feel free to remove inapplicable items for your PR.
   - [ ] The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to the relevant [JIRA issue](https://issues.apache.org/jira/projects/MXNET/issues) created (except PRs with tiny changes)
   - [ ] Changes are complete (i.e. I finished coding on this PR)
   - [ ] All changes have test coverage:
   - Unit tests are added for small changes to verify correctness (e.g. adding a new operator)
   - Nightly tests are added for complicated/long-running ones (e.g. changing distributed kvstore)
   - Build tests will be added for build configuration changes (e.g. adding a new build option with NCCL)
   - [ ] Code is well-documented: 
   - For user-facing API changes, API doc string has been updated. 
   - For new C++ functions in header files, their functionalities and arguments are documented. 
   - For new examples, README.md is added to explain the what the example does, the source of the dataset, expected performance on test set and reference to the original paper if applicable
   - Check the API doc at https://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
   - [ ] To the best of my knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change
   
   ### Changes ###
   - [ ] Feature1, tests, (and when applicable, API doc)
   - [ ] Feature2, tests, (and when applicable, API doc)
   
   ## Comments ##
   - If this change is a backward incompatible change, why must this change be made.
   - Interesting edge cases to note here
   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #17854: [Numpy] FFI: random.choice, take and clip

Posted by GitBox <gi...@apache.org>.
haojin2 commented on a change in pull request #17854: [Numpy] FFI: random.choice, take and clip
URL: https://github.com/apache/incubator-mxnet/pull/17854#discussion_r393503275
 
 

 ##########
 File path: src/operator/numpy/random/np_choice_op.h
 ##########
 @@ -53,6 +53,19 @@ struct NumpyChoiceParam : public dmlc::Parameter<NumpyChoiceParam> {
     DMLC_DECLARE_FIELD(replace).set_default(true);
     DMLC_DECLARE_FIELD(weighted).set_default(false);
   }
+  void SetAttrDict(std::unordered_map<std::string, std::string>* dict) {
+    std::ostringstream a_s, size_s, replace_s, weighted_s;
+    a_s << a;
+    size_s << size;
+    replace_s << replace;
+    weighted_s << weighted;
+    (*dict)["a"] = a_s.str();
+    (*dict)["size"] = size_s.str();
+    (*dict)["replace"] = replace_s.str();
+    (*dict)["weighted"] = weighted_s.str();
+    // We do not set ctx, because ctx has been set in dict instead of InitOpParam.
 
 Review comment:
   get rid of this comment, looks like it does not apply to this op.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] haojin2 merged pull request #17854: [Numpy] FFI: random.choice, take and clip

Posted by GitBox <gi...@apache.org>.
haojin2 merged pull request #17854: [Numpy] FFI: random.choice, take and clip
URL: https://github.com/apache/incubator-mxnet/pull/17854
 
 
   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] AntiZpvoh commented on issue #17854: [Numpy] FFI: random.choice, take and clip

Posted by GitBox <gi...@apache.org>.
AntiZpvoh commented on issue #17854: [Numpy] FFI: random.choice, take and clip
URL: https://github.com/apache/incubator-mxnet/pull/17854#issuecomment-605806042
 
 
   @mxnet-bot run ci [centos-cpu, unix-gpu]

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] hzfan commented on a change in pull request #17854: [Numpy] FFI: random.choice, take and clip

Posted by GitBox <gi...@apache.org>.
hzfan commented on a change in pull request #17854: [Numpy] FFI: random.choice, take and clip
URL: https://github.com/apache/incubator-mxnet/pull/17854#discussion_r394778954
 
 

 ##########
 File path: src/api/operator/tensor/indexing_op.cc
 ##########
 @@ -0,0 +1,78 @@
+/*
+ * 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 indexing_op.cc
+ * \brief Implementation of the API of functions in src/operator/tensor/indexing_op.cc
+ */
+#include <mxnet/api_registry.h>
+#include <mxnet/runtime/packed_func.h>
+#include "../utils.h"
+#include "../../../operator/tensor/indexing_op.h"
+
+namespace mxnet {
+
+MXNET_REGISTER_API("_npi.take")
+.set_body([](runtime::MXNetArgs args, runtime::MXNetRetValue* ret) {
+  using namespace runtime;
+  const nnvm::Op* op = Op::Get("_npi_take");
+  nnvm::NodeAttrs attrs;
+  op::TakeParam param;
+  NDArray** inputs = new NDArray*[2]();
 
 Review comment:
   Please avoid new here. Use `NDArray* inputs[2]`.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] hzfan commented on a change in pull request #17854: [Numpy] FFI: random.choice, take and clip

Posted by GitBox <gi...@apache.org>.
hzfan commented on a change in pull request #17854: [Numpy] FFI: random.choice, take and clip
URL: https://github.com/apache/incubator-mxnet/pull/17854#discussion_r394790380
 
 

 ##########
 File path: src/api/operator/numpy/random/np_choice_op.cc
 ##########
 @@ -0,0 +1,91 @@
+/*
+ * 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 np_choice_op.cc
+ * \brief Implementation of the API of functions in src/operator/numpy/np_choice_op.cc
+ */
+#include <mxnet/api_registry.h>
+#include <mxnet/runtime/packed_func.h>
+#include <algorithm>
+#include "../../utils.h"
+#include "../../../../operator/numpy/random/np_choice_op.h"
+
+namespace mxnet {
+
+MXNET_REGISTER_API("_npi.choice")
+.set_body([](runtime::MXNetArgs args, runtime::MXNetRetValue* ret) {
+  using namespace runtime;
+  const nnvm::Op* op = Op::Get("_npi_choice");
+  nnvm::NodeAttrs attrs;
+  op::NumpyChoiceParam param;
+
+  NDArray** in = new NDArray*[2];
 
 Review comment:
   Same, please avoid new

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] mxnet-bot commented on issue #17854: [Numpy] FFI: random.choice, take and clip

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on issue #17854: [Numpy] FFI: random.choice, take and clip
URL: https://github.com/apache/incubator-mxnet/pull/17854#issuecomment-612920993
 
 
   Jenkins CI successfully triggered : [unix-gpu]

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] AntiZpvoh commented on issue #17854: [Numpy] FFI: random.choice, take and clip

Posted by GitBox <gi...@apache.org>.
AntiZpvoh commented on issue #17854: [Numpy] FFI: random.choice, take and clip
URL: https://github.com/apache/incubator-mxnet/pull/17854#issuecomment-605805689
 
 
   @mxnet-bot run ci [ci/jenkins/mxnet-validation/centos-cpu, ci/jenkins/mxnet-validation/unix-gpu]

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] haojin2 commented on issue #17854: [Numpy] FFI: random.choice, take and clip

Posted by GitBox <gi...@apache.org>.
haojin2 commented on issue #17854: [Numpy] FFI: random.choice, take and clip
URL: https://github.com/apache/incubator-mxnet/pull/17854#issuecomment-599935219
 
 
   please also fix the sanity issues.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] mxnet-bot commented on issue #17854: [Numpy] FFI: random.choice, take and clip

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on issue #17854: [Numpy] FFI: random.choice, take and clip
URL: https://github.com/apache/incubator-mxnet/pull/17854#issuecomment-605805732
 
 
   None of the jobs entered are supported. 
   Jobs entered by user: [ci/jenkins/mxnet-validation/centos-cpu, ci/jenkins/mxnet-validation/unix-gpu]
   CI supported Jobs: [centos-cpu, windows-gpu, unix-gpu, edge, windows-cpu, sanity, clang, centos-gpu, website, miscellaneous, unix-cpu]
   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] AntiZpvoh removed a comment on issue #17854: [Numpy] FFI: random.choice, take and clip

Posted by GitBox <gi...@apache.org>.
AntiZpvoh removed a comment on issue #17854: [Numpy] FFI: random.choice, take and clip
URL: https://github.com/apache/incubator-mxnet/pull/17854#issuecomment-605805689
 
 
   @mxnet-bot run ci [ci/jenkins/mxnet-validation/centos-cpu, ci/jenkins/mxnet-validation/unix-gpu]

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] hzfan commented on a change in pull request #17854: [Numpy] FFI: random.choice, take and clip

Posted by GitBox <gi...@apache.org>.
hzfan commented on a change in pull request #17854: [Numpy] FFI: random.choice, take and clip
URL: https://github.com/apache/incubator-mxnet/pull/17854#discussion_r394778051
 
 

 ##########
 File path: python/mxnet/ndarray/numpy/_op.py
 ##########
 @@ -680,13 +680,20 @@ def take(a, indices, axis=None, mode='raise', out=None):
     array([[4., 3.],
            [5., 7.]])
     """
+    # if mode not in ('wrap', 'clip', 'raise'):
+    #     raise NotImplementedError(
+    #         "function take does not support mode '{}'".format(mode))
+    # if axis is None:
+    #     return _npi.take(_npi.reshape(a, -1), indices, 0, mode, out)
+    # else:
+    #     return _npi.take(a, indices, axis, mode, out)
 
 Review comment:
   Please remove dead code.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] AntiZpvoh commented on issue #17854: [Numpy] FFI: random.choice, take and clip

Posted by GitBox <gi...@apache.org>.
AntiZpvoh commented on issue #17854: [Numpy] FFI: random.choice, take and clip
URL: https://github.com/apache/incubator-mxnet/pull/17854#issuecomment-612920949
 
 
   @mxnet-bot run ci [unix-gpu]

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] hzfan commented on a change in pull request #17854: [Numpy] FFI: random.choice, take and clip

Posted by GitBox <gi...@apache.org>.
hzfan commented on a change in pull request #17854: [Numpy] FFI: random.choice, take and clip
URL: https://github.com/apache/incubator-mxnet/pull/17854#discussion_r394779496
 
 

 ##########
 File path: src/api/operator/tensor/matrix_op.cc
 ##########
 @@ -0,0 +1,71 @@
+/*
+ * 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 matrix_op.cc
+ * \brief Implementation of the API of functions in src/operator/tensor/matrix_op.cc
+ */
+#include <mxnet/api_registry.h>
+#include <mxnet/runtime/packed_func.h>
+#include "../utils.h"
+#include "../../../operator/tensor/matrix_op-inl.h"
+
+namespace mxnet {
+
+MXNET_REGISTER_API("_npi.clip")
+.set_body([](runtime::MXNetArgs args, runtime::MXNetRetValue* ret) {
+  using namespace runtime;
+  const nnvm::Op* op = Op::Get("_npi_clip");
+  nnvm::NodeAttrs attrs;
+  op::ClipParam param;
+  NDArray** inputs = new NDArray*[1]();
 
 Review comment:
   Same, please avoid new. Use `NDArray* inputs[1]`.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] mxnet-bot commented on issue #17854: [Numpy] FFI: random.choice, take and clip

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on issue #17854: [Numpy] FFI: random.choice, take and clip
URL: https://github.com/apache/incubator-mxnet/pull/17854#issuecomment-605806075
 
 
   Jenkins CI successfully triggered : [unix-gpu, centos-cpu]

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services