-
-
Notifications
You must be signed in to change notification settings - Fork 236
Offset fix for ctarget matrix equations #736
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
Conversation
|
Can this get a test? |
YingboMa
left a comment
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.
This logic is too hard to understand just from the code. I don't understand what
@variables x[1:2,1:2] y[1:4]
eqs = x[:] .~ y
build_function(eqs, y, target=ModelingToolkit.CTarget())is supposed to do.
|
The test failure on master got fixed though? We should update the branch when there's a passing master. |
|
Yeah I think the issue is that the CTarget, MATLABTarget, and StanTarget are old and need some work. |
|
I wouldn't want to merge this. It basically impossible to understand how Also, build_function(eqs, y, ...)is just wrong. We shouldn't support it. |
It is just wrong, these days. It's the MTK function signature from 2 years ago. It still lives on in the non-Julia targets because it hasn't been updated. And those haven't been deleted because they are still there because they are used in a bunch of tests and benchmarks. We need to completely overhaul them. |
|
Permission to close this PR in favor of the draft PR #746? |
|
I was thinking the same thing. Yeah doing the full update of CTarget is great and I'm happy you're interested in taking it on. Thanks! |
Overview
get_symnumber(just a copy of existing code, moved to a function)_build_function(::CTarget).More Detail
Before this PR (
master), calling the following code would result in an error.Upon further inspection, this issue was caused on
master:build_function.jl:500.Because the none of the output variables
xappear in the state vector provided (here the state vector provided is the second argument tobuild_function,y), thefindfirstcall returnsnothing.Changes
findfirstcode in one new place, so I moved it to a new function calledget_symnumber, and replaced that line (line 500) with a call toget_symnumbernumbered_expr(::Equation...), I changed thelhsandrhsoffsets to the following logic:lhsoffset is equal to1 + the index of the output vector element, andrhsoffset is equal to the index of each state vector element_build_function(::CTarget...), I added the following logic at the top:offset = index of output - 2)offset = -1)Conclusion
I'm definintely open to other implementations, but this was the least-optrusive solution I could think of. With this PR, the output of the following code block is as expected.