11import Base: _throw_dmrs
2- import Base. PermutedDimsArrays: genperm
32
43"""
5- ReshapedDiskArray <: AbstractDiskArray
4+ AbstractReshapedDiskArray <: AbstractDiskArray
5+
6+ Abstract supertype for a replacements of `Base.ReshapedArray` for `AbstractDiskArray`s`
7+ """
8+ abstract type AbstractReshapedDiskArray{T,N,P,M} <: AbstractDiskArray{T,N} end
9+
10+ """
11+ ReshapedDiskArray <: AbstractReshapedDiskArray
612
713A replacement for `Base.ReshapedArray` for disk arrays,
814returned by `reshape`.
915
10-
1116Reshaping is really not trivial, because the access pattern would
1217completely change for reshaped arrays, rectangles would not remain
1318rectangles in the parent array.
1419
1520However, we can support the case where only singleton dimensions are added,
1621later we could allow more special cases like joining two dimensions to one
1722"""
18- struct ReshapedDiskArray{T,N,P<: AbstractArray{T} ,M} <: AbstractDiskArray {T,N}
23+ struct ReshapedDiskArray{T,N,P<: AbstractArray{T} ,M} <: AbstractReshapedDiskArray {T,N,P,M }
1924 parent:: P
2025 keepdim:: NTuple{M,Int}
2126 newsize:: NTuple{N,Int}
2227end
2328
2429# Base methods
30+ Base. size (r:: AbstractReshapedDiskArray ) = r. newsize
31+ Base. parent (r:: AbstractReshapedDiskArray ) = r. parent
2532
26- Base. parent (r:: ReshapedDiskArray ) = r. parent
27- Base. size (r:: ReshapedDiskArray ) = r. newsize
33+ keepdim (r:: AbstractReshapedDiskArray ) = r. keepdim
2834
2935# DiskArrays interface
3036
31- haschunks (a:: ReshapedDiskArray ) = haschunks (a . parent)
32- function eachchunk (a:: ReshapedDiskArray {<:Any,N} ) where {N}
33- pchunks = eachchunk (a . parent)
37+ haschunks (a:: AbstractReshapedDiskArray ) = haschunks (parent (a) )
38+ function eachchunk (a:: AbstractReshapedDiskArray {<:Any,N} ) where {N}
39+ pchunks = eachchunk (parent (a) )
3440 inow:: Int = 0
3541 outchunks = ntuple (N) do idim
36- if in (idim, a . keepdim)
42+ if in (idim, keepdim (a) )
3743 inow += 1
3844 pchunks. chunks[inow]
3945 else
@@ -42,14 +48,14 @@ function eachchunk(a::ReshapedDiskArray{<:Any,N}) where {N}
4248 end
4349 return GridChunks (outchunks... )
4450end
45- function DiskArrays. readblock! (a:: ReshapedDiskArray , aout, i:: OrdinalRange... )
46- inew = tuple_tuple_getindex (i, a . keepdim)
47- DiskArrays. readblock! (a . parent, reshape (aout, map (length, inew)), inew... )
51+ function DiskArrays. readblock! (a:: AbstractReshapedDiskArray , aout, i:: OrdinalRange... )
52+ inew = tuple_tuple_getindex (i, keepdim (a) )
53+ DiskArrays. readblock! (parent (a) , reshape (aout, map (length, inew)), inew... )
4854 return nothing
4955end
50- function DiskArrays. writeblock! (a:: ReshapedDiskArray , v, i:: OrdinalRange... )
51- inew = tuple_tuple_getindex (i, a . keepdim)
52- DiskArrays. writeblock! (a . parent, reshape (v, map (length, inew)), inew... )
56+ function DiskArrays. writeblock! (a:: AbstractReshapedDiskArray , v, i:: OrdinalRange... )
57+ inew = tuple_tuple_getindex (i, keepdim (a) )
58+ DiskArrays. writeblock! (parent (a) , reshape (v, map (length, inew)), inew... )
5359 return nothing
5460end
5561function reshape_disk (parent, dims)
@@ -93,6 +99,6 @@ macro implement_reshape(t)
9399end
94100
95101# For ambiguity
96- function Base. _reshape (A:: DiskArrays. AbstractDiskArray{<:Any,1} , dims:: Tuple{Int64} )
102+ function Base. _reshape (A:: AbstractDiskArray{<:Any,1} , dims:: Tuple{Int64} )
97103 return reshape_disk (A, dims)
98104end
0 commit comments