-
-
Notifications
You must be signed in to change notification settings - Fork 74
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
Add get_variables
dispatch for Reaction
#855
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are going to add it we should probably add the in-place version and then just call that for the allocating version. It might also be worth using a Set
and converting to a vector at the end instead. See https://github.com/JuliaSymbolics/Symbolics.jl/blob/1da13fdc375fccd6cd0a779a53b06be4ec7a54ec/src/utils.jl#L47-L79
Actually, we already have an inplace version that takes |
In practise, I just used what Symbolics define for get_variables(eq::Equation) = unique(vcat(get_variables(eq.lhs), get_variables(eq.rhs))) and I figured the above definition was most faithful to that. Little bit uncertain exactly what rewrite you want, but if you have a different way to phrase the function content I am happy to update. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few minor changes. Once addressed and tests pass feel free to merge.
src/reaction.jl
Outdated
append!(set, rx.substrates) | ||
append!(set, rx.products) | ||
for stoichs in (rx.substoich, rx.prodstoich), stoich in stoichs | ||
get_variables!(set, stoich) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this check if stoich
is a Symbolic? If not there is no reason to call get_variables!
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that is definitely an improvement.
3f4fa76
to
a55f782
Compare
The
get_variables
function is currently defined forEquation
s but notReaction
s. I've added it. It goes through all fields, checking and adds all symbolic variables to an output vector.