Hi,
first of all, note that the NumPy bindings are now maintained by the NumPy
project, not by Cython:
https://github.com/numpy/numpy/blob/main/numpy/__init__.cython-30.pxd
Jerry Morrison schrieb am 02.11.23 um 06:57:
> This seems to be a behavior change:
> An `np.npy_intp` function parameter rejects a float value in Cython
> 3.0.0 - 3.05 vs. truncating the float to an integer in Cython 0.29.34.
"npy_intp" is declared as "Py_ssize_t", which uses the Python "__index__"
protocol for the conversion, not "__int__".
https://github.com/numpy/numpy/blob/7a4f6b0c11f9b5c13aa9e463a2a8f2c040a6daed/numpy/__init__.cython-30.pxd#L27
> Example: numpy.random.multinomial
> <
https://github.com/numpy/numpy/blob/cdfbdf428d9df9c7119cecae323512a4cd3f57b7/numpy/random/mtrand.pyx#L4256>(self,
> np.npy_intp n, object pvals, size=None)
>
> ----- Test case -----
> import numpy as np
> np.random.multinomial(20.0, [1/6.]*6, size=1)
> TypeError: 'float' object cannot be interpreted as an integer
> ----------
This is to be expected. You'd probably want to use your own integer
conversion/rounding in your code to make sure that you get the integer
value that you want.
Stefan