From 03063f2510f3ce8cebdddc04f1ca54a8b84a2317 Mon Sep 17 00:00:00 2001 From: Chaitanya Prakash Bapat Date: Thu, 15 Aug 2019 23:45:07 -0700 Subject: [PATCH] Add power, exponent, log ops large tensor support (#15794) * power, exponent, log ops * lint * Trigger notification * Trigger notification * Trigger notification --- tests/nightly/test_large_array.py | 66 +++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/tests/nightly/test_large_array.py b/tests/nightly/test_large_array.py index 585748ee59b1..02c867720609 100644 --- a/tests/nightly/test_large_array.py +++ b/tests/nightly/test_large_array.py @@ -444,6 +444,72 @@ def test_topk(): assert l.sum() == np.sum(np.arange(0, SMALL_Y)) +def test_exponent_logarithm_operators(): + a = 2*nd.ones(shape=(LARGE_X, SMALL_Y)) + # exponent + result = nd.exp(a) + assert result[0][-1] == 7.389056 + assert result.shape == a.shape + + # exponent minus 1 + result = nd.expm1(a) + assert result[0][-1] == 6.389056 + assert result.shape == a.shape + + # log2 + result = nd.log2(a) + assert result[0][-1] == 1 + assert result.shape == a.shape + + # log10 + result = nd.log10(a) + assert result[0][-1] == 0.30103 + assert result.shape == a.shape + + # log1p + result = nd.log1p(a) + assert result[0][-1] == 1.0986123 + assert result.shape == a.shape + + # log + result = nd.log(a) + assert result[0][-1] == 0.6931472 + assert result.shape == a.shape + + +def test_power_operators(): + a = 2*nd.ones(shape=(LARGE_X, SMALL_Y)) + # sqrt + result = nd.sqrt(a) + assert result[0][-1] == 1.4142135 + assert result.shape == a.shape + + # rsqrt + result = nd.rsqrt(a) + assert result[0][-1] == 0.70710677 + assert result.shape == a.shape + + # cbrt + result = nd.cbrt(a) + assert result[0][-1] == 1.2599211 + assert result.shape == a.shape + + # rcbrt + result = nd.rcbrt(a) + assert result[0][-1] == 0.7937005 + assert result.shape == a.shape + + # square + result = nd.square(a) + assert result[0][-1] == 4 + assert result.shape == a.shape + + # reciprocal + result = nd.reciprocal(a) + assert result[0][-1] == 0.5 + assert result.shape == a.shape + + def test_sequence_mask(): # Sequence Mask input [max_sequence_length, batch_size, other_feature_dims] # test with input batch_size = 2