Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions stdlib/LinearAlgebra/src/LinearAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,13 @@ _cut_B(x::AbstractVector, r::UnitRange) = length(x) > length(r) ? x[r] : x
_cut_B(X::AbstractMatrix, r::UnitRange) = size(X, 1) > length(r) ? X[r,:] : X

## append right hand side with zeros if necessary
_zeros(::Type{T}, b::AbstractVector, n::Integer) where {T} = zeros(T, max(length(b), n))
_zeros(::Type{T}, B::AbstractMatrix, n::Integer) where {T} = zeros(T, max(size(B, 1), n), size(B, 2))
_zeros(::Type{T}, b::AbstractVector, n::Integer) where {T} =
fill!(similar(b, T, max(length(b), n)), zero(T))
_zeros(::Type{T}, B::AbstractMatrix, n::Integer) where {T} =
fill!(similar(B, T, max(size(B, 1), n), size(B, 2)), zero(T))
# return a dense array, since similar(::Union{BiTriSym, Diagonal}) returns a sparse array
_zeros(::Type{T}, B::Union{BiTriSym, Diagonal}, n::Integer) where {T} =
zeros(T, max(size(B, 1), n), size(B, 2))

# General fallback definition for handling under- and overdetermined system as well as square problems
# While this definition is pretty general, it does e.g. promote to common element type of lhs and rhs
Expand Down
5 changes: 5 additions & 0 deletions stdlib/SparseArrays/src/SparseArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ similar(M::Tridiagonal, ::Type{T}, dims::Union{Dims{1},Dims{2}}) where {T} = spz

zero(a::AbstractSparseArray) = spzeros(eltype(a), size(a)...)

LinearAlgebra._zeros(::Type{T}, b::AbstractSparseVector, n::Integer) where {T} =
zeros(T, max(length(b), n))
LinearAlgebra._zeros(::Type{T}, B::AbstractSparseMatrix, n::Integer) where {T} =
zeros(T, max(size(B, 1), n), size(B, 2))

const BiTriSym = Union{Bidiagonal,SymTridiagonal,Tridiagonal}
function *(A::BiTriSym, B::BiTriSym)
TS = promote_op(matprod, eltype(A), eltype(B))
Expand Down