GeoStat-Framework / GSTools

GSTools - A geostatistical toolbox: random fields, variogram estimation, covariance models, kriging and much more
https://geostat-framework.org
GNU Lesser General Public License v3.0
544 stars 71 forks source link

add numpy 2 support #340

Closed MuellerSeb closed 4 months ago

MuellerSeb commented 6 months ago

Closes: #337 #345

Numpy 2.0.0rc1 was released: https://pypi.org/project/numpy/2.0.0c1 and is officially usable to build extensions.

Additional doc fixes

32bit builds were removed with this PR. I think we can happily drop that.

MuellerSeb commented 5 months ago

A lot of the tests fail because of emcee and this issue: https://github.com/dfm/emcee/issues/509

Other errors have a problem with these lines in estimator.pyx:

    cdef long[:, :] counts = np.zeros((d_max, len(bin_edges)-1), dtype=long)
    cdef long[:] counts = np.zeros(len(bin_edges)-1, dtype=long)
    cdef long[:] counts = np.zeros(k_max, dtype=long)
    cdef long[:] counts = np.zeros(k_max, dtype=long)

and raise

E   ValueError: Buffer dtype mismatch, expected 'long' but got 'long long'

This only occurs on windows and is related to this: https://numpy.org/devdocs/numpy_2_0_migration_guide.html#windows-default-integer

One other category of errors is:

If using `np.array(obj, copy=False)` replace it with `np.asarray(obj)` to allow a copy when needed (no behavior change in NumPy 1.x).

np.array(..., copy=False) is used in krige/base.py, 3 times in variogram/variogram.py and 3 times in tools/geometric.py

In order to mimic the ndmin=... feature, we could replace these with e.g.:

pos = np.atleast_2d(np.asarray(pos, dtype=np.double))
MuellerSeb commented 5 months ago

All issues fixed. Only remaining issues should be solved upstream in emcee with: https://github.com/dfm/emcee/pull/510