Skip to content

add new complex vm functions #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 29 additions & 22 deletions mkl_umath/src/mkl_umath_loops.c.src
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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];
Expand Down
Loading