Skip to content

Commit

Permalink
Merge pull request #54 from pymc-devs/invcdf_fix
Browse files Browse the repository at this point in the history
Generalizes utils.invcdf to accept n-dim arrays
  • Loading branch information
Chris Fonnesbeck committed Aug 19, 2015
2 parents ee9c834 + 8104089 commit 7c42d16
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
14 changes: 13 additions & 1 deletion pymc/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from pymc import six
xrange = six.moves.xrange


class test_logp_of_set(TestCase):
A = Normal('A', 0, 1)
B = Gamma('B', 1, 1)
Expand Down Expand Up @@ -73,6 +72,19 @@ def test_normcdf_log_3d_input(self):
x = arange(8.).reshape(2, 2, 2)
utils.normcdf(x, log=True)

class test_invcdf_input_shape(TestCase):

def test_invcdf_1d_input(self):
x = random.random(8)
utils.invcdf(x)

def test_invcdf_2d_input(self):
x = random.random((2, 4))
utils.invcdf(x)

def test_invcdf_3d_input(self):
x = random.random((2, 2, 2))
utils.invcdf(x)

if __name__ == '__main__':
C = nose.config.Config(verbosity=1)
Expand Down
5 changes: 3 additions & 2 deletions pymc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,9 @@ def lognormcdf(x, mu, tau):

def invcdf(x):
"""Inverse of normal cumulative density function."""
x = np.atleast_1d(x)
return np.array([flib.ppnd16(y, 1) for y in x])
x_flat = np.ravel(x)
x_trans = np.array([flib.ppnd16(y, 1) for y in x_flat])
return np.reshape(x_trans, np.shape(x))


def ar1_gen(rho, mu, sigma, size=1):
Expand Down

0 comments on commit 7c42d16

Please sign in to comment.