|
44 | 44 | function blockstype(a::AbstractArray) |
45 | 45 | return typeof(blocks(a)) |
46 | 46 | end |
| 47 | + |
| 48 | +#= |
| 49 | +Ideally this would just be defined as `eltype(blockstype(a))`. |
| 50 | +However, BlockArrays.jl doesn't make `eltype(blocks(a))` concrete |
| 51 | +even when it could be |
| 52 | +(https://github.com/JuliaArrays/BlockArrays.jl/blob/v1.4.0/src/blocks.jl#L71-L74): |
| 53 | +```julia |
| 54 | +julia> eltype(blocks(BlockArray(randn(2, 2), [1, 1], [1, 1]))) |
| 55 | +Matrix{Float64} (alias for Array{Float64, 2}) |
| 56 | +
|
| 57 | +julia> eltype(blocks(BlockedArray(randn(2, 2), [1, 1], [1, 1]))) |
| 58 | +AbstractMatrix{Float64} (alias for AbstractArray{Float64, 2}) |
| 59 | +
|
| 60 | +julia> eltype(blocks(randn(2, 2))) |
| 61 | +AbstractMatrix{Float64} (alias for AbstractArray{Float64, 2}) |
| 62 | +``` |
| 63 | +Also note the current definition doesn't handle the limit |
| 64 | +when `blocks(a)` is empty |
| 65 | +=# |
47 | 66 | function blocktype(a::AbstractArray) |
48 | 67 | if isempty(blocks(a)) |
49 | | - # TODO: Unfortunately, this doesn't always give |
50 | | - # a concrete type, even when it could be concrete, i.e. |
51 | | - #= |
52 | | - ```julia |
53 | | - julia> eltype(blocks(BlockArray(randn(2, 2), [1, 1], [1, 1]))) |
54 | | - Matrix{Float64} (alias for Array{Float64, 2}) |
55 | | -
|
56 | | - julia> eltype(blocks(BlockedArray(randn(2, 2), [1, 1], [1, 1]))) |
57 | | - AbstractMatrix{Float64} (alias for AbstractArray{Float64, 2}) |
58 | | -
|
59 | | - julia> eltype(blocks(randn(2, 2))) |
60 | | - AbstractMatrix{Float64} (alias for AbstractArray{Float64, 2}) |
61 | | - ``` |
62 | | - =# |
63 | | - # That is an issue in BlockArrays.jl that we should address. |
64 | | - return eltype(blocks(a)) |
| 68 | + error("`blocktype` can't be determined if `isempty(blocks(a))`.") |
65 | 69 | end |
66 | 70 | return mapreduce(typeof, promote_type, blocks(a)) |
67 | 71 | end |
|
0 commit comments