Skip to content

Commit 3bd326b

Browse files
committed
Catch cases when block type can't be determined from similartype
1 parent f3e9290 commit 3bd326b

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/blocksparsearray/blocksparsearray.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,22 @@ function BlockSparseArray{T,N,A}(
171171
return BlockSparseArray{T,N,A}(undef, (dim1, dim_rest...))
172172
end
173173

174+
function unchecked_similartype(a, args...)
175+
A = Base.promote_op(similar, a, args...)
176+
return !isconcretetype(A) ? Array{T,N} : A
177+
end
178+
174179
function BlockSparseArray{T,N}(
175180
::UndefInitializer, axes::Tuple{Vararg{AbstractUnitRange{<:Integer},N}}
176181
) where {T,N}
177182
axt = Tuple{blockaxistype.(axes)...}
178-
A = similartype(Array{T}, axt)
183+
# Ideally we would use:
184+
# ```julia
185+
# A = similartype(Array{T}, axt)
186+
# ```
187+
# but that doesn't work when `similar` isn't defined or
188+
# isn't type stable.
189+
A = unchecked_similartype(Array{T}, axt)
179190
return BlockSparseArray{T,N,A}(undef, axes)
180191
end
181192

0 commit comments

Comments
 (0)