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

Increase sparsity for Diagonal inputs #165

Merged
merged 6 commits into from
Aug 15, 2024
Merged

Increase sparsity for Diagonal inputs #165

merged 6 commits into from
Aug 15, 2024

Conversation

adrhill
Copy link
Owner

@adrhill adrhill commented Aug 13, 2024

By having trace_input create a Diagonal matrix of tracers with only the indices from diagind, the sparsity of patterns can be increased by a lot on Diagonal inputs:

image

Previously, this would have returned a dense pattern of ones (see #147).

@adrhill adrhill linked an issue Aug 13, 2024 that may be closed by this pull request
@codecov-commenter
Copy link

codecov-commenter commented Aug 13, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 87.24490% with 25 lines in your changes missing coverage. Please review.

Project coverage is 91.83%. Comparing base (199899d) to head (cec44b8).
Report is 1 commits behind head on main.

Files Patch % Lines
test/test_arrays.jl 86.18% 25 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #165      +/-   ##
==========================================
- Coverage   92.70%   91.83%   -0.88%     
==========================================
  Files          37       37              
  Lines        1590     1763     +173     
==========================================
+ Hits         1474     1619     +145     
- Misses        116      144      +28     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

test/test_arrays.jl Outdated Show resolved Hide resolved
@adrhill adrhill requested a review from gdalle August 14, 2024 22:47
@gdalle
Copy link
Collaborator

gdalle commented Aug 15, 2024

Is this even necessary?
I understand the need to handle Diagonal matrices created inside the function we trace. But I strongly doubt that there is a practical use case in which people would pass a Diagonal as input of sparsity detection. If you know that you only care about a Diagonal, you will pass the corresponding vector of coefficients as input and build the Diagonal internally.

@adrhill
Copy link
Owner Author

adrhill commented Aug 15, 2024

This issue started with #145, where a user had a ComponentArray input.
Until then, every input was converted to a dense Matrix.

The functionality of this PR is just 10 LOC to obtain much sparser patterns. Most of it is rewriting our array tests to be more flexible.

@gdalle
Copy link
Collaborator

gdalle commented Aug 15, 2024

I think this PR does two things: 1) more overloads for Diagonal inside generic code and 2) handling a Diagonal as input of sparsity detection. I'm only questioning the legitimacy of 2. While ComponentArrays or Symmetric matrices as input to sparsity detection make sense, Diagonal matrices make less sense to me.

@adrhill
Copy link
Owner Author

adrhill commented Aug 15, 2024

Point 2) is 4 LOC and worth it for easier testing of point 1), even if no user ever has Diagonal inputs.

@gdalle
Copy link
Collaborator

gdalle commented Aug 15, 2024

I'm just asking where you draw the line. To push this reasoning to the extreme, we want code to work if it uses FillArrays internally, but no sane person would give a FillArray as input of sparsity detection

@adrhill
Copy link
Owner Author

adrhill commented Aug 15, 2024

I'm just asking where you draw the line.

I definitely want to support SparseArray inputs in the future.

As soon as we "internally" support an array type, it makes sense to write a matching trace_input method. It makes testing and debugging that much easier.

To push this reasoning to the extreme, we want code to work if it uses FillArrays internally, but no sane person would give a FillArray as input of sparsity detection

Your point reminds me that we don't explicitly test FillArrays yet.

@adrhill adrhill merged commit 4a7ba7e into main Aug 15, 2024
6 checks passed
@adrhill adrhill deleted the ah/diag branch August 15, 2024 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add custom trace_input methods for LinearAlgebra matrix types
3 participants