Skip to content

Commit 7c42d16

Browse files
author
Chris Fonnesbeck
committed
Merge pull request #54 from pymc-devs/invcdf_fix
Generalizes utils.invcdf to accept n-dim arrays
2 parents ee9c834 + 8104089 commit 7c42d16

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

pymc/tests/test_utils.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from pymc import six
99
xrange = six.moves.xrange
1010

11-
1211
class test_logp_of_set(TestCase):
1312
A = Normal('A', 0, 1)
1413
B = Gamma('B', 1, 1)
@@ -73,6 +72,19 @@ def test_normcdf_log_3d_input(self):
7372
x = arange(8.).reshape(2, 2, 2)
7473
utils.normcdf(x, log=True)
7574

75+
class test_invcdf_input_shape(TestCase):
76+
77+
def test_invcdf_1d_input(self):
78+
x = random.random(8)
79+
utils.invcdf(x)
80+
81+
def test_invcdf_2d_input(self):
82+
x = random.random((2, 4))
83+
utils.invcdf(x)
84+
85+
def test_invcdf_3d_input(self):
86+
x = random.random((2, 2, 2))
87+
utils.invcdf(x)
7688

7789
if __name__ == '__main__':
7890
C = nose.config.Config(verbosity=1)

pymc/utils.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,9 @@ def lognormcdf(x, mu, tau):
445445

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

451452

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

0 commit comments

Comments
 (0)