You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think a helpful abstraction could be a BlockIndices type, analogous to the CartesianIndices type in Base Julia, to aid with converting back and forth between cartesian indices and block indices. I would find that very helpful for advanced slicing operations, for example when performing slicing operations across block arrays with mismatched blocking structures.
As a minimal demonstration:
using BlockArrays
struct BlockIndices{N,R<:NTuple{N,OrdinalRange{Int,Int}}} <:AbstractArray{BlockIndex{N},N}
indices::RendBlockIndices(a::AbstractArray) =BlockIndices(axes(a))
function Base.getindex(a::BlockIndices{N}, index::Vararg{Integer,N}) where {N}
returnBlockIndex(findblockindex.(a.indices, index))
end
which would allow for this syntax for converting back and forth between cartesian indices and block indices:
I found it interesting that indexing into CartesianIndices with a BlockIndex already works, I assume it is because the CartesianIndices object gets the same blocked axes as the BlockArray.
Something that doesn't work right now is indexing into CartesianIndices with a Block and getting back out a CartesianIndices, for example:
We may be able to make BlockIndices a subtype of AbstractBlockArray and automatically inherit a lot of AbstractBlockArray behavior, since it will have blocked axes.
The text was updated successfully, but these errors were encountered:
I quite like this idea, and I think this would certainly lead to code that is easier to reason about. Would you mind submitting a PR implementing this?
I think a helpful abstraction could be a
BlockIndices
type, analogous to theCartesianIndices
type in Base Julia, to aid with converting back and forth between cartesian indices and block indices. I would find that very helpful for advanced slicing operations, for example when performing slicing operations across block arrays with mismatched blocking structures.As a minimal demonstration:
which would allow for this syntax for converting back and forth between cartesian indices and block indices:
I found it interesting that indexing into
CartesianIndices
with aBlockIndex
already works, I assume it is because theCartesianIndices
object gets the same blocked axes as theBlockArray
.Something that doesn't work right now is indexing into
CartesianIndices
with aBlock
and getting back out aCartesianIndices
, for example:but that should be simple to fix.
We may be able to make
BlockIndices
a subtype ofAbstractBlockArray
and automatically inherit a lot ofAbstractBlockArray
behavior, since it will have blocked axes.The text was updated successfully, but these errors were encountered: