-
Notifications
You must be signed in to change notification settings - Fork 37
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
interface for rewrapping Array wrappers #136
Comments
I think this would be a band-aid for the real issue, which is that these arrays are all adding some sort of new trait/behavior but the trait is only evident if it is the top level. Similarly, we shouldn't try to make a Of course, the situation is different if the wrapper actually changes the layout of an array. For example, |
This is partially true, but in practice it will be very difficult for axis indexing to work correctly through multiple outer wrappers. Axis lookup wrappers like Being wrapped by other kind of arrays is awkward in comparison. How can a In practice it is much easier to aggressively rewrap to the outside - e.g. look at broadcast for NamedDims/DimensionalData/AxisKeys. I may be mistaken but maybe @mcabbott has experimented with these alternate strategies somewhere? From my own experience with DimensionalData I think that wrappers that do not affect the objects size, shape or values, but do depend on them, always being on the outside is the simplest option. There is only the caveat of needing some rule for working out what happens when two of these types collides (ie. unwrap I would of course be persuaded by a clean working solution that didn't need rewrapping to the outside! but I haven't seen one yet. Edit: also, for transposes and similar, both ways have their issues, there are definitely some situations where being the outer wrapper is not easier. Traits that notify or changes in axis order and permutation could help here. |
Yes I experimented a bit. In fact AxisKeys.jl is one experiment really, at making its wrapper commute with that of NamedDims.jl -- it runs the tests in both orders. But the approach is just to write lots of methods, which is not going to scale well, let alone work for packages which don't know about each other. It seems hard to know quite what re-wrapping should achieve in general. Broadcasting is easy in that Base defines the scope, likewise views. But making something like padding (from the discourse thread) "work" with array wrappers not designed for it seems messy. Regardless of which ends up on top, what are the rules? When an AxisArray has a StepRange do you extend it? And categorical? What happens to Hermitian or BiDiagonal types? By the time you've answered these, then it seems hard to say the wrapper and the padding don't know about each other anymore. If the shared knowledge lives in some traits package, it seems that this must grow to basically contain all the logic. |
Yes there would need to be fairly specific scope. Outside of Base, things like Then, something like a Further in, Then there is every other way that shape/size can be altered by a wrapper, that we just can't handle, and shouldn't rewrap. It seems there is some structure to the situation that we could work with, if it's worth it. We have 1 trait for an array wrapper: |
Ok I'm keen to see what you come up with! Although I'm still concerned that a lot of edge cases will mean we still need dispatch on |
There are some methods that will have issues and we need to put together our own implementation, but that's manageable. Most of these are actually pretty straightforward. "src/indexing.jl" has a lot of that for |
I like your enthusiasm!! but these wrappers do a lot more than
It would be great but it sounds like a lot of work to get all of this done. Absolutely we should aim high, and in the end a lot of that base code does needs to be fixed so these things are easier. My proposal here is just a basic incremental improvement on what already exists, but it's also pretty easily achieved. |
I should probably write something like "The State of ArrayInterface" thing to answer this properly. I've been doing a pretty terrible job of making stuff known and approachable for the Julia community over the last year. I'm going to finish a PR and start working on that. |
That would be great, good to start getting more people on board and contributing, at least ideas and feedback. |
BTW #141 is the PR I was referring to, so hopefully I can get started on this soon |
Some wrapper types like
AxisArray
,NamedDImsArray
andDimArray
(and probablyLabelledArray
?) need to be the "outside" wrapper for, e.g. keeping the axis index accurate and dispatch forgetindex
methods.This issue just came up on discourse:
https://discourse.julialang.org/t/multiple-inheritance-carry-over-members/58355/8
People kind of expect a
DimArray
to keep working after wrapping with other types. It could be useful to have a trait and a shared method here that allows rewrapping:rewrap(f, A)
andrewrap(f, A, I...)
could be used in other array constructors to allow rewrapping where necessary.isouterwrapper
could indicate if an object is an outer wrapper type.The text was updated successfully, but these errors were encountered: