Skip to content

Fix isstored with trailing singletons, vector show #45

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

Merged
merged 3 commits into from
Mar 8, 2025
Merged

Conversation

mtfishman
Copy link
Member

@mtfishman mtfishman commented Mar 7, 2025

This is a step towards addressing ITensor/BlockSparseArrays.jl#77.

To-do:

  • Fix linear indexing in isstored.
  • Add tests.

Copy link

codecov bot commented Mar 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 75.59%. Comparing base (248dd87) to head (27294cc).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #45      +/-   ##
==========================================
+ Coverage   74.88%   75.59%   +0.70%     
==========================================
  Files           7        7              
  Lines         450      463      +13     
==========================================
+ Hits          337      350      +13     
  Misses        113      113              
Flag Coverage Δ
docs 34.92% <25.00%> (-0.80%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mtfishman
Copy link
Member Author

@lkdvos the root of ITensor/BlockSparseArrays.jl#77 is that isstored wasn't handling trailing singleton indices properly, i.e.:

a = SparseArrayDOK{Float64}(undef, 2)
isstored(a, 1, 1)

should have output false but was outputting true, which is fixed in this PR. With that issue fixed, fixing ITensor/BlockSparseArrays.jl#77 is just a matter of generalizing Base.replace_in_print_matrix to accept matrices or vectors, which is demonstrated in this PR for sparse matrices/vectors and in ITensor/BlockSparseArrays.jl#79 for block sparse matrices/vectors.

You PR #39 refactors isstored, does that PR handle trailing singleton dimensions? I think that PR would be the correct place to address that issue since it involves a broader refactor of the isstored logic (though I do have some questions about which part of the logic around canonicalizing the index inputs should be handled at the level of isstored vs. @interface isstored, but we can discuss that in #39).

@lkdvos
Copy link
Contributor

lkdvos commented Mar 8, 2025

It should handle that correctly, since there are the calls to to_indices in there somewhere, but it's good that you brought this up so I can double check

@mtfishman
Copy link
Member Author

It should handle that correctly, since there are the calls to to_indices in there somewhere, but it's good that you brought this up so I can double check

This issue led me to wonder how Base handles that logic, apparently it isn't in Base.to_indices:

julia> Base.to_indices(randn(2), (1, 1))
(1, 1)

But anyway, however it is done, let's handle that logic as part of #39 and this PR will be limited to changing the definition of Base.replace_in_print_matrix (or we can do that in #39 as well since it is a small change anyway).

Copy link
Contributor

@lkdvos lkdvos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just double-checked it, in case you were interested, it's the combination of Base.to_indices and Base._to_linear_index or Base._to_subscript_indices that should resolve all combinations of indices. (which indeed is fixed in that PR)

Definitely agree on the rest though, if this works this is definitely a good intermediate patch.

@mtfishman mtfishman changed the title [WIP] Fix isstored with trailing singletons, vector show Fix isstored with trailing singletons, vector show Mar 8, 2025
@mtfishman mtfishman marked this pull request as ready for review March 8, 2025 20:01
@mtfishman
Copy link
Member Author

Alight, as you say I guess this is a reasonable intermediate solution, so I'll go ahead and merge this with the assumption that the isstored logic will be rewritten in #39 anyway, but at the very least it is useful for ITensor/BlockSparseArrays.jl#77 and ITensor/BlockSparseArrays.jl#79.

@mtfishman mtfishman merged commit 1236822 into main Mar 8, 2025
14 checks passed
@mtfishman mtfishman deleted the vec_show branch March 8, 2025 20:04
@mtfishman mtfishman mentioned this pull request Mar 9, 2025
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.

2 participants