Skip to content
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
6 changes: 6 additions & 0 deletions pymc/pytensorf.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,12 @@
def __call__(self, state):
return self.f(**state)

def __getattr__(self, item):
"""Allow access to the original function attributes."""
if item == "f":
return self.f

Check warning on line 606 in pymc/pytensorf.py

View check run for this annotation

Codecov / codecov/patch

pymc/pytensorf.py#L606

Added line #L606 was not covered by tests
Comment on lines +605 to +606
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't needed I didn't push the last version :(

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pymc is a fast-moving, cutting-edge open source package

return getattr(self.f, item)


class CallableTensor:
"""Turns a symbolic variable with one input into a function that returns symbolic arguments with the one variable replaced with the input."""
Expand Down
15 changes: 15 additions & 0 deletions tests/test_pytensorf.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from pymc.exceptions import NotConstantValueError
from pymc.logprob.utils import ParameterValueError
from pymc.pytensorf import (
PointFunc,
collect_default_updates,
compile,
constant_fold,
Expand Down Expand Up @@ -780,3 +781,17 @@ def test_hessian_sign_change_warning(func):
res_neg = func(f, vars=[x])
res = func(f, vars=[x], negate_output=False)
assert equal_computations([res_neg], [-res])


def test_point_func():
x, y = pt.vectors("x", "y")
outs = x * 2 + y**2
f = compile([x, y], outs)

point_f = PointFunc(f)
np.testing.assert_allclose(point_f({"y": [3], "x": [2]}), [4 + 9])

# Check we can access other methods of the wrapped pytensor function
dprint_res = point_f.dprint(file="str")
expected_dprint_res = point_f.f.dprint(file="str")
assert dprint_res == expected_dprint_res