Closed
Description
It seems that there is a regression after the merging of #13163
We had the case in scikit-learn where the parameter p
passed to np.random.choice
is a view on a 2D C-contiguous array. In the previous version, p
was surely contiguous in memory:
numpy/numpy/random/mtrand/mtrand.pyx
Line 1135 in a306a62
This has changed with the following:
Line 782 in afc6981
However, no flag enforcing the contiguity is passed. It implies a failure when computing the kahan_sum
which expect a contiguous array.
I assume that it should be possible to pass the NPY_ARRAY_C_CONTIGUOUS
flag when calling the PyArray_FROM_OTF
function.
Reproducing code example:
import numpy as np
p = np.repeat(np.array([[0.1, 0, 0.3, 0.6, 0]]).T, 3, axis=1)
x = np.random.choice(5, 3, p=p[:, 1])
print(x)
Error message:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/tmp/tmp.py in <module>
3 p = np.repeat(np.array([[0.1, 0, 0.3, 0.6, 0]]).T, 3, axis=1)
4
----> 5 x = np.random.choice(5, 3, p=p[:, 1])
6 print(x)
mtrand.pyx in numpy.random.mtrand.RandomState.choice()
ValueError: probabilities do not sum to 1
Numpy/Python version information:
In [12]: np.__version__
Out[12]: '1.17.0.dev0+495de50'