GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — ENH: Replace npy complex structs with native complex types by lysnikolaou · Pull Request #24085 · numpy/numpy

ENH: Replace npy complex structs with native complex types #24085

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.

Sign up for GitHub

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

Merged
mattip merged 46 commits into numpy:main from lysnikolaou:real-imag-remove
Jul 31, 2023

Uh oh!

There was an error while loading. Please reload this page.

Merged

ENH: Replace npy complex structs with native complex types #24085

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
fd455d2
Replace npy_c* structs with native types
lysnikolaou May 16, 2023
9eb7053
Format
lysnikolaou Jun 21, 2023
d2b5512
Fix f2py
lysnikolaou Jun 22, 2023
4a246bb
Rename complex to singlecomplex in all f2c'd files
lysnikolaou Jun 29, 2023
5c38f35
Fix complex init
lysnikolaou Jun 29, 2023
b240b10
Fix uninitialized values in arraytypes
lysnikolaou Jun 29, 2023
725a8d6
Make GET_REAL and GET_IMAG into inline functions that use unions
lysnikolaou Jun 30, 2023
6050aad
Fix call to memset with std::complex in umath_linalg
lysnikolaou Jun 30, 2023
a7fea9b
Fix call to SET_REAL/SET_IMAG in umath matmul
lysnikolaou Jun 30, 2023
8749082
Remove c99 compat layer from npymath
lysnikolaou Jun 30, 2023
ea282c7
Fix log10 and log2
lysnikolaou Jun 30, 2023
a926e01
Fix initialization of complex in npy_math_complex
lysnikolaou Jun 30, 2023
3d29fb1
Merge branch 'main' into real-imag-remove
lysnikolaou Jun 30, 2023
2b2c597
First attempt to fix CI // Add static inline
lysnikolaou Jul 4, 2023
ad60798
Fix inline setters
lysnikolaou Jul 5, 2023
f65c643
Initialize complex numbers
lysnikolaou Jul 5, 2023
bf3fa21
Fix implicit declaration of CMPLX on musllinux
lysnikolaou Jul 5, 2023
57e204b
Hopefully fix Windows stuff
lysnikolaou Jul 6, 2023
c24f998
Remove cast from INIT macros
lysnikolaou Jul 7, 2023
c38cab6
Remove direct complex arithmetic due to Windows
lysnikolaou Jul 7, 2023
5f4ea8a
Fix complex init in more places
lysnikolaou Jul 7, 2023
d2e8b41
Fix complex init in scalarmath
lysnikolaou Jul 7, 2023
0ef48b3
Use latest Cython in CI
lysnikolaou Jul 10, 2023
c4e9b34
Change pyproject.toml to build with latest Cython
lysnikolaou Jul 10, 2023
e972bc8
Demote linkage errors to warnings in pyodide build
lysnikolaou Jul 12, 2023
45b15a1
Revert changes to lapack_lite
lysnikolaou Jul 12, 2023
2118738
Necessary changes for complex not to be a reserved keyword
lysnikolaou Jul 12, 2023
8c77d69
Move complex utilities to npy_math.h [wheel build]
lysnikolaou Jul 12, 2023
7377f24
Remove necessity for INIT macro [wheel build]
lysnikolaou Jul 14, 2023
55a903b
Merge branch 'main' into real-imag-remove
lysnikolaou Jul 14, 2023
045a8cd
Fix Windows-CL workflow; update to latest cython 0.29.x
lysnikolaou Jul 14, 2023
ddcdf86
Necessary changes to only use C99 complex types (not std::complex)
lysnikolaou Jul 17, 2023
6ce134b
Use structs for C++ on MSVC
lysnikolaou Jul 21, 2023
1a89522
Fix when _NPY_MAX/MIN is defined
lysnikolaou Jul 21, 2023
f66f6e4
Revert changes to CFLAGS in pyodide build; improve formatting
lysnikolaou Jul 21, 2023
f6a516f
Merge branch 'main' into real-imag-remove
lysnikolaou Jul 25, 2023
013a8d4
Revert changes to Cython version now that cython3 is the default
lysnikolaou Jul 25, 2023
5757057
Merge branch 'main' into real-imag-remove
lysnikolaou Jul 25, 2023
7508afd
Remove unnecessary inline functions, use npy_c* inline functions instead
lysnikolaou Jul 25, 2023
19bdf90
Merge branch 'main' into real-imag-remove
lysnikolaou Jul 26, 2023
04f4ce1
Add const wherever possible
lysnikolaou Jul 26, 2023
991c4b1
Add complex compat header
lysnikolaou Jul 27, 2023
e2ad3c8
Change compat header to not use versions
lysnikolaou Jul 27, 2023
2d25d2a
Improve comment in compat header
lysnikolaou Jul 31, 2023
530cbc5
Address feedback
lysnikolaou Jul 31, 2023
2665d56
Merge branch 'main' into real-imag-remove
lysnikolaou Jul 31, 2023
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
Prev Previous commit
Next Next commit
Initialize complex numbers
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

