diff options
-rw-r--r-- | benchmarks/benchmarks/bench_avx.py | 32 | ||||
-rw-r--r-- | numpy/core/tests/test_umath_accuracy.py | 44 |
2 files changed, 53 insertions, 23 deletions
diff --git a/benchmarks/benchmarks/bench_avx.py b/benchmarks/benchmarks/bench_avx.py index b6a6aa59e..224c12e33 100644 --- a/benchmarks/benchmarks/bench_avx.py +++ b/benchmarks/benchmarks/bench_avx.py @@ -2,7 +2,11 @@ from .common import Benchmark import numpy as np -avx_ufuncs = ['sqrt', +avx_ufuncs = ['sin', + 'cos', + 'exp', + 'log', + 'sqrt', 'absolute', 'reciprocal', 'square', @@ -125,3 +129,29 @@ class Mandelbrot(Benchmark): def time_mandel(self): self.mandelbrot_set(-0.74877,-0.74872,0.06505,0.06510,1000,1000,2048) + +class LogisticRegression(Benchmark): + + timeout = 1000 + 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) + 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) + self.W = self.W - self.alpha*dw + + def setup(self): + np.random.seed(42) + self.size = 250 + features = 16 + 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.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(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) |