diff --git a/CHANGELOG.md b/CHANGELOG.md index 91e5da6..999f2d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,8 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added * Added mkl implementation for floating point data-types of `exp2`, `log2`, `fabs`, `copysign`, `nextafter`, `fmax`, `fmin` and `remainder` functions [gh-81](https://github.com/IntelPython/mkl_umath/pull/81) +* Added mkl implementation for complex data-types of `conjugate` and `abs` functions [gh-86](https://github.com/IntelPython/mkl_umath/pull/86) -## [0.2.0] (06/DD/2025) +## [0.2.0] (06/03/2025) This release updates `mkl_umath` to be aligned with both numpy-1.26.x and numpy-2.x.x. ### Added diff --git a/mkl_umath/src/mkl_umath_loops.c.src b/mkl_umath/src/mkl_umath_loops.c.src index 6bee4b2..e6045f5 100644 --- a/mkl_umath/src/mkl_umath_loops.c.src +++ b/mkl_umath/src/mkl_umath_loops.c.src @@ -129,6 +129,7 @@ * when these conditions are not met VML functions may produce incorrect output */ #define DISJOINT_OR_SAME(p1, p2, n, s) (((p1) == (p2)) || ((p2) + (n)*(s) < (p1)) || ((p1) + (n)*(s) < (p2)) ) +#define DISJOINT_OR_SAME_TWO_DTYPES(p1, p2, n, s1, s2) (((p1) == (p2)) || ((p2) + (n)*(s2) < (p1)) || ((p1) + (n)*(s1) < (p2)) ) /* * include vectorized functions and dispatchers @@ -2376,10 +2377,10 @@ mkl_umath_@TYPE@_ldexp_long(char **args, const npy_intp *dimensions, const npy_i * complex types * #TYPE = CFLOAT, CDOUBLE# * #ftype = npy_float, npy_double# + * #type = npy_cfloat, npy_cdouble# * #c = f, # - * #C = F, # - * #s = s, d# - * #SUPPORTED_BY_VML = 1, 1# + * #C = F, # + * #s = c, z# */ /* similar to pairwise sum of real floats */ @@ -2659,33 +2660,39 @@ mkl_umath_@TYPE@__ones_like(char **args, const npy_intp *dimensions, const npy_i } } -/* TODO: USE MKL */ void mkl_umath_@TYPE@_conjugate(char **args, const npy_intp *dimensions, const npy_intp *steps, void *NPY_UNUSED(func)) { - UNARY_LOOP { - const @ftype@ in1r = ((@ftype@ *)ip1)[0]; - const @ftype@ in1i = ((@ftype@ *)ip1)[1]; - ((@ftype@ *)op1)[0] = in1r; - ((@ftype@ *)op1)[1] = -in1i; - } + 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; + + if(can_vectorize && dimensions[0] > VML_TRANSCEDENTAL_THRESHOLD) { + printf("MKL was used for complex conjugate\n"); + CHUNKED_VML_CALL2(v@s@Conj, dimensions[0], @type@, args[0], args[1]); + /* v@s@Conj(dimensions[0], (@type@*) args[0], (@type@*) args[1]); */ + } else { + UNARY_LOOP { + const @ftype@ in1r = ((@ftype@ *)ip1)[0]; + const @ftype@ in1i = ((@ftype@ *)ip1)[1]; + ((@ftype@ *)op1)[0] = in1r; + ((@ftype@ *)op1)[1] = -in1i; + } + } } -/* TODO: USE MKL */ void mkl_umath_@TYPE@_absolute(char **args, const npy_intp *dimensions, const npy_intp *steps, void *NPY_UNUSED(func)) { int ignore_fpstatus = 0; - - // FIXME: abs function VML for complex numbers breaks FFT test_basic.py - //if(steps[0]/2 == sizeof(@ftype@) && steps[1] == sizeof(@ftype@) && dimensions[0] > VML_TRANSCEDENTAL_THRESHOLD) { -#if @SUPPORTED_BY_VML@ - if(0 == 1) { - ignore_fpstatus = 1; - CHUNKED_VML_CALL2(v@s@Abs, dimensions[0], @ftype@, args[0], args[1]); - /* v@s@Abs(dimensions[0], (@ftype@ *) args[0], (@ftype@ *) args[1]); */ - } else -#endif - { + const int contig = IS_UNARY_CONT(@type@, @ftype@); + const int disjoint_or_same = DISJOINT_OR_SAME_TWO_DTYPES(args[0], args[1], dimensions[0], sizeof(@type@), sizeof(@ftype@)); + const int can_vectorize = contig && disjoint_or_same; + + if(can_vectorize && dimensions[0] > VML_TRANSCEDENTAL_THRESHOLD) { + printf("MKL was used for complex absolute\n"); + CHUNKED_VML_CALL2(v@s@Abs, dimensions[0], @type@, args[0], args[1]); + /* v@s@Abs(dimensions[0], (@type@*) args[0], (@type@*) args[1]); */ + } else { UNARY_LOOP { const @ftype@ in1r = ((@ftype@ *)ip1)[0]; const @ftype@ in1i = ((@ftype@ *)ip1)[1];