@@ -5,48 +5,38 @@ struct GetUnstoredBlock{Axes}
5
5
axes:: Axes
6
6
end
7
7
8
- # Allow customizing based on the block index.
9
- function unstored_block (
10
- A:: Type{<:AbstractArray{<:Any,N}} , ax:: NTuple{N,AbstractUnitRange{<:Integer}} , I:: Block{N}
11
- ) where {N}
12
- return unstored_block (A, ax)
13
- end
14
- function unstored_block (
15
- A:: Type{<:AbstractArray{<:Any,N}} , ax:: NTuple{N,AbstractUnitRange{<:Integer}}
16
- ) where {N}
17
- a = similar (A, ax)
18
- zero! (a)
19
- return a
20
- end
21
-
22
- using LinearAlgebra: Diagonal
23
- # TODO : This is a hack and is also type-unstable.
24
- function unstored_block (
25
- A:: Type{<:Diagonal{<:Any,V}} , ax:: NTuple{2,AbstractUnitRange{<:Integer}} , I:: Block{2}
26
- ) where {V}
27
- if allequal (Tuple (I))
28
- # Diagonal blocks.
29
- diag = zero! (similar (V, first (ax)))
30
- return Diagonal (diag)
31
- else
32
- # Off-diagonal blocks.
33
- return zero! (similar (similartype (V, typeof (ax)), ax))
8
+ @inline function (f:: GetUnstoredBlock )(
9
+ :: Type{<:AbstractArray{A,N}} , I:: Vararg{Int,N}
10
+ ) where {A,N}
11
+ ax = ntuple (N) do d
12
+ return only (axes (f. axes[d][Block (I[d])]))
34
13
end
14
+ return zero! (similar (A, ax))
35
15
end
36
-
37
16
@inline function (f:: GetUnstoredBlock )(
38
17
a:: AbstractArray{<:Any,N} , I:: Vararg{Int,N}
39
18
) where {N}
40
- # TODO : Make sure this works for sparse or block sparse blocks, immutable
41
- # blocks, diagonal blocks, etc.!
42
- b_ax = ntuple (ndims (a)) do d
43
- return only (axes (f. axes[d][Block (I[d])]))
44
- end
45
- return unstored_block (eltype (a), b_ax, Block (I))
19
+ return f (typeof (a), I... )
46
20
end
47
21
# TODO : Use `Base.to_indices`.
48
22
@inline function (f:: GetUnstoredBlock )(
49
23
a:: AbstractArray{<:Any,N} , I:: CartesianIndex{N}
50
24
) where {N}
51
25
return f (a, Tuple (I)... )
52
26
end
27
+
28
+ # TODO : this is a hack and is also type-unstable
29
+ using LinearAlgebra: Diagonal
30
+ using TypeParameterAccessors: similartype
31
+ function (f:: GetUnstoredBlock )(
32
+ :: Type{<:AbstractMatrix{<:Diagonal{<:Any,V}}} , I:: Vararg{Int,2}
33
+ ) where {V}
34
+ ax = ntuple (2 ) do d
35
+ return only (axes (f. axes[d][Block (I[d])]))
36
+ end
37
+ if allequal (I)
38
+ return Diagonal (zero! (similar (V, first (ax))))
39
+ else
40
+ return zero! (similar (similartype (V, typeof (ax)), ax))
41
+ end
42
+ end
0 commit comments