anirudhacharya commented on a change in pull request #11229: [MXNET-379] L1 
Normalization
URL: https://github.com/apache/incubator-mxnet/pull/11229#discussion_r194531662
 
 

 ##########
 File path: tests/python/unittest/test_operator.py
 ##########
 @@ -2879,6 +2879,36 @@ def npy_layer_norm(data, gamma, beta, axis=1, eps=1E-5):
                                grad_nodes={'data': req, 'gamma': req, 'beta': 
req},
                                numeric_eps=1e-2, rtol=1e-2, atol=1e-2)
 
+@with_seed()
+def test_norml1():
+    def npy_l1norm(data, axis):
+        np.sum(abs(np_arr), axis=i, keepdims=True)
+    ctx = default_context()
+    data = mx.symbol.Variable('data')
+
+    for dtype in [np.float16, np.float32, np.float64]:
+        dtype = np.float32
+        in_data = np.random.uniform(-1, 1, (4,4,4,4)).astype(dtype)
+        for i in range(4):
+            for keep_dims in [True, False]:
+                norm_sym = mx.symbol.norm(data=data, ord=1, axis=i, 
keepdims=keep_dims)
+                exe = norm_sym.simple_bind(ctx, data=(4,4,4,4))
+                exe.arg_dict['data'][:] = in_data
+                npy_out = np.sum(abs(in_data), axis=i, keepdims=keep_dims)
+                out = exe.forward()[0]
+                assert_almost_equal(out, npy_out, rtol=1e-2, atol=1e-5)
+                # check gradient
+                check_numeric_gradient(out, [in_data], numeric_eps=1e-3, 
rtol=1e-2, atol=1e-3)
 
 Review comment:
   what should the values be for fp64 and fp32?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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

Reply via email to