1
1
import Base: _throw_dmrs
2
- import Base. PermutedDimsArrays: genperm
3
2
4
3
"""
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
6
12
7
13
A replacement for `Base.ReshapedArray` for disk arrays,
8
14
returned by `reshape`.
9
15
10
-
11
16
Reshaping is really not trivial, because the access pattern would
12
17
completely change for reshaped arrays, rectangles would not remain
13
18
rectangles in the parent array.
14
19
15
20
However, we can support the case where only singleton dimensions are added,
16
21
later we could allow more special cases like joining two dimensions to one
17
22
"""
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 }
19
24
parent:: P
20
25
keepdim:: NTuple{M,Int}
21
26
newsize:: NTuple{N,Int}
22
27
end
23
28
24
29
# Base methods
30
+ Base. size (r:: AbstractReshapedDiskArray ) = r. newsize
31
+ Base. parent (r:: AbstractReshapedDiskArray ) = r. parent
25
32
26
- Base. parent (r:: ReshapedDiskArray ) = r. parent
27
- Base. size (r:: ReshapedDiskArray ) = r. newsize
33
+ keepdim (r:: AbstractReshapedDiskArray ) = r. keepdim
28
34
29
35
# DiskArrays interface
30
36
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) )
34
40
inow:: Int = 0
35
41
outchunks = ntuple (N) do idim
36
- if in (idim, a . keepdim)
42
+ if in (idim, keepdim (a) )
37
43
inow += 1
38
44
pchunks. chunks[inow]
39
45
else
@@ -42,14 +48,14 @@ function eachchunk(a::ReshapedDiskArray{<:Any,N}) where {N}
42
48
end
43
49
return GridChunks (outchunks... )
44
50
end
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... )
48
54
return nothing
49
55
end
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... )
53
59
return nothing
54
60
end
55
61
function reshape_disk (parent, dims)
@@ -93,6 +99,6 @@ macro implement_reshape(t)
93
99
end
94
100
95
101
# 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} )
97
103
return reshape_disk (A, dims)
98
104
end
0 commit comments