Skip to content

Commit f746eeb

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

File tree

2 files changed

+31
-23
lines changed

2 files changed

+31
-23
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 `abs` 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: 29 additions & 22 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
@@ -2376,10 +2377,10 @@ mkl_umath_@TYPE@_ldexp_long(char **args, const npy_intp *dimensions, const npy_i
23762377
* complex types
23772378
* #TYPE = CFLOAT, CDOUBLE#
23782379
* #ftype = npy_float, npy_double#
2380+
* #type = npy_cfloat, npy_cdouble#
23792381
* #c = f, #
2380-
* #C = F, #
2381-
* #s = s, d#
2382-
* #SUPPORTED_BY_VML = 1, 1#
2382+
* #C = F, #
2383+
* #s = c, z#
23832384
*/
23842385

23852386
/* 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
26592660
}
26602661
}
26612662

2662-
/* TODO: USE MKL */
26632663
void
26642664
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-
}
2665+
const int contig = IS_UNARY_CONT(@type@, @type@);
2666+
const int disjoint_or_same = DISJOINT_OR_SAME(args[0], args[1], dimensions[0], sizeof(@type@));
2667+
const int can_vectorize = contig && disjoint_or_same;
2668+
2669+
if(can_vectorize && dimensions[0] > VML_TRANSCEDENTAL_THRESHOLD) {
2670+
printf("MKL was used for complex conjugate\n");
2671+
CHUNKED_VML_CALL2(v@s@Conj, dimensions[0], @type@, args[0], args[1]);
2672+
/* v@s@Conj(dimensions[0], (@type@*) args[0], (@type@*) args[1]); */
2673+
} else {
2674+
UNARY_LOOP {
2675+
const @ftype@ in1r = ((@ftype@ *)ip1)[0];
2676+
const @ftype@ in1i = ((@ftype@ *)ip1)[1];
2677+
((@ftype@ *)op1)[0] = in1r;
2678+
((@ftype@ *)op1)[1] = -in1i;
2679+
}
2680+
}
26712681
}
26722682

2673-
/* TODO: USE MKL */
26742683
void
26752684
mkl_umath_@TYPE@_absolute(char **args, const npy_intp *dimensions, const npy_intp *steps, void *NPY_UNUSED(func))
26762685
{
26772686
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) {
2683-
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-
{
2687+
const int contig = IS_UNARY_CONT(@type@, @ftype@);
2688+
const int disjoint_or_same = DISJOINT_OR_SAME_TWO_DTYPES(args[0], args[1], dimensions[0], sizeof(@type@), sizeof(@ftype@));
2689+
const int can_vectorize = contig && disjoint_or_same;
2690+
2691+
if(can_vectorize && dimensions[0] > VML_TRANSCEDENTAL_THRESHOLD) {
2692+
printf("MKL was used for complex absolute\n");
2693+
CHUNKED_VML_CALL2(v@s@Abs, dimensions[0], @type@, args[0], args[1]);
2694+
/* v@s@Abs(dimensions[0], (@type@*) args[0], (@type@*) args[1]); */
2695+
} else {
26892696
UNARY_LOOP {
26902697
const @ftype@ in1r = ((@ftype@ *)ip1)[0];
26912698
const @ftype@ in1i = ((@ftype@ *)ip1)[1];

0 commit comments

Comments
 (0)