Skip to content
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 custom trace_input methods for LinearAlgebra matrix types #147

Closed
adrhill opened this issue Aug 6, 2024 · 1 comment · Fixed by #165
Closed

Add custom trace_input methods for LinearAlgebra matrix types #147

adrhill opened this issue Aug 6, 2024 · 1 comment · Fixed by #165
Labels
bug Something isn't working input tracing Issue regarding creation of tracers from input.

Comments

@adrhill
Copy link
Owner

adrhill commented Aug 6, 2024

As shown in #146, if the user inputs a 3x3 Diagonal matrix, we currently create a dense Matrix of tracers with input indices 1 to 9.
This leads to non-conservative sparsity patterns:

julia> x = Diagonal(rand(3))
3×3 Diagonal{Float64, Vector{Float64}}:
 0.674044             
          0.683069    
                   0.387561

julia> jacobian_sparsity(sum, x, TracerSparsityDetector())
1×9 SparseArrays.SparseMatrixCSC{Bool, Int64} with 9 stored entries:
 1  1  1  1  1  1  1  1  1

Even worse, the user-provided function is called with a Matrix of tracers instead of a Diagonal of tracers, likely hitting an entirely different method.

For the example above, a custom trace_input method should be implemented that returns a Diagonal matrix of three tracers with indices 1, 5 and 9.

@adrhill adrhill added bug Something isn't working enhancement New feature or request labels Aug 6, 2024
@adrhill
Copy link
Owner Author

adrhill commented Aug 6, 2024

While Diagonal is easily fixed, Symmetric is much more tricky:
For a 3x3 Symmetric matrix, we actually want to create 9 tracers with input indices 1 to 9. However, the returned matrix can't be symmetric!

@adrhill adrhill added input tracing Issue regarding creation of tracers from input. and removed enhancement New feature or request labels Aug 7, 2024
@adrhill adrhill linked a pull request Aug 13, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working input tracing Issue regarding creation of tracers from input.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant