-
Notifications
You must be signed in to change notification settings - Fork 0
Implement _cat instead of cat
#13
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
This avoids causing too many invalidations
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #13 +/- ##
=======================================
Coverage 38.41% 38.41%
=======================================
Files 9 9
Lines 315 315
=======================================
Hits 121 121
Misses 194 194
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
|
Great, thanks! Glad that in the end there is a relatively simple (though hacky) fix. |
|
@lkdvos I think this should have been marked as a breaking change, since downstream libraries like BlockSparseArrays.jl are expecting Alternatively, thinking about this PR more, probably what we want to do is still overload: @interface interface::AbstractArrayInterface function Base.cat(as::AbstractArray...; dims)
# ...
endbut then downstream libraries can "derive" it by manually forwarding |
|
Sorry my mistake, I somehow understood your comment as a go ahead and wanted to strike this off my to do list. I understand what you’re saying, but I don’t think sending things back through a keyword syntax is really a good idea. The problem is that we’re introducing quite a few layers of non-trivial indirection, and this keyword actually determines the output type, so if somewhere along the way the const propagation fails this method becomes type unstable as a whole. I would maybe say that your initial implementation and suggestion in terms of a more broadcast-like way of thinking could be better suited, although that maybe doesn’t fit in so nicely with the whole interface idea, so maybe that should then just be a separate thing? |
Why doesn't that fit into the interface approach? Part of the point of this package, in my perspective, is to "hijack" things we think Base is doing poorly and do them better (if Base was doing everything well with good customization points, like it does with broadcasting, this package wouldn't be needed). |
I am slightly sympathetic to this issue, but also I think we shouldn't bend over backwards and make our interface worse because Base is doing something bad. But also I don't like being "prematurely pessimistic" about what the compiler will do, especially if it means making the code design worse. |
|
A compromise I could see is maybe: @interface interface::AbstractArrayInterface function Base.cat(as::AbstractArray...; dims)
return @interface interface cat_dims(dims, as...)
end
@interface interface::AbstractArrayInterface function cat_along(dims, as::AbstractArray...)
a_dest = similar(Cat(as...; dims))
@interface interface cat!(a_dest, as...; dims)
return a_dest
endand then types that want to derive our interface version of |
|
I made #17 just as a quick fix for issues I was hitting in BlockSparseArrays.jl. |
This is a slightly hacky way to bypass causing a lot of method invalidations. In particular, see the following issues:
ITensor/SparseArraysBase.jl#25
ITensor/BlockSparseArrays.jl#34
originally noticed during: ITensor/ITensors.jl#1579