Merged
Conversation
It's time we finally handle #531, https://github.com/SciML/ModelingToolkit.jl/issues/532, and https://discourse.julialang.org/t/differentiation-method-for-element-wise-abs-function-applied-on-operation-types-in-modelingtoolkit-jl/45867/4 . This PR creates a `ModelingToolkit.ifelse` with derivative fixes for `abs` to make it so standard conditional code can work. While tracing cannot correctly make these operations, this would at least allow directly written symbolic code to handle conditions, so we're at least as good (or bad) as TensorFlow.
Member
Author
|
@chriselrod should we make a IfElse.jl package so that way we use the same one as LoopVectorization.jl? @c42f should we inject this as Base.ifelse? |
Member
Author
using ModelingToolkit
function func!(du,u)
du = abs.(u)
end
@variables du[1:2] u[1:2]
func!(du,u)
sjac= ModelingToolkit.sparsejacobian(vec(du),vec(u));
function func!(du,u)
for j = 1:2
du[j] = abs(u[j])
end
end
@variables du[1:2] u[1:2]
func!(du,u)
sjac= ModelingToolkit.sparsejacobian(vec(du),vec(u));works with this PR. |
YingboMa
reviewed
Sep 2, 2020
Member
YingboMa
left a comment
There was a problem hiding this comment.
LGTM. I agree that it's better to make a new "IfElse.jl" package so that we can overload the same function.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
It's time we finally handle #531, https://github.com/SciML/ModelingToolkit.jl/issues/532, and https://discourse.julialang.org/t/differentiation-method-for-element-wise-abs-function-applied-on-operation-types-in-modelingtoolkit-jl/45867/4 . This PR creates a
ModelingToolkit.ifelsewith derivative fixes forabsto make it so standard conditional code can work. While tracing cannot correctly make these operations, this would at least allow directly written symbolic code to handle conditions, so we're at least as good (or bad) as TensorFlow.