Skip to content

Commit 15f1f23

Browse files
committed
Revert some changes to getunstoredblock
1 parent de3e859 commit 15f1f23

File tree

1 file changed

+23
-33
lines changed

1 file changed

+23
-33
lines changed

src/blocksparsearrayinterface/getunstoredblock.jl

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,38 @@ struct GetUnstoredBlock{Axes}
55
axes::Axes
66
end
77

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])]))
3413
end
14+
return zero!(similar(A, ax))
3515
end
36-
3716
@inline function (f::GetUnstoredBlock)(
3817
a::AbstractArray{<:Any,N}, I::Vararg{Int,N}
3918
) 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...)
4620
end
4721
# TODO: Use `Base.to_indices`.
4822
@inline function (f::GetUnstoredBlock)(
4923
a::AbstractArray{<:Any,N}, I::CartesianIndex{N}
5024
) where {N}
5125
return f(a, Tuple(I)...)
5226
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

Comments
 (0)