diff --git a/NEWS.md b/NEWS.md index bb22c9f940a78..9aebf5d42d954 100644 --- a/NEWS.md +++ b/NEWS.md @@ -138,6 +138,8 @@ Standard library changes (callable via `cholesky[!](A, RowMaximum())`) ([#54619]). * The number of default BLAS threads now respects process affinity, instead of using total number of logical threads available on the system ([#55574]). +* A new function `zeroslike` is added that is used to generate the zero elements for matrix-valued banded matrices. + Custom array types may specialize this function to return an appropriate result. ([#55252]) #### Logging diff --git a/stdlib/LinearAlgebra/src/diagonal.jl b/stdlib/LinearAlgebra/src/diagonal.jl index 0c8fcc61e0c76..be253c03ab3f6 100644 --- a/stdlib/LinearAlgebra/src/diagonal.jl +++ b/stdlib/LinearAlgebra/src/diagonal.jl @@ -197,11 +197,11 @@ diagzero(D::Diagonal{M}, i, j) where {M<:AbstractMatrix} = zeroslike(M::Type, ax::Vararg{Union{AbstractUnitRange, Integer}}) = zeroslike(M, ax) """ zeroslike(::Type{M}, ax::Tuple{AbstractUnitRange, Vararg{AbstractUnitRange}}) where {M<:AbstractMatrix} + zeroslike(::Type{M}, sz::Tuple{Integer, Vararg{Integer}}) where {M<:AbstractMatrix} -Return an appropriate zero-ed array similar to `M`, with either -the axes `ax`, or the `size` `map(length, ax)`. -This will be used as a structural zero element of a banded matrix. By default, `zeroslike` falls back to -using the size along each axis to construct the array. +Return an appropriate zero-ed array similar to `M`, with either the axes `ax` or the size `sz`. +This will be used as a structural zero element of a matrix-valued banded matrix. +By default, `zeroslike` falls back to using the size along each axis to construct the array. """ zeroslike(M::Type, ax::Tuple{AbstractUnitRange, Vararg{AbstractUnitRange}}) = zeroslike(M, map(length, ax)) zeroslike(M::Type, sz::Tuple{Integer, Vararg{Integer}}) = zeros(M, sz)