Subtype AbstractArray for TileArray#176
Conversation
What does it realistically enable? As mentioned in #66 (comment), I'm not sure this buys us much, even with the scalar ops from #76. Every operation on a TileArray is realistically going to have to be special-cased to lower to tile-based ops, and not simply expand to a loop doing scalar ones as all of the fallbacks in Base do. |
|
Hi Tim, the immediate benefit I was thinking to get from this patch is that TileArray would pass isa AbstractArray dispatch, which matters for the Tiled broadcast machinery and for user code doing arr isa AbstractArray guards. I’m still not fully sure the complete AbstractArray interface is meaningful here, but the type relationship being correct feels like a good baseline hence keeping it in draft. I’ll get back to you with more concrete details once I’ve figured out what else this realistically enables beyond the above. |
How so? We already have broadcast implemented here. |
|
My bad, the broadcast claim was wrong, and isa AbstractArray alone isn’t a strong enough motivation for a type hierarchy change when none of the Base fallbacks actually work. Closing this for now. |
|
Note that I'm really not opposed to doing this, I just don't know what it would buy is. If you run into a case where it would help, feel free to re-open. |
Closes #66
Fix
Subtype
TileArray{T, N, S}fromAbstractArray{T, N}.Changes
struct TileArray{T, N, S} <: AbstractArray{T, N}: one line change to the struct declarationBase.getindex: throws a clear error on host-side indexing instead of crashing cryptically when the defaultAbstractArraymachinery tries to call itBase.show/Base.show(::MIME"text/plain"): custom display so the REPL doesn't try to iterate elements and hit thegetindexerrorBase.pointer: exposes the underlyingptrfield so the existingTileArray(arr::AbstractArray)constructor doesn't accidentally recurse when passed aTileArrayReason
Base.size,Base.eltype, andBase.ndimswere already defined manually. SubtypingAbstractArraymeans these come for free via inheritance for any future additions, andTileArraynow participates correctly in Julia's type hierarchy, generic code that dispatches onAbstractArraywill work as expected.The core constraint is that
TileArraylives on the GPU and has no host-side element access. Thegetindeximplementation makes this explicit with a useful error message rather than a confusing stack trace.