Skip to content

Remove deprecated PyTensor function functionality and reduce overhead #1351

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
17 changes: 7 additions & 10 deletions doc/library/compile/io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@ The ``inputs`` argument to ``pytensor.function`` is a list, containing the ``Var
can be set by ``kwarg``, and its value can be accessed by
``self.<name>``. The default value is ``None``.

``value``: literal or ``Container``. The initial/default value for this
``value``: ``Container``. The initial value for this
input. If update is ``None``, this input acts just like
an argument with a default value in Python. If update is not ``None``,
changes to this
value will "stick around", whether due to an update or a user's
explicit action.
changes to this value will "stick around", whether due to an update
or a user's explicit action.

``update``: Variable instance. This expression Variable will
replace ``value`` after each function call. The default value is
Expand Down Expand Up @@ -73,18 +72,16 @@ The ``inputs`` argument to ``pytensor.function`` is a list, containing the ``Var
overwriting its content without being aware of it).


Value: initial and default values
---------------------------------
Update
------

A non-None `value` argument makes an In() instance an optional parameter
of the compiled function. For example, in the following code we are
defining an arity-2 function ``inc``.
We can define an update to modify the value

>>> import pytensor.tensor as pt
>>> from pytensor import function
>>> from pytensor.compile.io import In
>>> u, x, s = pt.scalars('u', 'x', 's')
>>> inc = function([u, In(x, value=3), In(s, update=(s+x*u), value=10.0)], [])
>>> inc = function([u, In(x), In(s, update=(s+x*u)], [])

Since we provided a ``value`` for ``s`` and ``x``, we can call it with just a value for ``u`` like this:

Expand Down
6 changes: 1 addition & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,8 @@ exclude = ["doc/", "pytensor/_version.py"]
docstring-code-format = true

[tool.ruff.lint]
select = ["B905", "C", "E", "F", "I", "UP", "W", "RUF", "PERF", "PTH", "ISC", "T20", "NPY201"]
select = ["C", "E", "F", "I", "UP", "W", "RUF", "PERF", "PTH", "ISC", "T20", "NPY201"]
ignore = ["C408", "C901", "E501", "E741", "RUF012", "PERF203", "ISC001"]
unfixable = [
# zip-strict: the auto-fix adds `strict=False` but we might want `strict=True` instead
"B905",
]


[tool.ruff.lint.isort]
Expand Down
5 changes: 2 additions & 3 deletions pytensor/compile/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,6 @@ def clone(self):

def perform(self, node, inputs, outputs):
variables = self.fn(*inputs)
assert len(variables) == len(outputs)
# strict=False because asserted above
for output, variable in zip(outputs, variables, strict=False):
# strict=None because we are in a hot loop
for output, variable in zip(outputs, variables):
output[0] = variable
Loading
Loading