apeforest commented on a change in pull request #14613: [MXNET-978] Higher 
order gradient support for some unary operators
URL: https://github.com/apache/incubator-mxnet/pull/14613#discussion_r290914583
 
 

 ##########
 File path: tests/python/unittest/test_higher_order_grad.py
 ##########
 @@ -15,13 +15,55 @@
 # specific language governing permissions and limitations
 # under the License.
 
-import math
 
+import math
 from mxnet import nd, autograd
-from mxnet.test_utils import assert_almost_equal, random_arrays
+from mxnet.test_utils import assert_almost_equal, random_arrays, rand_shape_nd
 from common import with_seed
 
 
+@with_seed()
+def test_sin():
+    def sin(x):
+        return nd.sin(x)
+
+    def grad_grad_op(x):
+        return -nd.sin(x)
+
+    for dim in range(1, 5):
+        shape = rand_shape_nd(dim)
+        array = random_arrays(shape)
+        check_second_order_unary(array, sin, grad_grad_op)
+
+
+@with_seed()
+def test_cos():
+    def cos(x):
+        return nd.cos(x)
+
+    def grad_grad_op(x):
+        return -nd.cos(x)
+
+    for dim in range(1, 5):
+        shape = rand_shape_nd(dim)
+        array = random_arrays(shape)
+        check_second_order_unary(array, cos, grad_grad_op)
 
 Review comment:
   This PR is only to support second order gradient. I can add a test later.

----------------------------------------------------------------
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