Skip to content

near-infinite loop on ppc64 in np.random.hypergeometric #14457

Closed
@ahaldane

Description

@ahaldane

Running the following command on ppc64(be) hangs due to a near-infinite loop:

>>> np.random.hypergeometric([1,2,2], [2], [2])

Appears to be related to new code in #13761, perhaps @WarrenWeckesser has an idea. See in particular frame #2 below. It appears a value is negative but the code expects it not to be.

gdb stack trace after breaking during hang:

#0  __log (x=-25811282) at ../math/w_log.c:27
#1  0x0ea14754 in loggam (x=-160848451)
    at numpy/random/src/distributions/distributions.c:503
#2  0x0ea1232c in random_hypergeometric_hrua (bitgen_state=0xf76272c8, good=1, 
    bad=2, sample=268080756)
    at numpy/random/src/legacy/legacy-distributions.c:266
#3  0x0ea12798 in random_hypergeometric_original (bitgen_state=0xf76272c8, 
    good=1, bad=2, sample=268080756)
    at numpy/random/src/legacy/legacy-distributions.c:315
#4  0x0ea12844 in legacy_random_hypergeometric (bitgen_state=0xf76272c8, 
    good=1, bad=2, sample=8858015348)
    at numpy/random/src/legacy/legacy-distributions.c:334
#5  0x0e96db10 in __pyx_f_5numpy_6random_6common_discrete_broadcast_iii (
    __pyx_v_func=0xea127e8 <legacy_random_hypergeometric>, 
    __pyx_v_state=0xf76272c8, __pyx_v_size=0x104520e0 <_Py_NoneStruct>, 
    __pyx_v_lock=0xf7647140, __pyx_v_a_arr=0xf754c638, 
    __pyx_v_a_name=0xf7643fa0, 
    __pyx_v_a_constraint=__pyx_e_5numpy_6random_6common_CONS_NON_NEGATIVE, 
    __pyx_v_b_arr=0xf754c570, __pyx_v_b_name=0xf7643f80, 
    __pyx_v_b_constraint=__pyx_e_5numpy_6random_6common_CONS_NON_NEGATIVE, 
    __pyx_v_c_arr=0xf754c548, __pyx_v_c_name=0xf7643fe0, 
    __pyx_v_c_constraint=__pyx_e_5numpy_6random_6common_CONS_GTE_1)
    at numpy/random/common.c:13924
---Type <return> to continue, or q <return> to quit---frame 1
#6  0x0e9e7c5c in __pyx_pf_5numpy_6random_6mtrand_11RandomState_96hypergeometric (__pyx_v_self=0xf76272b8, __pyx_v_ngood=0xf7551058, __pyx_v_nbad=0xf754ffa8, 
    __pyx_v_nsample=0xf754fe68, __pyx_v_size=0x104520e0 <_Py_NoneStruct>)
    at numpy/random/mtrand.c:15834
#7  0x0e9e536c in __pyx_pw_5numpy_6random_6mtrand_11RandomState_97hypergeometric (__pyx_v_self=0xf76272b8, __pyx_args=0xf7535b48, __pyx_kwds=0x0)
    at numpy/random/mtrand.c:15312
#8  0x1006ca2c in PyCFunction_Call ()

A little bit of gdb exploration so far:

(gdb) frame 1
#1  0x0ea14754 in loggam (x=-160848451)
    at numpy/random/src/distributions/distributions.c:503
(gdb) p n
$2 = 160848458
(gdb) p x
$3 = -160848451
(gdb) frame 2
#2  0x0ea1232c in random_hypergeometric_hrua (bitgen_state=0xf76272c8, good=1, 
    bad=2, sample=268080756)
    at numpy/random/src/legacy/legacy-distributions.c:266
266	  d10 = (loggam(d9 + 1) + loggam(mingoodbad - d9 + 1) + loggam(m - d9 + 1) +
(gdb) l
261	  d5 = 1.0 - d4;
262	  d6 = m * d4 + 0.5;
263	  d7 = sqrt((double)(popsize - m) * sample * d4 * d5 / (popsize - 1) + 0.5);
264	  d8 = D1 * d7 + D2;
265	  d9 = (RAND_INT_TYPE)floor((double)(m + 1) * (mingoodbad + 1) / (popsize + 2));
266	  d10 = (loggam(d9 + 1) + loggam(mingoodbad - d9 + 1) + loggam(m - d9 + 1) +
267	         loggam(maxgoodbad - m + d9 + 1));
268	  d11 = MIN(MIN(m, mingoodbad) + 1.0, floor(d6 + 16 * d7));
269	  /* 16 for 16-decimal-digit precision in D1 and D2 */
270	
(gdb) p d9
$4 = -107232301

The failing line 266 in the last bit of code is from #13761, but I haven't read it well enough yet to know what it should do.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions