wesselb / lab

A generic interface for linear algebra backends
MIT License
70 stars 5 forks source link

A buggy implementation of `randcat` for numpy #10

Closed stoprightthere closed 1 year ago

stoprightthere commented 1 year ago

The implementation of lab.numpy.random.randcat is incorrect.

Example

import lab as B
import numpy as np

ps = np.r_[1., 0., 0., 0.]
B.randcat(ps, 1)    # should be 0 because it has probability 1

Expected output: array([0]) Got output: array([3])

Suggested fix: use np.random.choice.

wesselb commented 1 year ago

Hey @stoprightthere ! Thanks for raising this, and I'm sorry for the slow reply. Been away on holiday and to a conference, and I'm only now catching up on email.

Ouch, this is an extremely embarassing bug. This is definitely not the intended behaviour. I will look into it!

wesselb commented 1 year ago

This should be fixed on the latest release v1.5.4. I've added a test that explicitly checks your above example.

stoprightthere commented 1 year ago

Hey @wesselb , thanks for fixing the issue!