From 125d29de8829edbb60b90b2a87e2ed97f0884643 Mon Sep 17 00:00:00 2001 From: Pieter Eendebak Date: Sat, 16 Mar 2024 21:18:57 +0100 Subject: [PATCH 01/14] ENH: Optimize np.power(x, 2) for float type --- numpy/_core/src/umath/fast_loop_macros.h | 10 ++++++++ .../src/umath/loops_umath_fp.dispatch.c.src | 24 ++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/numpy/_core/src/umath/fast_loop_macros.h b/numpy/_core/src/umath/fast_loop_macros.h index b8c1926b2f7e..7545fe40fb3e 100644 --- a/numpy/_core/src/umath/fast_loop_macros.h +++ b/numpy/_core/src/umath/fast_loop_macros.h @@ -90,6 +90,16 @@ abs_ptrdiff(char *a, char *b) BINARY_DEFS\ BINARY_LOOP_SLIDING +/** (ip1, ip2) -> (op1), for case ip2 has zero stride*/ +#define BINARY_DEFS_ZERO_STRIDE\ + char *ip1 = args[0], *ip2 = args[1], *op1 = args[2];\ + npy_intp is1 = steps[0], os1 = steps[2];\ + npy_intp n = dimensions[0];\ + npy_intp i; + +#define BINARY_LOOP_SLIDING_ZERO_STRIDE \ + for (i = 0; i < n; i++, ip1 += is1, op1 += os1) + /** (ip1, ip2) -> (op1, op2) */ #define BINARY_LOOP_TWO_OUT\ char *ip1 = args[0], *ip2 = args[1], *op1 = args[2], *op2 = args[3];\ diff --git a/numpy/_core/src/umath/loops_umath_fp.dispatch.c.src b/numpy/_core/src/umath/loops_umath_fp.dispatch.c.src index 2390fb989190..e5405d78ac34 100644 --- a/numpy/_core/src/umath/loops_umath_fp.dispatch.c.src +++ b/numpy/_core/src/umath/loops_umath_fp.dispatch.c.src @@ -251,10 +251,28 @@ NPY_NO_EXPORT void NPY_CPU_DISPATCH_CURFX(@TYPE@_@func@) return; } #endif - BINARY_LOOP { - const @type@ in1 = *(@type@ *)ip1; + if (steps[1]==0) { + BINARY_DEFS_ZERO_STRIDE const @type@ in2 = *(@type@ *)ip2; - *(@type@ *)op1 = npy_@intrin@@vsub@(in1, in2); + if (in2 == 2.0) { + BINARY_LOOP_SLIDING_ZERO_STRIDE { + const @type@ in1 = *(@type@ *)ip1; + *(@type@ *)op1 = in1 * in1; + } + } + else { + BINARY_LOOP_SLIDING_ZERO_STRIDE { + const @type@ in1 = *(@type@ *)ip1; + *(@type@ *)op1 = npy_@intrin@@vsub@(in1, in2); + } + } + } + else { + BINARY_LOOP { + const @type@ in1 = *(@type@ *)ip1; + const @type@ in2 = *(@type@ *)ip2; + *(@type@ *)op1 = npy_@intrin@@vsub@(in1, in2); + } } } /**end repeat1**/ From 852bfec6b714ab0f067c9bd58c16809e026ce955 Mon Sep 17 00:00:00 2001 From: Pieter Eendebak Date: Sat, 16 Mar 2024 21:25:37 +0100 Subject: [PATCH 02/14] fix macro --- numpy/_core/src/umath/fast_loop_macros.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numpy/_core/src/umath/fast_loop_macros.h b/numpy/_core/src/umath/fast_loop_macros.h index 7545fe40fb3e..366facb5a100 100644 --- a/numpy/_core/src/umath/fast_loop_macros.h +++ b/numpy/_core/src/umath/fast_loop_macros.h @@ -95,7 +95,7 @@ abs_ptrdiff(char *a, char *b) char *ip1 = args[0], *ip2 = args[1], *op1 = args[2];\ npy_intp is1 = steps[0], os1 = steps[2];\ npy_intp n = dimensions[0];\ - npy_intp i; + npy_intp i;\ #define BINARY_LOOP_SLIDING_ZERO_STRIDE \ for (i = 0; i < n; i++, ip1 += is1, op1 += os1) From a4e208d39de323827226427c9c854796c6d31b12 Mon Sep 17 00:00:00 2001 From: Pieter Eendebak Date: Sat, 16 Mar 2024 21:52:09 +0100 Subject: [PATCH 03/14] apply only to power and not arctan2 --- .../_core/src/umath/loops_umath_fp.dispatch.c.src | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/numpy/_core/src/umath/loops_umath_fp.dispatch.c.src b/numpy/_core/src/umath/loops_umath_fp.dispatch.c.src index e5405d78ac34..476286fb259a 100644 --- a/numpy/_core/src/umath/loops_umath_fp.dispatch.c.src +++ b/numpy/_core/src/umath/loops_umath_fp.dispatch.c.src @@ -230,6 +230,7 @@ NPY_NO_EXPORT void NPY_CPU_DISPATCH_CURFX(@TYPE@_@func@) /**begin repeat1 * #func = power, arctan2# * #intrin = pow, atan2# + * #ispower = 1, 0# */ NPY_NO_EXPORT void NPY_CPU_DISPATCH_CURFX(@TYPE@_@func@) (char **args, npy_intp const *dimensions, npy_intp const *steps, void *NPY_UNUSED(data)) @@ -251,6 +252,7 @@ NPY_NO_EXPORT void NPY_CPU_DISPATCH_CURFX(@TYPE@_@func@) return; } #endif +#if @ispower@ if (steps[1]==0) { BINARY_DEFS_ZERO_STRIDE const @type@ in2 = *(@type@ *)ip2; @@ -266,13 +268,13 @@ NPY_NO_EXPORT void NPY_CPU_DISPATCH_CURFX(@TYPE@_@func@) *(@type@ *)op1 = npy_@intrin@@vsub@(in1, in2); } } + return; } - else { - BINARY_LOOP { - const @type@ in1 = *(@type@ *)ip1; - const @type@ in2 = *(@type@ *)ip2; - *(@type@ *)op1 = npy_@intrin@@vsub@(in1, in2); - } +#endif + BINARY_LOOP { + const @type@ in1 = *(@type@ *)ip1; + const @type@ in2 = *(@type@ *)ip2; + *(@type@ *)op1 = npy_@intrin@@vsub@(in1, in2); } } /**end repeat1**/ From e0194de1c943120c261bd4d7c9a752e69a6f17e1 Mon Sep 17 00:00:00 2001 From: Pieter Eendebak Date: Thu, 4 Apr 2024 12:54:10 +0200 Subject: [PATCH 04/14] add sqrt --- .../src/umath/loops_umath_fp.dispatch.c.src | 75 +++++++++++++++---- 1 file changed, 59 insertions(+), 16 deletions(-) diff --git a/numpy/_core/src/umath/loops_umath_fp.dispatch.c.src b/numpy/_core/src/umath/loops_umath_fp.dispatch.c.src index 476286fb259a..2e38e575b9e2 100644 --- a/numpy/_core/src/umath/loops_umath_fp.dispatch.c.src +++ b/numpy/_core/src/umath/loops_umath_fp.dispatch.c.src @@ -226,15 +226,34 @@ NPY_NO_EXPORT void NPY_CPU_DISPATCH_CURFX(@TYPE@_@func@) * #type = npy_double, npy_float# * #vsub = , f# * #sfx = f64, f32# + * #sqrt = sqrt, sqrtf# */ /**begin repeat1 - * #func = power, arctan2# - * #intrin = pow, atan2# - * #ispower = 1, 0# + * #func = power# + * #intrin = pow# */ NPY_NO_EXPORT void NPY_CPU_DISPATCH_CURFX(@TYPE@_@func@) (char **args, npy_intp const *dimensions, npy_intp const *steps, void *NPY_UNUSED(data)) { + int stride_zero = steps[1]==0; + if (stride_zero) { + BINARY_DEFS_ZERO_STRIDE + const @type@ in2 = *(@type@ *)ip2; + if (in2 == 2.0) { + BINARY_LOOP_SLIDING_ZERO_STRIDE { + const @type@ in1 = *(@type@ *)ip1; + *(@type@ *)op1 = in1 * in1; + } + return; + } + else if (in2 == 0.5) { + BINARY_LOOP_SLIDING_ZERO_STRIDE { + const @type@ in1 = *(@type@ *)ip1; + *(@type@ *)op1 =@sqrt@(in1); + } + return; + } + } #if NPY_SIMD && defined(NPY_HAVE_AVX512_SKX) && defined(NPY_CAN_LINK_SVML) const @type@ *src1 = (@type@*)args[0]; const @type@ *src2 = (@type@*)args[1]; @@ -252,24 +271,47 @@ NPY_NO_EXPORT void NPY_CPU_DISPATCH_CURFX(@TYPE@_@func@) return; } #endif -#if @ispower@ - if (steps[1]==0) { + if (stride_zero) { + // this maybe a bit faster than the generic loop, but not sure BINARY_DEFS_ZERO_STRIDE const @type@ in2 = *(@type@ *)ip2; - if (in2 == 2.0) { - BINARY_LOOP_SLIDING_ZERO_STRIDE { - const @type@ in1 = *(@type@ *)ip1; - *(@type@ *)op1 = in1 * in1; - } - } - else { - BINARY_LOOP_SLIDING_ZERO_STRIDE { - const @type@ in1 = *(@type@ *)ip1; - *(@type@ *)op1 = npy_@intrin@@vsub@(in1, in2); - } + BINARY_LOOP_SLIDING_ZERO_STRIDE { + const @type@ in1 = *(@type@ *)ip1; + *(@type@ *)op1 = npy_@intrin@@vsub@(in1, in2); } return; } + BINARY_LOOP { + const @type@ in1 = *(@type@ *)ip1; + const @type@ in2 = *(@type@ *)ip2; + *(@type@ *)op1 = npy_@intrin@@vsub@(in1, in2); + } +} +/**end repeat1**/ + +/**begin repeat1 + * #func = arctan2# + * #intrin = atan2# + */ +NPY_NO_EXPORT void NPY_CPU_DISPATCH_CURFX(@TYPE@_@func@) +(char **args, npy_intp const *dimensions, npy_intp const *steps, void *NPY_UNUSED(data)) +{ +#if NPY_SIMD && defined(NPY_HAVE_AVX512_SKX) && defined(NPY_CAN_LINK_SVML) + const @type@ *src1 = (@type@*)args[0]; + const @type@ *src2 = (@type@*)args[1]; + @type@ *dst = (@type@*)args[2]; + const int lsize = sizeof(src1[0]); + const npy_intp ssrc1 = steps[0] / lsize; + const npy_intp ssrc2 = steps[1] / lsize; + const npy_intp sdst = steps[2] / lsize; + const npy_intp len = dimensions[0]; + assert(len <= 1 || (steps[0] % lsize == 0 && steps[1] % lsize == 0)); + if (!is_mem_overlap(src1, steps[0], dst, steps[2], len) && !is_mem_overlap(src2, steps[1], dst, steps[2], len) && + npyv_loadable_stride_@sfx@(ssrc1) && npyv_loadable_stride_@sfx@(ssrc2) && + npyv_storable_stride_@sfx@(sdst)) { + simd_@intrin@_@sfx@(src1, ssrc1, src2, ssrc2, dst, sdst, len); + return; + } #endif BINARY_LOOP { const @type@ in1 = *(@type@ *)ip1; @@ -278,4 +320,5 @@ NPY_NO_EXPORT void NPY_CPU_DISPATCH_CURFX(@TYPE@_@func@) } } /**end repeat1**/ + /**end repeat**/ From f8d9e5402c3d085d0eac4c3d5ca2138cd3044355 Mon Sep 17 00:00:00 2001 From: Pieter Eendebak Date: Thu, 4 Apr 2024 23:23:03 +0200 Subject: [PATCH 05/14] add tests for the fast paths --- numpy/_core/tests/test_umath.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/numpy/_core/tests/test_umath.py b/numpy/_core/tests/test_umath.py index e01e6dd6346b..32c000501fa2 100644 --- a/numpy/_core/tests/test_umath.py +++ b/numpy/_core/tests/test_umath.py @@ -1235,6 +1235,16 @@ def test_float_to_inf_power(self): r = np.array([1, 1, np.inf, 0, np.inf, 0, np.inf, 0], dt) assert_equal(np.power(a, b), r) + def test_power_fast_paths(self): + # gh-26055 + for dt in [np.float32, np.float64]: + expected = np.array([0.0, 1.21, 4., 1.44e+26, np.inf, np.inf]) + a = np.array([0, 1.1, 2, 12e12, np.inf, -np.inf], dt) + assert_equal(np.power(a, 2.), expected.astype(dt)) + + expected = np.sqrt(a) + assert_equal(np.power(a, 0.5), expected.astype(dt)) + class TestFloat_power: def test_type_conversion(self): From 3831d69bc0e9284c4dfa4022ba1e614ce89c31b3 Mon Sep 17 00:00:00 2001 From: Pieter Eendebak Date: Thu, 4 Apr 2024 23:26:17 +0200 Subject: [PATCH 06/14] review comments --- numpy/_core/src/umath/loops_umath_fp.dispatch.c.src | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/numpy/_core/src/umath/loops_umath_fp.dispatch.c.src b/numpy/_core/src/umath/loops_umath_fp.dispatch.c.src index 2e38e575b9e2..7c379e1612ce 100644 --- a/numpy/_core/src/umath/loops_umath_fp.dispatch.c.src +++ b/numpy/_core/src/umath/loops_umath_fp.dispatch.c.src @@ -271,16 +271,6 @@ NPY_NO_EXPORT void NPY_CPU_DISPATCH_CURFX(@TYPE@_@func@) return; } #endif - if (stride_zero) { - // this maybe a bit faster than the generic loop, but not sure - BINARY_DEFS_ZERO_STRIDE - const @type@ in2 = *(@type@ *)ip2; - BINARY_LOOP_SLIDING_ZERO_STRIDE { - const @type@ in1 = *(@type@ *)ip1; - *(@type@ *)op1 = npy_@intrin@@vsub@(in1, in2); - } - return; - } BINARY_LOOP { const @type@ in1 = *(@type@ *)ip1; const @type@ in2 = *(@type@ *)ip2; From c5d3e29662722df586bf075151e84abf31b0e428 Mon Sep 17 00:00:00 2001 From: Pieter Eendebak Date: Fri, 5 Apr 2024 10:51:13 +0200 Subject: [PATCH 07/14] review comments --- numpy/_core/tests/test_umath.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/numpy/_core/tests/test_umath.py b/numpy/_core/tests/test_umath.py index 32c000501fa2..491c1a54853c 100644 --- a/numpy/_core/tests/test_umath.py +++ b/numpy/_core/tests/test_umath.py @@ -1238,12 +1238,15 @@ def test_float_to_inf_power(self): def test_power_fast_paths(self): # gh-26055 for dt in [np.float32, np.float64]: + a = np.array([0, 1.1, 2, 12e12, -10., np.inf, -np.inf], dt) + expected = np.array([0.0, 1.21, 4., 1.44e+26, np.inf, np.inf]) - a = np.array([0, 1.1, 2, 12e12, np.inf, -np.inf], dt) - assert_equal(np.power(a, 2.), expected.astype(dt)) + result = np.power(a, 2.) + assert_array_max_ulp(result, expected.astype(dt), maxulp=1) expected = np.sqrt(a) - assert_equal(np.power(a, 0.5), expected.astype(dt)) + result = np.power(a, 0.5) + assert_array_max_ulp(result, expected.astype(dt), maxulp=1) class TestFloat_power: From 620b562756efb5dedefa2ded94ef43ec89f86ea4 Mon Sep 17 00:00:00 2001 From: Pieter Eendebak Date: Fri, 5 Apr 2024 14:45:08 +0200 Subject: [PATCH 08/14] tests --- numpy/_core/tests/test_umath.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/numpy/_core/tests/test_umath.py b/numpy/_core/tests/test_umath.py index 491c1a54853c..429c3543add8 100644 --- a/numpy/_core/tests/test_umath.py +++ b/numpy/_core/tests/test_umath.py @@ -1240,13 +1240,14 @@ def test_power_fast_paths(self): for dt in [np.float32, np.float64]: a = np.array([0, 1.1, 2, 12e12, -10., np.inf, -np.inf], dt) - expected = np.array([0.0, 1.21, 4., 1.44e+26, np.inf, np.inf]) + expected = np.array([0.0, 1.21, 4., 1.44e+26, 100, np.inf, np.inf]) result = np.power(a, 2.) assert_array_max_ulp(result, expected.astype(dt), maxulp=1) expected = np.sqrt(a) result = np.power(a, 0.5) - assert_array_max_ulp(result, expected.astype(dt), maxulp=1) + # needs to be fixed! + assert_array_max_ulp(result[:-1], expected[:-1].astype(dt), maxulp=1) class TestFloat_power: From 320d036a2658bcc82d37095afdd58226e3c7f8da Mon Sep 17 00:00:00 2001 From: Pieter Eendebak Date: Fri, 19 Apr 2024 20:40:01 +0200 Subject: [PATCH 09/14] remove fast path for sqrt --- numpy/_core/src/umath/loops_umath_fp.dispatch.c.src | 7 ------- numpy/_core/tests/test_umath.py | 1 - 2 files changed, 8 deletions(-) diff --git a/numpy/_core/src/umath/loops_umath_fp.dispatch.c.src b/numpy/_core/src/umath/loops_umath_fp.dispatch.c.src index 7c379e1612ce..8b6b06c4199a 100644 --- a/numpy/_core/src/umath/loops_umath_fp.dispatch.c.src +++ b/numpy/_core/src/umath/loops_umath_fp.dispatch.c.src @@ -246,13 +246,6 @@ NPY_NO_EXPORT void NPY_CPU_DISPATCH_CURFX(@TYPE@_@func@) } return; } - else if (in2 == 0.5) { - BINARY_LOOP_SLIDING_ZERO_STRIDE { - const @type@ in1 = *(@type@ *)ip1; - *(@type@ *)op1 =@sqrt@(in1); - } - return; - } } #if NPY_SIMD && defined(NPY_HAVE_AVX512_SKX) && defined(NPY_CAN_LINK_SVML) const @type@ *src1 = (@type@*)args[0]; diff --git a/numpy/_core/tests/test_umath.py b/numpy/_core/tests/test_umath.py index 429c3543add8..be3cdf2e8e06 100644 --- a/numpy/_core/tests/test_umath.py +++ b/numpy/_core/tests/test_umath.py @@ -1246,7 +1246,6 @@ def test_power_fast_paths(self): expected = np.sqrt(a) result = np.power(a, 0.5) - # needs to be fixed! assert_array_max_ulp(result[:-1], expected[:-1].astype(dt), maxulp=1) From 050cb1f1d88c1306fab5bab46d259f5f656043be Mon Sep 17 00:00:00 2001 From: Pieter Eendebak Date: Sat, 11 May 2024 22:29:50 +0200 Subject: [PATCH 10/14] lint --- numpy/_core/tests/test_umath.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/numpy/_core/tests/test_umath.py b/numpy/_core/tests/test_umath.py index 4d73fce3b727..1ebd5633be6c 100644 --- a/numpy/_core/tests/test_umath.py +++ b/numpy/_core/tests/test_umath.py @@ -1244,9 +1244,9 @@ def test_power_fast_paths(self): result = np.power(a, 2.) assert_array_max_ulp(result, expected.astype(dt), maxulp=1) - expected = np.sqrt(a) + expected = np.sqrt(a).astype(dt) result = np.power(a, 0.5) - assert_array_max_ulp(result[:-1], expected[:-1].astype(dt), maxulp=1) + assert_array_max_ulp(result[:-1], expected[:-1], maxulp=1) class TestFloat_power: From 3ff27fee75a39b5025a1a3a28ffbda9ea2e35ec2 Mon Sep 17 00:00:00 2001 From: Pieter Eendebak Date: Sat, 11 May 2024 22:51:10 +0200 Subject: [PATCH 11/14] fix tests --- numpy/_core/tests/test_umath.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/numpy/_core/tests/test_umath.py b/numpy/_core/tests/test_umath.py index 1ebd5633be6c..621579b4da2b 100644 --- a/numpy/_core/tests/test_umath.py +++ b/numpy/_core/tests/test_umath.py @@ -1239,15 +1239,19 @@ def test_power_fast_paths(self): # gh-26055 for dt in [np.float32, np.float64]: a = np.array([0, 1.1, 2, 12e12, -10., np.inf, -np.inf], dt) - expected = np.array([0.0, 1.21, 4., 1.44e+26, 100, np.inf, np.inf]) result = np.power(a, 2.) assert_array_max_ulp(result, expected.astype(dt), maxulp=1) + a = np.array([0, 1.1, 2, 12e12, np.inf], dt) expected = np.sqrt(a).astype(dt) result = np.power(a, 0.5) - assert_array_max_ulp(result[:-1], expected[:-1], maxulp=1) + assert_array_max_ulp(result, expected, maxulp=1) + with warnings.catch_warnings(record=True) as w: + warnings.filterwarnings('always', '', RuntimeWarning) + assert_(np.isnan(np.power(-10, .5))) + assert_(w[0].category is RuntimeWarning) class TestFloat_power: def test_type_conversion(self): From 2eff77fb9cbc4a5abc642b9acaecd5a05137d2f9 Mon Sep 17 00:00:00 2001 From: Pieter Eendebak Date: Sat, 11 May 2024 22:59:03 +0200 Subject: [PATCH 12/14] apply branching pattern --- numpy/_core/src/umath/fast_loop_macros.h | 10 ---------- numpy/_core/src/umath/loops_umath_fp.dispatch.c.src | 4 ++-- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/numpy/_core/src/umath/fast_loop_macros.h b/numpy/_core/src/umath/fast_loop_macros.h index 366facb5a100..b8c1926b2f7e 100644 --- a/numpy/_core/src/umath/fast_loop_macros.h +++ b/numpy/_core/src/umath/fast_loop_macros.h @@ -90,16 +90,6 @@ abs_ptrdiff(char *a, char *b) BINARY_DEFS\ BINARY_LOOP_SLIDING -/** (ip1, ip2) -> (op1), for case ip2 has zero stride*/ -#define BINARY_DEFS_ZERO_STRIDE\ - char *ip1 = args[0], *ip2 = args[1], *op1 = args[2];\ - npy_intp is1 = steps[0], os1 = steps[2];\ - npy_intp n = dimensions[0];\ - npy_intp i;\ - -#define BINARY_LOOP_SLIDING_ZERO_STRIDE \ - for (i = 0; i < n; i++, ip1 += is1, op1 += os1) - /** (ip1, ip2) -> (op1, op2) */ #define BINARY_LOOP_TWO_OUT\ char *ip1 = args[0], *ip2 = args[1], *op1 = args[2], *op2 = args[3];\ diff --git a/numpy/_core/src/umath/loops_umath_fp.dispatch.c.src b/numpy/_core/src/umath/loops_umath_fp.dispatch.c.src index 8b6b06c4199a..74af8edaa1f5 100644 --- a/numpy/_core/src/umath/loops_umath_fp.dispatch.c.src +++ b/numpy/_core/src/umath/loops_umath_fp.dispatch.c.src @@ -237,10 +237,10 @@ NPY_NO_EXPORT void NPY_CPU_DISPATCH_CURFX(@TYPE@_@func@) { int stride_zero = steps[1]==0; if (stride_zero) { - BINARY_DEFS_ZERO_STRIDE + BINARY_DEFS const @type@ in2 = *(@type@ *)ip2; if (in2 == 2.0) { - BINARY_LOOP_SLIDING_ZERO_STRIDE { + BINARY_LOOP_SLIDING { const @type@ in1 = *(@type@ *)ip1; *(@type@ *)op1 = in1 * in1; } From 1a599d52fd98669436634d5c9f21e8bfe3704318 Mon Sep 17 00:00:00 2001 From: Pieter Eendebak Date: Sat, 11 May 2024 23:10:22 +0200 Subject: [PATCH 13/14] do not add special test for sqrt --- numpy/_core/tests/test_umath.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/numpy/_core/tests/test_umath.py b/numpy/_core/tests/test_umath.py index 621579b4da2b..ad02b101022e 100644 --- a/numpy/_core/tests/test_umath.py +++ b/numpy/_core/tests/test_umath.py @@ -1248,10 +1248,6 @@ def test_power_fast_paths(self): result = np.power(a, 0.5) assert_array_max_ulp(result, expected, maxulp=1) - with warnings.catch_warnings(record=True) as w: - warnings.filterwarnings('always', '', RuntimeWarning) - assert_(np.isnan(np.power(-10, .5))) - assert_(w[0].category is RuntimeWarning) class TestFloat_power: def test_type_conversion(self): From 51bedd5b7592a316e55ccd01f6f5586e0cfadc7e Mon Sep 17 00:00:00 2001 From: Pieter Eendebak Date: Sun, 12 May 2024 00:22:16 +0200 Subject: [PATCH 14/14] fix tests on all platforms --- numpy/_core/tests/test_umath.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numpy/_core/tests/test_umath.py b/numpy/_core/tests/test_umath.py index ad02b101022e..7a3d1078647a 100644 --- a/numpy/_core/tests/test_umath.py +++ b/numpy/_core/tests/test_umath.py @@ -1243,7 +1243,7 @@ def test_power_fast_paths(self): result = np.power(a, 2.) assert_array_max_ulp(result, expected.astype(dt), maxulp=1) - a = np.array([0, 1.1, 2, 12e12, np.inf], dt) + a = np.array([0, 1.1, 2, 12e12], dt) expected = np.sqrt(a).astype(dt) result = np.power(a, 0.5) assert_array_max_ulp(result, expected, maxulp=1)