Skip to content

Don't broadcast in alltrue #1452

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions pymc3/distributions/dist_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ def bound(logp, *conditions):


def alltrue(vals):
ret = 1
for c in vals:
ret = ret * (1 * c)
return ret
return tt.all([tt.all(1 * val) for val in vals])


def logpow(x, m):
Expand Down
36 changes: 36 additions & 0 deletions pymc3/tests/test_dist_math.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import numpy as np
import theano.tensor as tt

from ..distributions.dist_math import alltrue


def test_alltrue():
assert alltrue([]).eval()
assert alltrue([True]).eval()
assert alltrue([tt.ones(10)]).eval()
assert alltrue([tt.ones(10),
5 * tt.ones(101)]).eval()
assert alltrue([np.ones(10),
5 * tt.ones(101)]).eval()
assert alltrue([np.ones(10),
True,
5 * tt.ones(101)]).eval()
assert alltrue([np.array([1, 2, 3]),
True,
5 * tt.ones(101)]).eval()

assert not alltrue([False]).eval()
assert not alltrue([tt.zeros(10)]).eval()
assert not alltrue([True,
False]).eval()
assert not alltrue([np.array([0, -1]),
tt.ones(60)]).eval()
assert not alltrue([np.ones(10),
False,
5 * tt.ones(101)]).eval()


def test_alltrue_shape():
vals = [True, tt.ones(10), tt.zeros(5)]

assert alltrue(vals).eval().shape == ()