-
Notifications
You must be signed in to change notification settings - Fork 2
Simplify show implementation #46
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
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #46 +/- ##
==========================================
- Coverage 75.89% 75.71% -0.18%
==========================================
Files 29 29
Lines 1095 1083 -12
==========================================
- Hits 831 820 -11
+ Misses 264 263 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
That will be good to have anyway!
Oh interesting, I think I didn't appreciate there were two different kinds of dots... The fun of unicode.
Good question. I see GPUArrays.jl handles it in this way: https://github.com/JuliaGPU/GPUArrays.jl/blob/v11.2.2/src/host/abstractarray.jl#L139-L149 which seems like a good approach. We could define something similar for |
Following up on the last comment, it seems like we could either do something like: Base.print_array(io::IO, X::AnyAbstractBlockSparseArray) = Base.print_array(io, adapt(ToCPU(), X)) or: Base.print_array(io::IO, X::AnyAbstractBlockSparseArray) = @allowscalar Base.print_array(io, X) but the issue would be that either one can lead to infinite recursion, but that could be fixed with Base.print_array(io::IO, X::AnyAbstractBlockSparseArray) = invoke(Base.print_array, Tuple{IO,AbstractVecOrMat}, io, adapt(ToCPU(), X)) or: Base.print_array(io::IO, X::AnyAbstractBlockSparseArray) = @allowscalar invoke(Base.print_array, Tuple{IO,AbstractVecOrMat}, io, X) |
I guess that what bothers me about this is that In principle, converting to CPU is definitely the better option, since that pulls in the entire matrix in one go instead of one element at a time. |
I'm a bit confused about that point, this could just act as a fallback definition and if there are more specialized overloads of |
Oh right, I guess that's true. |
This does a simplified implementation of
show
, as in ITensor/SparseArraysBase.jl#31.In order to make this work, I also added an
isstored
implementation for blocksparsearrays.Note that the alignment again changes slightly, and apparently Base uses a centered dot, which I hadn't realized (spotting why the tests were failing was a fun exercise 😀).
Side note: This also unintentionally removes a
@allowscalar
before the call toprint_array
, since Base doesn't automatically put that there. Do you know if there is a good way to hook into that?