Skip to content

Commit 2db04e6

Browse files
committed
add new complex vm functions
1 parent ac0e478 commit 2db04e6

File tree

2 files changed

+37
-36
lines changed

2 files changed

+37
-36
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
### Added
1010
* 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)
11+
* Added mkl implementation for complex data-types of `conjugate` and `absolute` functions [gh-86](https://github.com/IntelPython/mkl_umath/pull/86)
1112

12-
## [0.2.0] (06/DD/2025)
13+
## [0.2.0] (06/03/2025)
1314
This release updates `mkl_umath` to be aligned with both numpy-1.26.x and numpy-2.x.x.
1415

1516
### Added

mkl_umath/src/mkl_umath_loops.c.src

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
* when these conditions are not met VML functions may produce incorrect output
130130
*/
131131
#define DISJOINT_OR_SAME(p1, p2, n, s) (((p1) == (p2)) || ((p2) + (n)*(s) < (p1)) || ((p1) + (n)*(s) < (p2)) )
132+
#define DISJOINT_OR_SAME_TWO_DTYPES(p1, p2, n, s1, s2) (((p1) == (p2)) || ((p2) + (n)*(s2) < (p1)) || ((p1) + (n)*(s1) < (p2)) )
132133

133134
/*
134135
* include vectorized functions and dispatchers
@@ -316,8 +317,7 @@ mkl_umath_@TYPE@_exp(char **args, const npy_intp *dimensions, const npy_intp *st
316317
can_vectorize
317318
,
318319
const @type@ in1 = *(@type@ *)ip1;
319-
const int invalid_cases = npy_isnan(in1) || in1 == NPY_INFINITY || in1 == -NPY_INFINITY;
320-
ignore_fpstatus |= (invalid_cases ? 1 : 0);
320+
ignore_fpstatus = npy_isnan(in1) || in1 == NPY_INFINITY || in1 == -NPY_INFINITY;
321321
*(@type@ *)op1 = @scalarf@(in1);
322322
)
323323
}
@@ -355,8 +355,7 @@ mkl_umath_@TYPE@_exp2(char **args, const npy_intp *dimensions, const npy_intp *s
355355
can_vectorize
356356
,
357357
const @type@ in1 = *(@type@ *)ip1;
358-
const int invalid_cases = npy_isnan(in1) || in1 == NPY_INFINITY || in1 == -NPY_INFINITY;
359-
ignore_fpstatus |= (invalid_cases ? 1 : 0);
358+
ignore_fpstatus = npy_isnan(in1) || in1 == NPY_INFINITY || in1 == -NPY_INFINITY;
360359
*(@type@ *)op1 = @scalarf@(in1);
361360
)
362361
}
@@ -493,8 +492,7 @@ mkl_umath_@TYPE@_log2(char **args, const npy_intp *dimensions, const npy_intp *s
493492
can_vectorize
494493
,
495494
const @type@ in1 = *(@type@ *)ip1;
496-
const int invalid_cases = in1 < 0 || in1 == 0 || npy_isnan(in1) || in1 == -NPY_INFINITY;
497-
ignore_fpstatus |= (invalid_cases ? 1 : 0);
495+
ignore_fpstatus = in1 < 0 || in1 == 0 || npy_isnan(in1) || in1 == -NPY_INFINITY;
498496
*(@type@ *)op1 = @scalarf@(in1);
499497
)
500498
}
@@ -2124,10 +2122,9 @@ mkl_umath_@TYPE@_remainder(char **args, const npy_intp *dimensions, const npy_in
21242122
BINARY_LOOP {
21252123
const @type@ in1 = *(@type@ *)ip1;
21262124
const @type@ in2 = *(@type@ *)ip2;
2127-
int invalid_cases = !npy_isnan(in1) && in2 == 0;
2128-
invalid_cases |= (in1 == NPY_INFINITY || in1 == -NPY_INFINITY) && !npy_isnan(in2);
2129-
invalid_cases |= (in1 != NPY_INFINITY && in1 != -NPY_INFINITY) && (in2 == NPY_INFINITY || in2 == -NPY_INFINITY);
2130-
ignore_fpstatus |= (invalid_cases ? 1 : 0);
2125+
ignore_fpstatus = !npy_isnan(in1) && in2 == 0;
2126+
ignore_fpstatus |= (in1 == NPY_INFINITY || in1 == -NPY_INFINITY) && !npy_isnan(in2);
2127+
ignore_fpstatus |= (in1 != NPY_INFINITY && in1 != -NPY_INFINITY) && (in2 == NPY_INFINITY || in2 == -NPY_INFINITY);
21312128
divmod@c@(in1, in2, (@type@ *)op1);
21322129
}
21332130
}
@@ -2376,10 +2373,10 @@ mkl_umath_@TYPE@_ldexp_long(char **args, const npy_intp *dimensions, const npy_i
23762373
* complex types
23772374
* #TYPE = CFLOAT, CDOUBLE#
23782375
* #ftype = npy_float, npy_double#
2376+
* #type = npy_cfloat, npy_cdouble#
23792377
* #c = f, #
2380-
* #C = F, #
2381-
* #s = s, d#
2382-
* #SUPPORTED_BY_VML = 1, 1#
2378+
* #C = F, #
2379+
* #s = c, z#
23832380
*/
23842381

23852382
/* similar to pairwise sum of real floats */
@@ -2659,44 +2656,47 @@ mkl_umath_@TYPE@__ones_like(char **args, const npy_intp *dimensions, const npy_i
26592656
}
26602657
}
26612658

