-
-
Notifications
You must be signed in to change notification settings - Fork 195
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
Fix initialization of W for static arrays #1269
base: master
Are you sure you want to change the base?
Conversation
I should add that a tricky complication here is that the definition in https://github.com/JuliaDiff/ForwardDiff.jl/blob/c4487d5620983581f6a63284cca3599b8dacf203/src/jacobian.jl#L97-L105 isn't sound so the issue here is only triggered by the tests when LabelledArrays is loaded before ForwardDiff. Ref JuliaDiff/ForwardDiff.jl#468 |
No. With auto switch methods (the default in DiffEq), this can be an order of magnitude more than the entire computation if it's a large non-stiff system.
How so? The Jacobian is just a static array and static arrays are fine? |
Fair enough. I'll try to patch the bug in a different way.
I don't think is a good approach. It's too easy to make errors when you try to guess the return types like this. The only robust way of doing this is to base it on the instances. If computing the instances of the stiff solver is too costly for non-stiff problems then the initialization of the stiff solver should probably be made lazy somehow.
The Jacobian of an |
Making the cache construction lazy would be really cool since it would allow non-stiff ODEs with auto-switch to essentially have no overhead. Right now they always build the caches for the Jacobians and such even if they aren't used.
That's odd? using LabelledArrays
x = SLVector(a=1,b=2,c=3)
x.*x'
3×3 SArray{Tuple{3,3},Int64,2,9} with indices SOneTo(3)×SOneTo(3):
1 2 3
2 4 6
3 6 9 |
Just for the reference, I figured out what was going on here. For all but the 1x1 case, the Jacobian of the ODE system will be a |
To trigger this, I'm using LabelledArrays in the AD tests I recently added. I'm not sure the
ArrayInterface.lu_instance
approach can be made completely robust and, at least, it isn't right forLabelledArrays
right now. The setup costs of computing the LU once should be small. Generally, I think it would be useful if initialization was based on the actual values since it's so easy to get the types wrong when you do it heuristically instead of using the instances.