Skip to content

Commit 0bd1cd3

Browse files
committed
Small cleanup
1 parent 56ee5a5 commit 0bd1cd3

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

src/BlockArraysExtensions/blockedunitrange.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,18 @@ axis(a::AbstractVector) = axes(a, 1)
2929
function eachblockaxis(a::AbstractVector)
3030
return map(axis, blocks(a))
3131
end
32+
function blockaxistype(a::AbstractVector)
33+
return eltype(eachblockaxis(a))
34+
end
3235

3336
# Take a collection of axes and mortar them
3437
# into a single blocked axis.
3538
function mortar_axis(axs)
36-
## return blockedrange(length.(axs))
3739
return blockrange(axs)
3840
end
41+
function mortar_axis(axs::Vector{<:Base.OneTo{<:Integer}})
42+
return blockedrange(length.(axs))
43+
end
3944

4045
# Custom `BlockedUnitRange` constructor that takes a unit range
4146
# and a set of block lengths, similar to `BlockArray(::AbstractArray, blocklengths...)`.

src/abstractblocksparsearray/wrappedabstractblocksparsearray.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,15 @@ end
232232

233233
# This circumvents some issues with `TypeParameterAccessors.similartype`.
234234
# TODO: Fix this poperly in `TypeParameterAccessors.jl`.
235-
function _similartype(arraytype::Type{<:AbstractArray}, elt::Type, axt)
236-
return Base.promote_op(similar, arraytype, elt, axt)
235+
function _similartype(arrayt::Type{<:AbstractArray}, elt::Type, axt::Type{<:Tuple})
236+
return Base.promote_op(similar, arrayt, elt, axt)
237+
end
238+
function _similartype(arrayt::Type{<:AbstractArray}, axt::Type{<:Tuple})
239+
return Base.promote_op(similar, arrayt, axt)
237240
end
238241

239242
function blocksparse_similar(a, elt::Type, axes::Tuple)
240-
block_axt = Tuple{eltype.(eachblockaxis.(axes))...}
243+
block_axt = Tuple{blockaxistype.(axes)...}
241244
blockt = _similartype(blocktype(a), Type{elt}, block_axt)
242245
return BlockSparseArray{elt,length(axes),blockt}(undef, axes)
243246
end

src/blocksparsearray/blocksparsearray.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ end
173173
function BlockSparseArray{T,N}(
174174
::UndefInitializer, axes::Tuple{Vararg{AbstractUnitRange{<:Integer},N}}
175175
) where {T,N}
176-
# TODO: Use `similartype` to determine the block type.
177-
A = Base.promote_op(similar, Array{T}, Tuple{eltype.(eachblockaxis.(axes))...})
176+
axt = Tuple{blockaxistype.(axes)...}
177+
A = _similartype(Array{T}, axt)
178178
return BlockSparseArray{T,N,A}(undef, axes)
179179
end
180180

0 commit comments

Comments
 (0)