[GitHub] [incubator-mxnet] xiezhq-hermann commented on a change in pull request #15906: [Numpy] Numpy operator diff

2019-09-11 Thread GitBox
xiezhq-hermann commented on a change in pull request #15906: [Numpy] Numpy 
operator diff
URL: https://github.com/apache/incubator-mxnet/pull/15906#discussion_r323559384
 
 

 ##
 File path: tests/python/unittest/test_numpy_op.py
 ##
 @@ -1519,6 +1519,58 @@ def hybrid_forward(self, F, a):
 assert_almost_equal(mx_out.asnumpy(), np_out, 
rtol=1e-3, atol=1e-5)
 
 
+@with_seed()
+@use_np
+def test_np_diff():
+def np_diff_backward(ograd, n, axis):
+res = ograd
+for i in range(n):
+res = _np.negative(_np.diff(res, n=1, axis=axis, prepend=0, 
append=0))
+return res
+
+class TestDiff(HybridBlock):
+def __init__(self, n=1, axis=-1):
+super(TestDiff, self).__init__()
+self._n = n
+self._axis = axis
+
+def hybrid_forward(self, F, a):
+return F.np.diff(a, n=self._n, axis=self._axis)
+
+shapes = [tuple(random.randrange(10) for i in range(random.randrange(6))) 
for j in range(5)]
 
 Review comment:
   I agreed your opinions and that's what I did before, but the present random 
cases generator should be concise and easy to understand. 
   The tests are switched to random cases mainly for the balance of time cost 
and test coverage, which is advised by @haojin2 , could you reach an agreement?


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


[GitHub] [incubator-mxnet] xiezhq-hermann commented on a change in pull request #15906: [Numpy] Numpy operator diff

2019-09-11 Thread GitBox
xiezhq-hermann commented on a change in pull request #15906: [Numpy] Numpy 
operator diff
URL: https://github.com/apache/incubator-mxnet/pull/15906#discussion_r323545625
 
 

 ##
 File path: tests/python/unittest/test_numpy_op.py
 ##
 @@ -1519,6 +1519,58 @@ def hybrid_forward(self, F, a):
 assert_almost_equal(mx_out.asnumpy(), np_out, 
rtol=1e-3, atol=1e-5)
 
 
+@with_seed()
+@use_np
+def test_np_diff():
+def np_diff_backward(ograd, n, axis):
+res = ograd
+for i in range(n):
+res = _np.negative(_np.diff(res, n=1, axis=axis, prepend=0, 
append=0))
+return res
+
+class TestDiff(HybridBlock):
+def __init__(self, n=1, axis=-1):
+super(TestDiff, self).__init__()
+self._n = n
+self._axis = axis
+
+def hybrid_forward(self, F, a):
+return F.np.diff(a, n=self._n, axis=self._axis)
+
+shapes = [tuple(random.randrange(10) for i in range(random.randrange(6))) 
for j in range(5)]
 
 Review comment:
   Hi, the random shape generator should have covered the corner cases, 
including zero dim, 1d to 5d input shape. Actually, the codes have been tested 
by static shapes and the random generator here is for shorter testing time.
   Do you think it's necessary to change back still? If yes, I'll do it.


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


[GitHub] [incubator-mxnet] xiezhq-hermann commented on a change in pull request #15906: [Numpy] Numpy operator diff

2019-08-26 Thread GitBox
xiezhq-hermann commented on a change in pull request #15906: [Numpy] Numpy 
operator diff
URL: https://github.com/apache/incubator-mxnet/pull/15906#discussion_r317920191
 
 

 ##
 File path: src/operator/numpy/np_diff-inl.h
 ##
 @@ -0,0 +1,215 @@
+/*
+ * 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_diff-inl.h
+ * \brief Function definition of numpy-compatible diff operator
+ */
+
+#ifndef MXNET_OPERATOR_NUMPY_NP_DIFF_INL_H_
+#define MXNET_OPERATOR_NUMPY_NP_DIFF_INL_H_
+
+#include 
+#include 
+#include 
+#include "../mxnet_op.h"
+#include "../operator_common.h"
+#include "../tensor/broadcast_reduce_op.h"
+
+namespace mxnet {
+namespace op {
+
+struct DiffParam : public dmlc::Parameter {
+  int n, axis;
+  dmlc::optional prepend;
+  dmlc::optional append;
+  DMLC_DECLARE_PARAMETER(DiffParam) {
+DMLC_DECLARE_FIELD(n).set_default(1).describe(
+"The number of times values are differenced."
+" If zero, the input is returned as-is.");
+DMLC_DECLARE_FIELD(axis).set_default(-1).describe(
+"Axis along which the cumulative sum is computed."
+" The default (None) is to compute the diff over the flattened 
array.");
+  }
+};
+
+inline void YanghuiTri(std::vector* buffer, int n) {
 
 Review comment:
   The `inline` is finally kept since the function here is really concise and 
no need to be put in .cc


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