Skip to content

Commit 65d5b1a

Browse files
committed
More general definition of blocktype
1 parent 9424058 commit 65d5b1a

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/blocksparsearrayinterface/blocksparsearrayinterface.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,31 @@ function eachstoredblock(a::AbstractArray)
4040
return storedvalues(blocks(a))
4141
end
4242

43+
# TODO: Generalize this, this catches simple cases
44+
# where the more general definition isn't specific enough.
45+
blocktype(a::Array) = typeof(a)
46+
# TODO: Maybe unwrap SubArrays?
47+
function blocktype(a::AbstractArray)
48+
# TODO: Unfortunately, this doesn't always give
49+
# a concrete type, even when it could be concrete, i.e.
50+
#=
51+
```julia
52+
julia> eltype(blocks(BlockArray(randn(2, 2), [1, 1], [1, 1])))
53+
Matrix{Float64} (alias for Array{Float64, 2})
54+
55+
julia> eltype(blocks(BlockedArray(randn(2, 2), [1, 1], [1, 1])))
56+
AbstractMatrix{Float64} (alias for AbstractArray{Float64, 2})
57+
58+
julia> eltype(blocks(randn(2, 2)))
59+
AbstractMatrix{Float64} (alias for AbstractArray{Float64, 2})
60+
```
61+
=#
62+
if isempty(blocks(a))
63+
return eltype(blocks(a))
64+
end
65+
return eltype(first(blocks(a)))
66+
end
67+
4368
abstract type AbstractBlockSparseArrayInterface <: AbstractSparseArrayInterface end
4469

4570
# TODO: Also support specifying the `blocktype` along with the `eltype`.

0 commit comments

Comments
 (0)