@lysnikolaou
lysnikolaou committed Jul 5, 2023
commit f65c6434742b52f09bb1b6f47caaa7749ce8ca5a

There are no files selected for viewing

9 changes: 9 additions & 0 deletions 9 numpy/core/include/numpy/npy_common.h
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -392,14 +392,23 @@ extern "C++" {
typedef _Dcomplex npy_cdouble;
typedef _Fcomplex npy_cfloat;
typedef _Lcomplex npy_clongdouble;
#define NPY_CDOUBLE_INIT(real, imag) _CBuild(real, imag)
#define NPY_CFLOAT_INIT(real, imag) _FCBuild(real, imag)
#define NPY_CLONGDOUBLE_INIT(real, imag) _LCBuild(real, imag)
#elif defined(__cplusplus) /* && (!defined(_MSC_VER) || defined(__INTEL_COMPILER)) */
typedef std::complex<double> npy_cdouble;
typedef std::complex<float> npy_cfloat;
typedef std::complex<longdouble_t> npy_clongdouble;
Comment thread
lysnikolaou marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

#define NPY_CDOUBLE_INIT(real, imag) std::complex<double>(real, imag)
#define NPY_CFLOAT_INIT(real, imag) std::complex<float>(real, imag)
#define NPY_CLONGDOUBLE_INIT(real, imag) std::complex<longdouble_t>(real, imag)
#else /* !defined(__cplusplus) && (!defined(_MSC_VER) || defined(__INTEL_COMPILER)) */
typedef complex double npy_cdouble;
typedef complex float npy_cfloat;
typedef complex longdouble_t npy_clongdouble;
#define NPY_CDOUBLE_INIT(real, imag) CMPLX(real, imag)
#define NPY_CFLOAT_INIT(real, imag) CMPLXF(real, imag)
#define NPY_CLONGDOUBLE_INIT(real, imag) CMPLXL(real, imag)
#endif

#ifndef __cplusplus
Expand Down
6 changes: 3 additions & 3 deletions 6 numpy/core/include/numpy/npy_math.h
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -359,23 +359,23 @@ NPY_INPLACE npy_longdouble npy_heavisidel(npy_longdouble x, npy_longdouble h0);

static inline npy_cdouble npy_cpack(double x, double y)
{
npy_cdouble z;
npy_cdouble z = NPY_CDOUBLE_INIT(0.0, 0.0);
NPY_CDOUBLE_SET_REAL(&z, x);
NPY_CDOUBLE_SET_IMAG(&z, y);
return z;
}

static inline npy_cfloat npy_cpackf(float x, float y)
{
npy_cfloat z;
npy_cfloat z = NPY_CFLOAT_INIT(0.0f, 0.0f);
NPY_CFLOAT_SET_REAL(&z, x);
NPY_CFLOAT_SET_IMAG(&z, y);
return z;
}

static inline npy_clongdouble npy_cpackl(npy_longdouble x, npy_longdouble y)
{
npy_clongdouble z;
npy_clongdouble z = NPY_CLONGDOUBLE_INIT(0.0l, 0.0l);
NPY_CLONGDOUBLE_SET_REAL(&z, x);
NPY_CLONGDOUBLE_SET_IMAG(&z, y);
return z;
Expand Down
9 changes: 6 additions & 3 deletions 9 numpy/core/src/multiarray/arraytypes.c.src
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -442,13 +442,14 @@ static PyObject *
* #type = npy_cfloat, npy_cdouble, npy_clongdouble#
* #ftype = npy_float, npy_double, npy_longdouble#
* #kind = CFloat, CDouble, CLongDouble#
* #c = f, , l#
*/
NPY_NO_EXPORT int
@NAME@_setitem(PyObject *op, void *ov, void *vap)
{
PyArrayObject *ap = vap;
Py_complex oop;
@type@ temp;
@type@ temp = NPY_@NAME@_INIT(0.0@c@, 0.0@c@);

if (PyArray_IsZeroDim(op)) {
return convert_to_scalar_and_retry(op, ov, vap, @NAME@_setitem);
Expand Down Expand Up @@ -1934,6 +1935,7 @@ BOOL_scan(FILE *fp, npy_bool *ip, void *NPY_UNUSED(ignore),
/**begin repeat
* #fname = CFLOAT, CDOUBLE#
* #type = npy_cfloat, npy_cdouble#
* #c = f, #
*/
static int
@fname@_scan(FILE *fp, @type@ *ip, void *NPY_UNUSED(ignore),
Expand All @@ -1943,7 +1945,7 @@ static int
int ret_real, ret_imag;

ret_real = NumPyOS_ascii_ftolf(fp, &result);
@type@ output;
@type@ output = NPY_@fname@_INIT(0.0@c@, 0.0@c@);
// Peek next character
char next = getc(fp);
if ((next == '+') || (next == '-')) {
Expand Down Expand Up @@ -2077,6 +2079,7 @@ BOOL_fromstr(char *str, void *ip, char **endptr,
/**begin repeat
* #fname = CFLOAT, CDOUBLE#
* #type = npy_cfloat, npy_cdouble#
* #c = f, #
*/
static int
@fname@_fromstr(char *str, void *ip, char **endptr,
Expand All @@ -2085,7 +2088,7 @@ static int
double result;

result = NumPyOS_ascii_strtod(str, endptr);
@type@ output;
@type@ output = NPY_@fname@_INIT(0.0@c@, 0.0@c@);

if (endptr && ((*endptr[0] == '+') || (*endptr[0] == '-'))) {
// Imaginary component specified
Expand Down
4 changes: 2 additions & 2 deletions 4 numpy/core/src/multiarray/compiled_base.c
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ arr_interp_complex(PyObject *NPY_UNUSED(self), PyObject *const *args, Py_ssize_t

const npy_double *dx, *dz;
const npy_cdouble *dy;
npy_cdouble lval, rval;
npy_cdouble lval = NPY_CDOUBLE_INIT(0.0, 0.0), rval = NPY_CDOUBLE_INIT(0.0, 0.0);
npy_cdouble *dres, *slopes = NULL;

NPY_BEGIN_THREADS_DEF;
Expand Down Expand Up @@ -817,7 +817,7 @@ arr_interp_complex(PyObject *NPY_UNUSED(self), PyObject *const *args, Py_ssize_t
dres[i] = dy[j];
}
else {
npy_cdouble slope;
npy_cdouble slope = NPY_CDOUBLE_INIT(0.0, 0.0);
if (slopes != NULL) {
slope = slopes[j];
}
Expand Down
4 changes: 2 additions & 2 deletions 4 numpy/core/src/multiarray/textreading/conversions.c
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ npy_to_cfloat(PyArray_Descr *descr,
if (!success) {
return -1;
}
npy_complex64 val;
npy_complex64 val = NPY_CFLOAT_INIT(0.0f, 0.0f);
NPY_CFLOAT_SET_REAL(&val, (float) real);
NPY_CFLOAT_SET_IMAG(&val, (float) imag);
memcpy(dataptr, &val, sizeof(npy_complex64));
Expand All @@ -268,7 +268,7 @@ npy_to_cdouble(PyArray_Descr *descr,
if (!success) {
return -1;
}
npy_complex128 val;
npy_complex128 val = NPY_CDOUBLE_INIT(0.0, 0.0);
NPY_CDOUBLE_SET_REAL(&val, real);
NPY_CDOUBLE_SET_IMAG(&val, imag);
memcpy(dataptr, &val, sizeof(npy_complex128));
Expand Down
9 changes: 2 additions & 7 deletions 9 numpy/core/src/npymath/npy_math_complex.c.src
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ static const volatile npy_float tiny = 3.9443045e-31f;
* #ctype = npy_cfloat,npy_cdouble,npy_clongdouble#
* #c = f, , l#
* #C = F, , L#
* #NAME = CFLOAT, CDOUBLE, CLONGDOUBLE#
* #TMAX = FLT_MAX, DBL_MAX, LDBL_MAX#
* #TMIN = FLT_MIN, DBL_MIN, LDBL_MIN#
* #TMANT_DIG = FLT_MANT_DIG, DBL_MANT_DIG, LDBL_MANT_DIG#
Expand All @@ -64,13 +65,7 @@ static const volatile npy_float tiny = 3.9443045e-31f;
/*==========================================================
* Constants
*=========================================================*/
#if !defined(__cplusplus) && defined(_MSC_VER) && !defined(__INTEL_COMPILER)
static const @ctype@ c_1@c@ = {1.0@C@, 0.0@C@};
#elif defined(__cplusplus)
static const @ctype@ c_1@c@ (1.0@C@, 0.0@C@);
#else
static const @ctype@ c_1@c@ = 1.0@C@;
#endif
static const @ctype@ c_1@c@ = NPY_@NAME@_INIT(1.0@C@, 0.0@C@);

/*==========================================================
* Helper functions
Expand Down
2 changes: 1 addition & 1 deletion 2 numpy/core/src/umath/funcs.inc.src
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ nc_exp@c@(@ctype@ *x, @ctype@ *r)
static void
nc_exp2@c@(@ctype@ *x, @ctype@ *r)
{
@ctype@ a;
@ctype@ a = NPY_@NAME@_INIT(0.0@c@, 0.0@c@);
NPY_@NAME@_SET_REAL(&a, NPY_@NAME@_GET_REAL(x)*NPY_LOGE2@c@);
NPY_@NAME@_SET_IMAG(&a, NPY_@NAME@_GET_IMAG(x)*NPY_LOGE2@c@);
nc_exp@c@(&a, r);
Expand Down
4 changes: 2 additions & 2 deletions 4 numpy/core/src/umath/loops.c.src
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ PyUFunc_F_F_As_D_D(char **args, npy_intp const *dimensions, npy_intp const *step
typedef void func_type(npy_cdouble *, npy_cdouble *);
func_type *f = (func_type *)func;
UNARY_LOOP {
npy_cdouble tmp, out;
npy_cdouble tmp = NPY_CDOUBLE_INIT(0.0, 0.0), out = NPY_CDOUBLE_INIT(0.0, 0.0);
NPY_CDOUBLE_SET_REAL(&tmp, (double)((float *)ip1)[0]);
NPY_CDOUBLE_SET_IMAG(&tmp, (double)((float *)ip1)[1]);
f(&tmp, &out);
Expand All @@ -173,7 +173,7 @@ PyUFunc_FF_F_As_DD_D(char **args, npy_intp const *dimensions, npy_intp const *st
typedef void func_type(npy_cdouble *, npy_cdouble *, npy_cdouble *);
func_type *f = (func_type *)func;
BINARY_LOOP {
npy_cdouble tmp1, tmp2, out;
npy_cdouble tmp1 = NPY_CDOUBLE_INIT(0.0, 0.0), tmp2 = NPY_CDOUBLE_INIT(0.0, 0.0), out = NPY_CDOUBLE_INIT(0.0, 0.0);
NPY_CDOUBLE_SET_REAL(&tmp1, (double)((float *)ip1)[0]);
NPY_CDOUBLE_SET_IMAG(&tmp1, (double)((float *)ip1)[1]);
NPY_CDOUBLE_SET_REAL(&tmp2, (double)((float *)ip2)[0]);
Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.