Skip to content

Commit

Permalink
Merge pull request JuliaLang#11989 from JuliaLang/anj/fixqr
Browse files Browse the repository at this point in the history
Fix \ for underdetermined systems of integers
  • Loading branch information
andreasnoack committed Jul 2, 2015
2 parents 126b5d4 + 1bde4d6 commit b6ae1df
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
18 changes: 8 additions & 10 deletions base/linalg/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -389,18 +389,16 @@ end

(\)(a::Vector, B::StridedVecOrMat) = (\)(reshape(a, length(a), 1), B)

for (T1,PIVOT) in ((BlasFloat,Val{true}),(Any,Val{false}))
@eval function (\){T<:$T1}(A::StridedMatrix{T}, B::StridedVecOrMat)
m, n = size(A)
if m == n
if istril(A)
return istriu(A) ? \(Diagonal(A),B) : \(LowerTriangular(A),B)
end
istriu(A) && return \(UpperTriangular(A),B)
return \(lufact(A),B)
function (\)(A::StridedMatrix, B::StridedVecOrMat)
m, n = size(A)
if m == n
if istril(A)
return istriu(A) ? \(Diagonal(A),B) : \(LowerTriangular(A),B)
end
return qrfact(A,$PIVOT)\B
istriu(A) && return \(UpperTriangular(A),B)
return \(lufact(A),B)
end
return qrfact(A,Val{true})\B
end

## Moore-Penrose pseudoinverse
Expand Down
2 changes: 1 addition & 1 deletion test/choosetests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function choosetests(choices = [])

linalgtests = ["linalg1", "linalg2", "linalg3", "linalg4",
"linalg/lapack", "linalg/triangular", "linalg/tridiag",
"linalg/bidiag", "linalg/diagonal",
"linalg/bidiag", "linalg/diagonal", "linalg/dense",
"linalg/pinv", "linalg/givens", "linalg/cholesky",
"linalg/lu", "linalg/symmetric", "linalg/generic"]
if Base.USE_GPL_LIBS
Expand Down
4 changes: 3 additions & 1 deletion test/linalg/bidiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ for relty in (Float32, Float64, BigFloat), elty in (relty, Complex{relty})
debug && println("Generic Mat-vec ops")
@test_approx_eq T*dv Tfull*dv
@test_approx_eq T'*dv Tfull'*dv
@test_approx_eq T/dv' Tfull/dv'
if relty != BigFloat # not supported by pivoted QR
@test_approx_eq T/dv' Tfull/dv'
end

debug && println("Diagonals")
@test diag(T,2) == zeros(elty, n-2)
Expand Down
4 changes: 4 additions & 0 deletions test/linalg/dense.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
using Base.Test

# Check that non-floats are correctly promoted
@test_approx_eq [1 0 0; 0 1 0]\[1,1] [1;1;0]

0 comments on commit b6ae1df

Please sign in to comment.