Skip to content

Commit

Permalink
Add test for conversion from dist.Delta to Delta
Browse files Browse the repository at this point in the history
  • Loading branch information
fritzo committed Mar 10, 2019
1 parent ef7358b commit 3825deb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion funsor/delta.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Delta(Funsor):
Normalized delta distribution binding a single variable.
:param str name: Name of the bound variable.
:param Funsor value: Value of the bound variable.
:param Funsor point: Value of the bound variable.
:param Funsor log_density: Optional log density to be added when evaluating
at a point. This is needed to make :class:`Delta` closed under
differentiable substitution.
Expand Down
9 changes: 9 additions & 0 deletions test/test_distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import funsor
import funsor.distributions as dist
from funsor.delta import Delta
from funsor.domains import bint, reals
from funsor.gaussian import Gaussian
from funsor.terms import Variable
Expand Down Expand Up @@ -80,6 +81,14 @@ def delta(v, log_density, value):
assert_close(actual, expected)


def test_delta_delta():
v = Variable('v', reals(2))
point = Tensor(torch.randn(2))
log_density = Tensor(torch.tensor(0.5))
d = dist.Delta(point, log_density, v)
assert d is Delta('v', point, log_density)


def test_normal_defaults():
loc = Variable('loc', reals())
scale = Variable('scale', reals())
Expand Down

0 comments on commit 3825deb

Please sign in to comment.