Skip to content

Commit e922abb

Browse files
Use np.asarray to ensure output of np.add is array, not scalar
``` Python 3.10.4 (main, Sep 1 2022, 10:54:42) [GCC 11.2.0] Type 'copyright', 'credits' or 'license' for more information IPython 8.5.0 -- An enhanced Interactive Python. Type '?' for help. In [1]: import numpy as np In [2]: a = np.asarray(3, dtype='long') In [3]: b = np.asarray(2, dtype='long') In [4]: c = np.add(a, b) In [5]: type(c) Out[5]: numpy.int64 ``` It appears this behavior existed with prior versions of Python and numpy as well, but Cython likely became stricter, and no longer allows assigning NumPy scalars to variables of `cnp.ndarray` type.
1 parent 780fde9 commit e922abb

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

mkl_random/mklrand.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ cdef object vec_disc0_array(irk_state *state, irk_disc0_vec func, object size,
426426
return array
427427

428428
cdef object vec_long_disc0_array(
429-
irk_state *state, irk_disc0_vec_long func,
429+
irk_state *state, irk_disc0_vec_long func,
430430
object size, object lock
431431
):
432432
cdef long *array_data
@@ -5044,7 +5044,7 @@ cdef class RandomState:
50445044
raise ValueError("nbad < 0")
50455045
if np.any(np.less(onsample, 1)):
50465046
raise ValueError("nsample < 1")
5047-
otot = np.add(ongood, onbad);
5047+
otot = np.asarray(np.add(ongood, onbad));
50485048
if np.any(np.less_equal(otot, 0)):
50495049
raise ValueError("Number of balls in each urn should not exceed 2147483647")
50505050
if np.any(np.less(otot,onsample)):

0 commit comments

Comments
 (0)