Skip to content

Commit

Permalink
Use structs for C++ on MSVC
Browse files Browse the repository at this point in the history
Co-authored-by: mattip <[email protected]>
  • Loading branch information
lysnikolaou and mattip committed Jul 21, 2023
1 parent ddcdf86 commit 6ce134b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
20 changes: 10 additions & 10 deletions numpy/core/include/numpy/ndarraytypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -964,20 +964,20 @@ typedef int (PyArray_FinalizeFunc)(PyArrayObject *, PyObject *);
#define PyArray_MAX(a,b) (((a)>(b))?(a):(b))
#define PyArray_MIN(a,b) (((a)<(b))?(a):(b))

#define PyArray_CLT(p,q, type) NPY_##type##_GET_REAL(&(p)) == NPY_##type##_GET_REAL(&(q)) \
#define PyArray_CLT(p,q, type) (NPY_##type##_GET_REAL(&(p)) == NPY_##type##_GET_REAL(&(q)) \
? NPY_##type##_GET_IMAG(&(p)) < NPY_##type##_GET_IMAG(&(q)) \
: NPY_##type##_GET_REAL(&(p)) < NPY_##type##_GET_REAL(&(q))
#define PyArray_CGT(p,q, type) NPY_##type##_GET_REAL(&(p)) == NPY_##type##_GET_REAL(&(q)) \
: NPY_##type##_GET_REAL(&(p)) < NPY_##type##_GET_REAL(&(q)))
#define PyArray_CGT(p,q, type) (NPY_##type##_GET_REAL(&(p)) == NPY_##type##_GET_REAL(&(q)) \
? NPY_##type##_GET_IMAG(&(p)) > NPY_##type##_GET_IMAG(&(q)) \
: NPY_##type##_GET_REAL(&(p)) > NPY_##type##_GET_REAL(&(q))
#define PyArray_CLE(p,q, type) NPY_##type##_GET_REAL(&(p)) == NPY_##type##_GET_REAL(&(q)) \
: NPY_##type##_GET_REAL(&(p)) > NPY_##type##_GET_REAL(&(q)))
#define PyArray_CLE(p,q, type) (NPY_##type##_GET_REAL(&(p)) == NPY_##type##_GET_REAL(&(q)) \
? NPY_##type##_GET_IMAG(&(p)) <= NPY_##type##_GET_IMAG(&(q)) \
: NPY_##type##_GET_REAL(&(p)) <= NPY_##type##_GET_REAL(&(q))
#define PyArray_CGE(p,q, type) NPY_##type##_GET_REAL(&(p)) == NPY_##type##_GET_REAL(&(q)) \
: NPY_##type##_GET_REAL(&(p)) <= NPY_##type##_GET_REAL(&(q)))
#define PyArray_CGE(p,q, type) (NPY_##type##_GET_REAL(&(p)) == NPY_##type##_GET_REAL(&(q)) \
? NPY_##type##_GET_IMAG(&(p)) >= NPY_##type##_GET_IMAG(&(q)) \
: NPY_##type##_GET_REAL(&(p)) >= NPY_##type##_GET_REAL(&(q))
#define PyArray_CEQ(p,q, type) (p) == (q)
#define PyArray_CNE(p,q, type) (p) != (q)
: NPY_##type##_GET_REAL(&(p)) >= NPY_##type##_GET_REAL(&(q)))
#define PyArray_CEQ(p,q, type) ((p) == (q))
#define PyArray_CNE(p,q, type) ((p) != (q))

/*
* C API: consists of Macros and functions. The MACROS are defined
Expand Down
17 changes: 17 additions & 0 deletions numpy/core/include/numpy/npy_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,27 @@ typedef Py_hash_t npy_hash_t;


#if defined(_MSC_VER) && !defined(__INTEL_COMPILER)
#ifdef __cplusplus
typedef struct
{
double _Val[2];
} npy_cdouble;

typedef struct
{
float _Val[2];
} npy_cfloat;

typedef struct
{
long double _Val[2];
} npy_clongdouble;
#else
#include <complex.h>
typedef _Dcomplex npy_cdouble;
typedef _Fcomplex npy_cfloat;
typedef _Lcomplex npy_clongdouble;
#endif
#else /* !defined(__cplusplus) && (!defined(_MSC_VER) || defined(__INTEL_COMPILER)) */
#ifdef __cplusplus
extern "C++" {
Expand Down
4 changes: 2 additions & 2 deletions numpy/core/src/umath/clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ _NPY_MIN(npy_cfloat a, npy_cfloat b, npy::complex_tag const &)
: (b);
}

#if NPY_SIZEOF_COMPLEX_LONGDOUBLE != NPY_SIZEOF_COMPLEX_DOUBLE
#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && NPY_SIZEOF_COMPLEX_LONGDOUBLE != NPY_SIZEOF_COMPLEX_DOUBLE
npy_clongdouble
_NPY_MIN(npy_clongdouble a, npy_clongdouble b, npy::complex_tag const &)
{
Expand All @@ -97,7 +97,7 @@ _NPY_MAX(npy_cfloat a, npy_cfloat b, npy::complex_tag const &)
: (b);
}

#if NPY_SIZEOF_COMPLEX_LONGDOUBLE != NPY_SIZEOF_COMPLEX_DOUBLE
#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && NPY_SIZEOF_COMPLEX_LONGDOUBLE != NPY_SIZEOF_COMPLEX_DOUBLE
npy_clongdouble
_NPY_MAX(npy_clongdouble a, npy_clongdouble b, npy::complex_tag const &)
{
Expand Down

0 comments on commit 6ce134b

Please sign in to comment.