-
Notifications
You must be signed in to change notification settings - Fork 1
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
Rework cat
implementation
#18
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #18 +/- ##
==========================================
+ Coverage 72.89% 81.56% +8.67%
==========================================
Files 9 10 +1
Lines 321 293 -28
==========================================
+ Hits 234 239 +5
+ Misses 87 54 -33
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
I think it is ok, I see that you tried to stick closer to the implementation of I think we can have some compromise between the two approaches, for example: function cat(dims, args...)
# `instantiate` reduces over the `args` and determines a common `CatStyle`,
# returning a new `Catted` with the `CatStyle` stored.
return copy(instantiate(Catted(dims, args...)))
end
function Base.copy(c::Catted)
dest = similar(c)
copyto!(dest, c)
return dest
end
function Base.copyto!(dest::AbstractArray, c::Catted)
cat!(dest, axes(c), c.dims, c.args...)
return dest
end
function cat!(dest, shape, catdims, args...)
# Implementation of `cat!`.
end |
I initially started with a design similar to I agree that sure, the Concretely, I would suggest we avoid the |
I'm a bit concerned about reusing |
It's possible, but then we can still specialize on the types. Also, since we currently don't have that many different sparse types in place, I would much rather have a simple solution that works for now, which we can fix later if need be, instead of a more complicated one that may account for future options, but may also still have to be fixed later because we cannot foresee all possibilities without actual examples. |
I still personally prefer a solution based around a |
I reworked the implementation to include a |
I like the new names, What do you have in mind for how to incorporate this into the rest of the package? I'm curious what you think of: #12 (comment). It seems like those broader questions around what this package should be and how opinionated it should be has implications for what we decide to do with these cat methods. If we go the route of having this package be very unopinionated and not really having any implementations, it might then make sense for this PR to be put in a separate package |
I think I would lean towards having defaults that aren't opinionated, while providing tools for customization. I'm not very enthusiastic about splitting this off into a separate package. This has the drawback that it would then require us to also add the logic of having interfaces and interface promotion rules there, or simply depend on this package anyways. I fear that if we need to have Another somewhat unfortunate factor is that these kinds of solutions don't follow the same format as the other functions, and it's a bit hard to try and fit it into the |
Yeah, I think that would be a bit too much (it would be unfortunate for someone to call
Right, for now I was picturing that if we moved it to a separate package we could depend on this package and the
As you say, I think that is just the nature of the fact that I'm ok keeping it in this package right now, but lets keep it in mind going forward. I would want to have some "philosophy" or guiding principle for what goes in this package vs. in a separate package. Maybe the principle is that if it implements functionality that is close to functionality in Base but provides better customization points based around |
@lkdvos this looks good to me, what are the next steps here? |
Since this one is breaking, I would suggest either merging but not yet tagging, or slightly holding off on merging, because maybe we can simultaneously alter the
|
Sure, that sounds reasonable to do all of those in a single breaking release. So, up to you if you want to merge this and then work on those next, or keep this unmerged and building off of it (I think I prefer not merging this yet since if there are non-breaking things we want to fix in the meantime it would make that easier). |
I'm okay with keeping this open, the other changes should not depend on this anyways |
src/concatenate.jl
Outdated
# copy_or_fill!(A, inds, x) = fill!(view(A, inds...), x) | ||
# copy_or_fill!(A, inds, x::AbstractArray) = (A[inds...] = x) | ||
|
||
zero!(x::AbstractArray) = fill!(x, zero(eltype(x))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like we are going to end up with a few zero!
definitions in various places. Should we define DerivableInterfaces.zero!
which is used here and in SparseArraysBase.jl?
As we've discussed, SparseArraysBase.jl currently uses ArrayLayouts.zero!
, but maybe it would be better to have DerivableInterfaces.zero!
which we use in our own code, and then types that want to use ArrayLayouts.jl can overload ArrayLayouts.zero!
(which could just forward to DerivableInterfaces.zero!
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I definitely think that's a good idea, it's strange to me that it doesn't exist in Base anyways.
I cooked up a minimal version of the parts of a small adaptation to the Base implementation of
cat
with more well-defined entry-points for customization, and which should be friendly on both inference and invalidations because the dispatching is happening in steps.Let me know how you feel about this and we can think about the most convenient way of integrating this into the rest of the framework.