summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Berry <stereotype441@gmail.com>2011-08-08 15:49:19 -0700
committerPaul Berry <stereotype441@gmail.com>2011-08-10 14:38:35 -0700
commitb0517d17754a8c35bd044b61afb23456dab3cac4 (patch)
tree23a9602e7b195d42046adba15e08c669144d04d9
parent1e77364946e50d087a09ef588f8b90b502019838 (diff)
Generated tests: unify code for testing exp2 across all numpy versions.
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.
-rw-r--r--generated_tests/builtin_function.py10
1 files changed, 5 insertions, 5 deletions
diff --git a/generated_tests/builtin_function.py b/generated_tests/builtin_function.py
index 1f8e4af7..69deb777 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)])