[Piglit] [PATCH] Generated tests: unify code for testing exp2 across all numpy versions.

Paul Berry stereotype441 at gmail.com
Mon Aug 8 16:04:05 PDT 2011


Versions of numpy previous to 1.3.0 (such as the one that ships with
Snow Leopard, which is 1.2.1) didn't include an exp2() function, so
commit a5180ddc worked around the problem by emulating it using
power(2, x) when the numpy version was less than 1.3.0.

There is no real advantage to using exp2() over power(2, x) (other
than to save a few keystrokes), but there is a maintenance advantage
to being as consistent as possible across numpy versions.  So this
patch changes Piglit to use power(2, x) regardless of the numpy
version.
---
 generated_tests/builtin_function.py |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/generated_tests/builtin_function.py b/generated_tests/builtin_function.py
index 1f8e4af..69deb77 100644
--- a/generated_tests/builtin_function.py
+++ b/generated_tests/builtin_function.py
@@ -34,7 +34,6 @@
 # they are not pure, so they can't be tested using simple test
 # vectors.
 
-import distutils.version
 import collections
 import itertools
 import numpy as np
@@ -303,6 +302,10 @@ def _pow(x, y):
     if x == 0.0 and y <= 0.0:
 	return None
     return np.power(x, y)
+def _exp2(x):
+    # exp2() is not available in versions of numpy < 1.3.0 so we
+    # emulate it with power().
+    return np.power(2, x)
 def _clamp(x, minVal, maxVal):
     if minVal > maxVal:
 	return None
@@ -625,10 +628,7 @@ def _make_componentwise_test_vectors(test_suite_dict):
     f('pow', 2, '1.10', _pow, None, [np.linspace(0.0, 2.0, 4), np.linspace(-2.0, 2.0, 4)])
     f('exp', 1, '1.10', np.exp, None, [np.linspace(-2.0, 2.0, 4)])
     f('log', 1, '1.10', np.log, None, [np.linspace(0.01, 2.0, 4)])
-    if distutils.version.StrictVersion(np.version.version) >= '1.3.0':
-        f('exp2', 1, '1.10', np.exp2, None, [np.linspace(-2.0, 2.0, 4)])
-    else:
-        f('exp2', 1, '1.10', lambda x: np.power(2, x), None, [np.linspace(-2.0, 2.0, 4)])
+    f('exp2', 1, '1.10', _exp2, None, [np.linspace(-2.0, 2.0, 4)])
     f('log2', 1, '1.10', np.log2, None, [np.linspace(0.01, 2.0, 4)])
     f('sqrt', 1, '1.10', np.sqrt, None, [np.linspace(0.0, 2.0, 4)])
     f('inversesqrt', 1, '1.10', lambda x: 1.0/np.sqrt(x), None, [np.linspace(0.1, 2.0, 4)])
-- 
1.7.6



More information about the Piglit mailing list