Skip to content

Commit 72827cd

Browse files
authored
Fix show of QRSparseQ (#311)
1 parent 2632257 commit 72827cd

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

src/solvers/spqr.jl

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -357,20 +357,13 @@ function Base.show(io::IO, mime::MIME{Symbol("text/plain")}, F::QRSparse)
357357
println(io, "\nColumn permutation:")
358358
show(io, mime, F.pcol)
359359
end
360-
function Base.show(io::IO, ::MIME{Symbol("text/plain")}, Q::QRSparseQ)
361-
summary(io, Q)
360+
# TODO: remove once the AdjointQ PR is merged
361+
if QRSparseQ <: AbstractMatrix
362+
function Base.show(io::IO, ::MIME{Symbol("text/plain")}, Q::QRSparseQ)
363+
summary(io, Q)
364+
end
362365
end
363366

364-
# With a real lhs and complex rhs with the same precision, we can reinterpret
365-
# the complex rhs as a real rhs with twice the number of columns
366-
#
367-
# This definition is similar to the definition in factorization.jl except that
368-
# here we have to use \ instead of ldiv! because of limitations in SPQR
369-
370-
## Two helper methods
371-
_ret_size(F::QRSparse, b::AbstractVector) = (size(F, 2),)
372-
_ret_size(F::QRSparse, B::AbstractMatrix) = (size(F, 2), size(B, 2))
373-
374367
"""
375368
rank(::QRSparse{Tv,Ti}) -> Ti
376369
@@ -385,6 +378,16 @@ Calculate rank of `S` by calculating its QR factorization. Values smaller than `
385378
"""
386379
LinearAlgebra.rank(S::SparseMatrixCSC; tol=_default_tol(S)) = rank(qr(S; tol))
387380

381+
# With a real lhs and complex rhs with the same precision, we can reinterpret
382+
# the complex rhs as a real rhs with twice the number of columns
383+
#
384+
# This definition is similar to the definition in factorization.jl except that
385+
# here we have to use \ instead of ldiv! because of limitations in SPQR
386+
387+
## Two helper methods
388+
_ret_size(F::QRSparse, b::AbstractVector) = (size(F, 2),)
389+
_ret_size(F::QRSparse, B::AbstractMatrix) = (size(F, 2), size(B, 2))
390+
388391
function (\)(F::QRSparse{T}, B::VecOrMat{Complex{T}}) where T<:LinearAlgebra.BlasReal
389392
# |z1|z3| reinterpret |x1|x2|x3|x4| transpose |x1|y1| reshape |x1|y1|x3|y3|
390393
# |z2|z4| -> |y1|y2|y3|y4| -> |x2|y2| -> |x2|y2|x4|y4|

test/spqr.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ using Test
66
using SparseArrays.SPQR
77
using SparseArrays.CHOLMOD
88
using LinearAlgebra: I, istriu, norm, qr, rank, rmul!, lmul!, Adjoint, Transpose, ColumnNorm, RowMaximum, NoPivot
9-
using SparseArrays: sparse, sprandn, spzeros, SparseMatrixCSC
9+
using SparseArrays: SparseArrays, sparse, sprandn, spzeros, SparseMatrixCSC
1010

1111
if Base.USE_GPL_LIBS
1212

@@ -16,6 +16,8 @@ nn = 100
1616

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

19+
@test repr("text/plain", qr(sprandn(4, 4, 0.5)).Q) == "4×4 $(SparseArrays.SPQR.QRSparseQ{Float64, Int})"
20+
1921
@testset "element type of A: $eltyA" for eltyA in (Float64, ComplexF64)
2022
if eltyA <: Real
2123
A = sparse([1:n; rand(1:m, nn - n)], [1:n; rand(1:n, nn - n)], randn(nn), m, n)

0 commit comments

Comments
 (0)