Skip to content

Add code block example for switch function #620

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

Closed
wants to merge 2 commits into from
Closed
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
16 changes: 15 additions & 1 deletion pytensor/tensor/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,21 @@ def cast(x, dtype: Union[str, np.dtype]) -> TensorVariable:

@scalar_elemwise
def switch(cond, ift, iff):
"""if cond then ift else iff"""
r"""
if cond then ift else iff

Examples
--------
.. code-block:: python

import pymc as pm
with pm.Model() as model:
x = pm.Normal('x', mu=0, sigma=1)
mu = pm.math.switch(x > 0, 2.0, -2.0)

x1 = pm.Normal('x1', mu=mu, sigma=1)

"""


where = switch
Expand Down