From e421b7805e0b1e7b2092bc73b8174a9f711ca903 Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Wed, 10 Sep 2025 11:12:54 -0500 Subject: [PATCH 1/2] No need to have a separate loop for log2 --- mkl_umath/src/mkl_umath_loops.c.src | 37 +++-------------------------- 1 file changed, 3 insertions(+), 34 deletions(-) diff --git a/mkl_umath/src/mkl_umath_loops.c.src b/mkl_umath/src/mkl_umath_loops.c.src index 1890dcd..e47477e 100644 --- a/mkl_umath/src/mkl_umath_loops.c.src +++ b/mkl_umath/src/mkl_umath_loops.c.src @@ -866,9 +866,9 @@ mkl_umath_@TYPE@_remainder(char **args, const npy_intp *dimensions, const npy_in } /**begin repeat1 - * # kind = cos, sin, tan, arccos, arcsin, arctan, cosh, sinh, tanh, arccosh, arcsinh, arctanh, fabs, floor, ceil, rint, trunc, cbrt, sqrt, expm1, log, log1p, log10# - * # func = cos, sin, tan, acos, asin, atan, cosh, sinh, tanh, acosh, asinh, atanh, fabs, floor, ceil, rint, trunc, cbrt, sqrt, expm1, log, log1p, log10# - * # VML = Cos, Sin, Tan, Acos, Asin, Atan, Cosh, Sinh, Tanh, Acosh, Asinh, Atanh, Abs, Floor, Ceil, Rint, Trunc, Cbrt, Sqrt, Expm1, Ln, Log1p, Log10# + * # kind = cos, sin, tan, arccos, arcsin, arctan, cosh, sinh, tanh, arccosh, arcsinh, arctanh, fabs, floor, ceil, rint, trunc, cbrt, sqrt, expm1, log, log2, log1p, log10# + * # func = cos, sin, tan, acos, asin, atan, cosh, sinh, tanh, acosh, asinh, atanh, fabs, floor, ceil, rint, trunc, cbrt, sqrt, expm1, log, log2, log1p, log10# + * # VML = Cos, Sin, Tan, Acos, Asin, Atan, Cosh, Sinh, Tanh, Acosh, Asinh, Atanh, Abs, Floor, Ceil, Rint, Trunc, Cbrt, Sqrt, Expm1, Ln, Log2, Log1p, Log10# */ void mkl_umath_@TYPE@_@kind@(char **args, const npy_intp *dimensions, const npy_intp *steps, void *NPY_UNUSED(func)) @@ -931,37 +931,6 @@ mkl_umath_@TYPE@_@kind@(char **args, const npy_intp *dimensions, const npy_intp } /**end repeat1**/ -void -mkl_umath_@TYPE@_log2(char **args, const npy_intp *dimensions, const npy_intp *steps, void *NPY_UNUSED(func)) -{ - const int contig = IS_UNARY_CONT(@type@, @type@); - const int disjoint_or_same = DISJOINT_OR_SAME(args[0], args[1], dimensions[0], sizeof(@type@)); - const int can_vectorize = contig && disjoint_or_same; - int ignore_fpstatus = 0; - - if (can_vectorize && dimensions[0] > VML_TRANSCEDENTAL_THRESHOLD) - { - ignore_fpstatus = 1; - CHUNKED_VML_CALL2(v@s@Log2, dimensions[0], @type@, args[0], args[1]); - /* v@s@Log2(dimensions[0], (@type@*) args[0], (@type@*) args[1]); */ - } - else { - UNARY_LOOP_DISPATCH( - @type@, @type@ - , - can_vectorize - , - const @type@ in1 = *(@type@ *)ip1; - const int invalid_cases = in1 < 0 || in1 == 0 || npy_isnan(in1) || in1 == -NPY_INFINITY; - ignore_fpstatus |= invalid_cases; - *(@type@ *)op1 = log2@c@(in1); - ) - } - if (ignore_fpstatus) { - feclearexcept(FE_DIVBYZERO | FE_INVALID); - } -} - void mkl_umath_@TYPE@_absolute(char **args, const npy_intp *dimensions, const npy_intp *steps, void *NPY_UNUSED(func)) { From 633d08f8c1bc105b2d96f7b1568914ddb942743b Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Thu, 11 Sep 2025 08:21:51 -0500 Subject: [PATCH 2/2] Add PR to the changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index aece0d7..839bbcc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed * Dropped support for `maximum` and `minimum` [gh-104](https://github.com/IntelPython/mkl_umath/pull/104) +* Used a common umath loop for `log2` function to match NumPy [gh-109](https://github.com/IntelPython/mkl_umath/pull/109) ## [0.2.0] - 2025-06-03 This release updates `mkl_umath` to be aligned with both numpy-1.26.x and numpy-2.x.x.