anirudhacharya 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_r289501007
########## File path: tests/python/unittest/test_higher_order_grad.py ########## @@ -15,13 +15,52 @@ # 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 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) + + arrays = random_arrays((2, 2), (2, 3), (4, 5, 2), (3, 1, 4, 5)) + for array in arrays: + 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) + + arrays = random_arrays((2, 2), (2, 3), (4, 5, 2), (3, 1, 4, 5)) + for array in arrays: + check_second_order_unary(array, cos, grad_grad_op) + + +@with_seed() +def test_relu(): + def relu(x): + return nd.relu(x) + + def grad_grad_op(x): + return nd.zeros_like(x) + + arrays = random_arrays((2, 2), (2, 3), (4, 5, 2), (3, 1, 4, 5)) Review comment: shouldn't we test for 1-d arrays? not sure if it is needed here, but there is this to randomize the shape of an array - https://github.com/apache/incubator-mxnet/blob/master/python/mxnet/test_utils.py#L418 ---------------------------------------------------------------- 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
