summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--benchmarks/benchmarks/bench_avx.py8
-rw-r--r--numpy/core/tests/test_umath_accuracy.py44
2 files changed, 26 insertions, 26 deletions
diff --git a/benchmarks/benchmarks/bench_avx.py b/benchmarks/benchmarks/bench_avx.py
index c166d6b3f..224c12e33 100644
--- a/benchmarks/benchmarks/bench_avx.py
+++ b/benchmarks/benchmarks/bench_avx.py
@@ -136,7 +136,7 @@ class LogisticRegression(Benchmark):
def train(self, max_epoch):
for epoch in range(max_epoch):
z = np.matmul(self.X_train, self.W)
- A = 1/ (1 + np.exp(-z)) #sigmoid(z)
+ A = 1 / (1 + np.exp(-z)) # sigmoid(z)
loss = -np.mean(self.Y_train * np.log(A) + (1-self.Y_train) * np.log(1-A))
dz = A - self.Y_train
dw = (1/self.size) * np.matmul(self.X_train.T, dz)
@@ -149,9 +149,9 @@ class LogisticRegression(Benchmark):
self.X_train = np.float32(np.random.rand(self.size,features))
self.Y_train = np.float32(np.random.choice(2,self.size))
# Initialize weights
- self.W = np.float32(np.zeros((features,1)))
- self.b = np.float32(np.zeros((1,1)))
+ self.W = np.zeros((features,1), dtype=np.float32)
+ self.b = np.zeros((1,1), dtype=np.float32)
self.alpha = 0.1
def time_train(self):
- self.train(5000)
+ self.train(1000)
diff --git a/numpy/core/tests/test_umath_accuracy.py b/numpy/core/tests/test_umath_accuracy.py
index 32211974c..f3281e418 100644
--- a/numpy/core/tests/test_umath_accuracy.py
+++ b/numpy/core/tests/test_umath_accuracy.py
@@ -5,14 +5,14 @@ import sys
import pytest
from ctypes import c_float, c_int, cast, pointer, POINTER
from numpy.testing import assert_array_max_ulp
+from numpy.core._multiarray_umath import __cpu_features__
-runtest = sys.platform.startswith('linux') and (platform.machine() == 'x86_64')
+IS_AVX = __cpu_features__.get('AVX512F', False) or \
+ (__cpu_features__.get('FMA3', False) and __cpu_features__.get('AVX2', False))
+runtest = sys.platform.startswith('linux') and IS_AVX
platform_skip = pytest.mark.skipif(not runtest,
- reason="""
- stick to x86_64 and linux platforms.
- test seems to fail on some of ARM and power
- architectures.
- """)
+ reason="avoid testing inconsistent platform "
+ "library implementations")
# convert string to hex function taken from:
# https://stackoverflow.com/questions/1592158/convert-hex-to-float #
@@ -29,7 +29,7 @@ files = ['umath-validation-set-exp',
'umath-validation-set-cos']
class TestAccuracy:
- @pytest.mark.xfail(reason="Fails for MacPython/numpy-wheels builds")
+ @platform_skip
def test_validate_transcendentals(self):
with np.errstate(all='ignore'):
for filename in files:
@@ -37,18 +37,18 @@ class TestAccuracy:
filepath = path.join(data_dir, filename)
with open(filepath) as fid:
file_without_comments = (r for r in fid if not r[0] in ('$', '#'))
- data = np.genfromtxt(file_without_comments,
- dtype=('|S39','|S39','|S39',int),
- names=('type','input','output','ulperr'),
- delimiter=',',
- skip_header=1)
- npfunc = getattr(np, filename.split('-')[3])
- for datatype in np.unique(data['type']):
- data_subset = data[data['type'] == datatype]
- inval = np.array(str_to_float(data_subset['input'].astype(str)), dtype=eval(datatype))
- outval = np.array(str_to_float(data_subset['output'].astype(str)), dtype=eval(datatype))
- perm = np.random.permutation(len(inval))
- inval = inval[perm]
- outval = outval[perm]
- maxulperr = data_subset['ulperr'].max()
- assert_array_max_ulp(npfunc(inval), outval, maxulperr)
+ data = np.genfromtxt(file_without_comments,
+ dtype=('|S39','|S39','|S39',int),
+ names=('type','input','output','ulperr'),
+ delimiter=',',
+ skip_header=1)
+ npfunc = getattr(np, filename.split('-')[3])
+ for datatype in np.unique(data['type']):
+ data_subset = data[data['type'] == datatype]
+ inval = np.array(str_to_float(data_subset['input'].astype(str)), dtype=eval(datatype))
+ outval = np.array(str_to_float(data_subset['output'].astype(str)), dtype=eval(datatype))
+ perm = np.random.permutation(len(inval))
+ inval = inval[perm]
+ outval = outval[perm]
+ maxulperr = data_subset['ulperr'].max()
+ assert_array_max_ulp(npfunc(inval), outval, maxulperr)