Multiple inheritance carry-over members

and it failed to do its job

I think you misunderstand the scope of what you want here. It’s job doesn’t really extend into the constructors of ecosystem packages that I don’t know about, I can’t see how this would “just work” in any language. How do we influence the PaddedView constructor? and what should happen if you try to wrap it with a NamedDims.jl wrapper? which should “win”?

But it is possible to solve this with very little boilerplate code, and as usual in Julia, it would need some (a lot of) coordination and a shared interface (as you suggest with AbstractArray, but probably actually with traits and shared methods in an interface package like ArrayInterface.jl).

The simple case would be that PaddedView has a method that dispatches on DimArray and rewraps. But to generalise to AxisArrays,jl and NamdDims.jl and any other wrapper type, we could have a method in ArrayInterface.jl - rewrap(f, A). PaddedView and other array packages could call rewrap in their constructor. The default rewrap would just call f and return it. But DimensionalData.jl could add a method to unwrap the internal array, run the constructor f, and wrap it with a DimArray again.

Someone would have to write this, and packages would have to implement it. Probably a lot wouldn’t, but as ArrayInterface.jl is more widely accepted, things like this may start to work?

Broadcast can handle this a little better - it’s possible to make DD always “win” as the outer wrapper. I’m not sure how well it goes currently with other packages. Probably NamedDims.jl wrappers would beat it as @oxinabox understands broadcast better than I do.

Composition is what we are doing by wrapping objects that already have behaviors, instead of inheriting behaviours from a supertype, as we are with AbstractArray. But I meant that comment in relation you question about field inheritance, which is actually unrelated to this problem. Regular inheritance doesn’t apply in this context because PaddedView does not inherit from or know about AbstractDimArray, it inherits from AbstractArray - so composition is all we can do.

This is a problem of agreeing on ecosystem wide shared interfaces, and working out what they need to do and agreeing to implement them. Maybe some of them will make it into Base one day. That’s what ArrayInterface.jl is for, but these things are a long way off.

Personally, I just use DimensionalData.rebuild for this kind of thing:

rebuild(some_dimarray, PaddedView(parent(some_dimarray), args...))

Which of course will break the index if PaddedView changes the array size, another complication to this issue. Doing that generically would need rewrap(f, A, I...)

See: interface for rewrapping Array wrappers · Issue #136 · JuliaArrays/ArrayInterface.jl · GitHub

1 Like