File tree Expand file tree Collapse file tree 3 files changed +39
-5
lines changed
numpy/_core/include/numpy Expand file tree Collapse file tree 3 files changed +39
-5
lines changed Original file line number Diff line number Diff line change @@ -220,6 +220,19 @@ using the NumPy types. You can still write cython code using the ``c.real`` and
220
220
``c.imag `` attributes (using the native typedefs), but you can no longer use
221
221
in-place operators ``c.imag += 1 `` in Cython's c++ mode.
222
222
223
+ Because NumPy 2 now includes ``complex.h `` code that uses a variable named
224
+ ``I `` may see an error such as
225
+
226
+ .. code-block::C
227
+ error: expected ‘)’ before ‘__extension__’
228
+ double I,
229
+
230
+ to use the name ``I `` requires an ``#undef I `` now.
231
+
232
+ .. note ::
233
+ NumPy 2.0.1 briefly included the ``#undef I `` to help users not already
234
+ including ``complex.h ``.
235
+
223
236
224
237
Changes to namespaces
225
238
=====================
Original file line number Diff line number Diff line change @@ -1611,3 +1611,29 @@ for completeness and assistance in understanding the code.
1611
1611
``arrayobject.h `` header. This type is not exposed to Python and
1612
1612
could be replaced with a C-structure. As a Python type it takes
1613
1613
advantage of reference- counted memory management.
1614
+
1615
+
1616
+ NumPy C-API and C complex
1617
+ =========================
1618
+ When you use the NumPy C-API, you will have access to complex real declarations
1619
+ ``npy_cdouble `` and ``npy_cfloat ``, which are declared in terms of the C
1620
+ standard types from ``complex.h ``. Unfortunately, ``complex.h `` contains
1621
+ `#define I ...`` (where the actual definition depends on the compiler), which
1622
+ means that any downstream user that does ``#include <numpy/arrayobject.h> ``
1623
+ could get ``I `` defined, and using something like declaring ``double I; `` in
1624
+ their code will result in an obscure compiler error like
1625
+
1626
+ .. code-block::C
1627
+ error: expected ‘)’ before ‘__extension__’
1628
+ double I,
1629
+
1630
+ This error can be avoided by adding::
1631
+
1632
+ #undef I
1633
+
1634
+ to your code.
1635
+
1636
+ .. versionchanged :: 2.0
1637
+ The inclusion of ``complex.h `` was new in NumPy 2, so that code defining
1638
+ a different ``I `` may not have required the ``#undef I `` on older versions.
1639
+ NumPy 2.0.1 briefly included the ``#under I ``
Original file line number Diff line number Diff line change @@ -379,11 +379,6 @@ typedef struct
379
379
380
380
#include <complex.h>
381
381
382
- // Downstream libraries like sympy would like to use I
383
- // see https://github.com/numpy/numpy/issues/26787
384
- #ifdef I
385
- #undef I
386
- #endif
387
382
388
383
#if defined(_MSC_VER ) && !defined(__INTEL_COMPILER )
389
384
typedef _Dcomplex npy_cdouble ;
You can’t perform that action at this time.
0 commit comments