|
1 | 1 | using ArrayLayouts: ArrayLayouts |
2 | 2 | using BlockArrays: BlockArrays, AbstractBlockVector, Block, BlockIndex, BlockRange, |
3 | | - BlockSlice, BlockVector, BlockedUnitRange, BlockedVector, block, blockcheckbounds, |
4 | | - blockisequal, blocklength, blocklengths, blocks, findblockindex |
| 3 | + BlockSlice, BlockVector, BlockedUnitRange, BlockedVector, BlocksView, block, |
| 4 | + blockcheckbounds, blockisequal, blocklength, blocklengths, blocks, findblockindex |
5 | 5 | using FunctionImplementations: FunctionImplementations, permuteddims, zero! |
6 | 6 | using LinearAlgebra: Adjoint, Transpose |
7 | 7 | using SparseArraysBase: AbstractSparseArrayImplementationStyle, eachstoredindex, |
@@ -75,13 +75,13 @@ julia> length(blocks(BlockedVector{Float64}(randn(0)))) |
75 | 75 | 1 |
76 | 76 | ``` |
77 | 77 | =# |
78 | | -function blocktype(a::AbstractArray) |
79 | | - if isempty(blocks(a)) |
80 | | - error("`blocktype` can't be determined if `isempty(blocks(a))`.") |
81 | | - end |
82 | | - return mapreduce(typeof, promote_type, blocks(a)) |
| 78 | +eltype_inferred(a::AbstractArray{T}) where {T} = T |
| 79 | +function eltype_inferred(a::BlocksView{<:Any, N}) where {N} |
| 80 | + return Base.promote_op(getindex, typeof(a), ntuple(Returns(Int), Val(N))...) |
83 | 81 | end |
84 | 82 |
|
| 83 | +blocktype(a::AbstractArray) = eltype_inferred(blocks(a)) |
| 84 | + |
85 | 85 | using BlockArrays: BlockArray |
86 | 86 | blockstype(::Type{<:BlockArray{<:Any, <:Any, B}}) where {B} = B |
87 | 87 | blockstype(a::BlockArray) = blockstype(typeof(a)) |
@@ -526,5 +526,4 @@ function blocks_blocksparse( |
526 | 526 | return @view blocks(parent(a))[map(to_blocks_indices, parentindices(a))...] |
527 | 527 | end |
528 | 528 |
|
529 | | -using BlockArrays: BlocksView |
530 | 529 | SparseArraysBase.storedlength(a::BlocksView) = length(a) |
0 commit comments