anirudhacharya commented on a change in pull request #11229: [MXNET-379] L1
Normalization
URL: https://github.com/apache/incubator-mxnet/pull/11229#discussion_r199027961
##########
File path: tests/python/unittest/test_operator.py
##########
@@ -3009,6 +3009,49 @@ 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_norm():
+ def l1norm(input_data, axis=0, keepdims=True):
+ return np.sum(abs(input_data), axis=axis, keepdims=keepdims)
+ def l2norm(input_data, axis=0, keepdims=True):
+ return np.linalg.norm(input_data, axis=axis, keepdims=keepdims)
+
+ ctx = default_context()
+ data = mx.symbol.Variable('data')
+ in_data_dim = random_sample([4,5,6], 1)[0]
+ in_shape = rand_shape_nd(in_data_dim)
+ for order in [1, 2]:
+ for dtype in [np.float16, np.float32, np.float64]:
+ in_data = np.random.uniform(-1, 1, in_shape).astype(dtype)
+ in_data[abs(in_data) < 1e-2] = 1e-2
+ for i in range(in_data_dim):
+ norm_sym = mx.symbol.norm(data=data, ord=order, axis=i,
keepdims=True)
+ npy_out = l1norm(in_data, i) if order==1 else l2norm(in_data,
i)
Review comment:
python's ``is`` compares object reference whereas == compares for value.
Here we want to compare the values and not object references. Using ``is``
might make the test fail.
For example -
```python
>>> 625 is 25**2
False
>>> 625 == 25**2
True
```
----------------------------------------------------------------
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