Skip to content

Commit

Permalink
first step to support numpy 2.0
Browse files Browse the repository at this point in the history
call np.import_array https://github.com/cython/cython/wiki/tutorials-numpy#c-api-initialization

to avoid the following error:

ultranest/mlfriends.pyx:1: in init ultranest.mlfriends
    # cython: language_level=3,annotate=True,profile=True,fast_fail=True,warning_errors=True
E   ImportError: numpy.core.multiarray failed to import (auto-generated because you didn't call 'numpy.import_array()' after cimporting numpy; use '<void>numpy._import_array' to disable if you are certain you don't need it).
------------------------------- Captured stderr --------------------------------

A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.0.0 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.

If you are a user of the module, the easiest solution will be to
downgrade to 'numpy<2' or try to upgrade the affected module.
We expect that some modules will need time to support NumPy 2.

also see
https://numpy.org/doc/stable//dev/depending_on_numpy.html#numpy-2-abi-handling
https://numpy.org/doc/stable//numpy_2_0_migration_guide.html
  • Loading branch information
JohannesBuchner committed Jun 20, 2024
1 parent 766392c commit ed0dd46
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions ultranest/mlfriends.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Includes

import numpy as np
cimport numpy as np
np.import_array()
from numpy import pi
cimport cython
from cython.cimports.libc.math import sqrt
Expand Down
1 change: 1 addition & 0 deletions ultranest/stepfuncs.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Efficient helper functions for vectorized step-samplers

import numpy as np
cimport numpy as np
np.import_array()
from numpy import nan as np_nan
cimport cython
from cython.parallel import prange
Expand Down

0 comments on commit ed0dd46

Please sign in to comment.