Skip to content
Merged
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
27 changes: 15 additions & 12 deletions src/solvers/spqr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -357,20 +357,13 @@ function Base.show(io::IO, mime::MIME{Symbol("text/plain")}, F::QRSparse)
println(io, "\nColumn permutation:")
show(io, mime, F.pcol)
end
function Base.show(io::IO, ::MIME{Symbol("text/plain")}, Q::QRSparseQ)
summary(io, Q)
# TODO: remove once the AdjointQ PR is merged
if QRSparseQ <: AbstractMatrix
function Base.show(io::IO, ::MIME{Symbol("text/plain")}, Q::QRSparseQ)
summary(io, Q)
end
end

# With a real lhs and complex rhs with the same precision, we can reinterpret
# the complex rhs as a real rhs with twice the number of columns
#
# This definition is similar to the definition in factorization.jl except that
# here we have to use \ instead of ldiv! because of limitations in SPQR

## Two helper methods
_ret_size(F::QRSparse, b::AbstractVector) = (size(F, 2),)
_ret_size(F::QRSparse, B::AbstractMatrix) = (size(F, 2), size(B, 2))

"""
rank(::QRSparse{Tv,Ti}) -> Ti

Expand All @@ -385,6 +378,16 @@ Calculate rank of `S` by calculating its QR factorization. Values smaller than `
"""
LinearAlgebra.rank(S::SparseMatrixCSC; tol=_default_tol(S)) = rank(qr(S; tol))

# With a real lhs and complex rhs with the same precision, we can reinterpret
# the complex rhs as a real rhs with twice the number of columns
#
# This definition is similar to the definition in factorization.jl except that
# here we have to use \ instead of ldiv! because of limitations in SPQR

## Two helper methods
_ret_size(F::QRSparse, b::AbstractVector) = (size(F, 2),)
_ret_size(F::QRSparse, B::AbstractMatrix) = (size(F, 2), size(B, 2))

function (\)(F::QRSparse{T}, B::VecOrMat{Complex{T}}) where T<:LinearAlgebra.BlasReal
# |z1|z3| reinterpret |x1|x2|x3|x4| transpose |x1|y1| reshape |x1|y1|x3|y3|
# |z2|z4| -> |y1|y2|y3|y4| -> |x2|y2| -> |x2|y2|x4|y4|
Expand Down
4 changes: 3 additions & 1 deletion test/spqr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using Test
using SparseArrays.SPQR
using SparseArrays.CHOLMOD
using LinearAlgebra: I, istriu, norm, qr, rank, rmul!, lmul!, Adjoint, Transpose, ColumnNorm, RowMaximum, NoPivot
using SparseArrays: sparse, sprandn, spzeros, SparseMatrixCSC
using SparseArrays: SparseArrays, sparse, sprandn, spzeros, SparseMatrixCSC

if Base.USE_GPL_LIBS

Expand All @@ -16,6 +16,8 @@ nn = 100

@test size(qr(sprandn(m, n, 0.1)).Q) == (m, m)

@test repr("text/plain", qr(sprandn(4, 4, 0.5)).Q) == "4×4 $(SparseArrays.SPQR.QRSparseQ{Float64, Int})"

@testset "element type of A: $eltyA" for eltyA in (Float64, ComplexF64)
if eltyA <: Real
A = sparse([1:n; rand(1:m, nn - n)], [1:n; rand(1:n, nn - n)], randn(nn), m, n)
Expand Down