Conditional branches of expressions #125
MilesCranmer
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Here's how you can search for conditional branches of expressions (including if statements) using PySR:
The
::T
where {T}
is just Julia notation for templating a function for arbitrary type. It's not normally required, but I want to declare the type of the0
there as the same type, so I used it.Using the
Piecewise
function, SymPy should correctly convert the output of this to an executable function when calling lambdify.A simpler version which is also valid:
"cond(x, y) = x >= 0 ? y : 0*y"
. Though this might be slower due to the type conversions.Beta Was this translation helpful? Give feedback.
All reactions