2662-
/* TODO: USE MKL */
26632659
void
26642660
mkl_umath_@TYPE@_conjugate(char **args, const npy_intp *dimensions, const npy_intp *steps, void *NPY_UNUSED(func)) {
2665-
UNARY_LOOP {
2666-
const @ftype@ in1r = ((@ftype@ *)ip1)[0];
2667-
const @ftype@ in1i = ((@ftype@ *)ip1)[1];
2668-
((@ftype@ *)op1)[0] = in1r;
2669-
((@ftype@ *)op1)[1] = -in1i;
2670-
}
2661+
const int contig = IS_UNARY_CONT(@type@, @type@);
2662+
const int disjoint_or_same = DISJOINT_OR_SAME(args[0], args[1], dimensions[0], sizeof(@type@));
2663+
const int can_vectorize = contig && disjoint_or_same;
2664+
2665+
if(can_vectorize && dimensions[0] > VML_TRANSCEDENTAL_THRESHOLD) {
2666+
CHUNKED_VML_CALL2(v@s@Conj, dimensions[0], @type@, args[0], args[1]);
2667+
/* v@s@Conj(dimensions[0], (@type@*) args[0], (@type@*) args[1]); */
2668+
} else {
2669+
UNARY_LOOP {
2670+
const @ftype@ in1r = ((@ftype@ *)ip1)[0];
2671+
const @ftype@ in1i = ((@ftype@ *)ip1)[1];
2672+
((@ftype@ *)op1)[0] = in1r;
2673+
((@ftype@ *)op1)[1] = -in1i;
2674+
}
2675+
}
26712676
}
26722677

2673-
/* TODO: USE MKL */
26742678
void
26752679
mkl_umath_@TYPE@_absolute(char **args, const npy_intp *dimensions, const npy_intp *steps, void *NPY_UNUSED(func))
26762680
{
2681+
const int contig = IS_UNARY_CONT(@type@, @ftype@);
2682+
const int disjoint_or_same = DISJOINT_OR_SAME_TWO_DTYPES(args[0], args[1], dimensions[0], sizeof(@type@), sizeof(@ftype@));
2683+
const int can_vectorize = contig && disjoint_or_same;
26772684
int ignore_fpstatus = 0;
2678-
2679-
// FIXME: abs function VML for complex numbers breaks FFT test_basic.py
2680-
//if(steps[0]/2 == sizeof(@ftype@) && steps[1] == sizeof(@ftype@) && dimensions[0] > VML_TRANSCEDENTAL_THRESHOLD) {
2681-
#if @SUPPORTED_BY_VML@
2682-
if(0 == 1) {
2685+
2686+
if(can_vectorize && dimensions[0] > VML_TRANSCEDENTAL_THRESHOLD) {
26832687
ignore_fpstatus = 1;
2684-
CHUNKED_VML_CALL2(v@s@Abs, dimensions[0], @ftype@, args[0], args[1]);
2685-
/* v@s@Abs(dimensions[0], (@ftype@ *) args[0], (@ftype@ *) args[1]); */
2686-
} else
2687-
#endif
2688-
{
2688+
CHUNKED_VML_CALL2(v@s@Abs, dimensions[0], @type@, args[0], args[1]);
2689+
/* v@s@Abs(dimensions[0], (@type@*) args[0], (@type@*) args[1]); */
2690+
} else {
26892691
UNARY_LOOP {
26902692
const @ftype@ in1r = ((@ftype@ *)ip1)[0];
26912693
const @ftype@ in1i = ((@ftype@ *)ip1)[1];
2692-
if(in1r == 0.0 && in1i == 0.0){
2693-
ignore_fpstatus = 1;
2694-
}
2694+
ignore_fpstatus = npy_isnan(in1r) && npy_isnan(in1i);
26952695
*((@ftype@ *)op1) = hypot@c@(in1r, in1i);
26962696
}
26972697
}
26982698
if(ignore_fpstatus) {
2699-
feclearexcept(FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW | FE_INVALID);
2699+
feclearexcept(FE_INVALID);
27002700
}
27012701
}
27022702

0 commit comments

Comments
 (0)