@@ -191,19 +191,21 @@ end
191191Return the appropriate zero element `A[i, j]` corresponding to a banded matrix `A`.
192192"""
193193diagzero (:: Diagonal{T} , i, j) where {T} = zero (T)
194- diagzero (D:: Diagonal{<:AbstractMatrix{T}} , i, j) where {T} = diagzero (T, axes (D. diag[i], 1 ), axes (D. diag[j], 2 ))
194+ diagzero (D:: Diagonal{M, <:AbstractVector{M}} , i, j) where {T,M<: AbstractMatrix{T} } =
195+ diagzero (M, axes (D. diag[i], 1 ), axes (D. diag[j], 2 ))
195196# dispatching on the axes permits specializing on the axis types to return something other than an Array
196- diagzero (T :: Type , ax:: Union{AbstractUnitRange, Integer} ...) = diagzero (T , ax)
197- diagzero (T :: Type , :: Tuple{} ) = zeros (T )
197+ diagzero (M :: Type , ax:: Union{AbstractUnitRange, Integer} ...) = diagzero (M , ax)
198+ diagzero (M :: Type , :: Tuple{} ) = zeros (eltype (M) )
198199"""
199- diagzero(T ::Type, ax::Tuple{AbstractUnitRange, Vararg{AbstractUnitRange}})
200+ diagzero(::Type{M} , ax::Tuple{AbstractUnitRange, Vararg{AbstractUnitRange}}) where {M<:AbstractMatrix}
200201
201- Return an appropriate zero-ed array with either the axes `ax`, or the `size` `map(length, ax)`,
202- which may be used as a structural zero element of a banded matrix. By default, this falls back to
202+ Return an appropriate zero-ed matrix similar to `M`, with either
203+ the axes `ax`, or the `size` `map(length, ax)`.
204+ This will be used as a structural zero element of a banded matrix. By default, `diagzero` falls back to
203205using the size along each axis to construct the result.
204206"""
205- diagzero (T :: Type , ax:: Tuple{AbstractUnitRange, Vararg{AbstractUnitRange}} ) = diagzero (T , map (length, ax))
206- diagzero (T :: Type , sz:: Tuple{Integer, Vararg{Integer}} ) = zeros (T , sz)
207+ diagzero (M :: Type , ax:: Tuple{AbstractUnitRange, Vararg{AbstractUnitRange}} ) = diagzero (M , map (length, ax))
208+ diagzero (:: Type{M} , sz:: Tuple{Integer, Vararg{Integer}} ) where {M <: AbstractMatrix } = zeros (eltype (M) , sz)
207209
208210@inline function getindex (D:: Diagonal , b:: BandIndex )
209211 @boundscheck checkbounds (D, b)
0 commit comments