Skip to content

Commit

Permalink
Fixed up bidiag too
Browse files Browse the repository at this point in the history
  • Loading branch information
kshyatt committed Aug 13, 2015
1 parent c0818f5 commit 9a566cb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
4 changes: 2 additions & 2 deletions base/linalg/bidiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ ctranspose(M::Bidiagonal) = Bidiagonal(conj(M.dv), conj(M.ev), !M.isupper)
istriu(M::Bidiagonal) = M.isupper || all(M.ev .== 0)
istril(M::Bidiagonal) = !M.isupper || all(M.ev .== 0)

function tril(M::Bidiagonal, k::Integer=0)
function tril!(M::Bidiagonal, k::Integer=0)
n = length(M.dv)
if abs(k) > n
throw(ArgumentError("requested diagonal, $k, out of bounds in matrix of size ($n,$n)"))
Expand All @@ -127,7 +127,7 @@ function tril(M::Bidiagonal, k::Integer=0)
end
end

function triu(M::Bidiagonal, k::Integer=0)
function triu!(M::Bidiagonal, k::Integer=0)
n = length(M.dv)
if abs(k) > n
throw(ArgumentError("requested diagonal, $k, out of bounds in matrix of size ($n,$n)"))
Expand Down
43 changes: 23 additions & 20 deletions test/linalg/bidiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,29 @@ for relty in (Float32, Float64, BigFloat), elty in (relty, Complex{relty})
end

debug && println("triu and tril")
@test tril(Bidiagonal(dv,ev,'U'),-1) == Bidiagonal(zeros(dv),zeros(ev),'U')
@test tril(Bidiagonal(dv,ev,'L'),-1) == Bidiagonal(zeros(dv),ev,'L')
@test tril(Bidiagonal(dv,ev,'U'),-2) == Bidiagonal(zeros(dv),zeros(ev),'U')
@test tril(Bidiagonal(dv,ev,'L'),-2) == Bidiagonal(zeros(dv),zeros(ev),'L')
@test tril(Bidiagonal(dv,ev,'U'),1) == Bidiagonal(dv,ev,'U')
@test tril(Bidiagonal(dv,ev,'L'),1) == Bidiagonal(dv,ev,'L')
@test tril(Bidiagonal(dv,ev,'U')) == Bidiagonal(dv,zeros(ev),'U')
@test tril(Bidiagonal(dv,ev,'L')) == Bidiagonal(dv,ev,'L')
@test_throws ArgumentError tril(Bidiagonal(dv,ev,'U'),n+1)

@test triu(Bidiagonal(dv,ev,'L'),1) == Bidiagonal(zeros(dv),zeros(ev),'L')
@test triu(Bidiagonal(dv,ev,'U'),1) == Bidiagonal(zeros(dv),ev,'U')
@test triu(Bidiagonal(dv,ev,'U'),2) == Bidiagonal(zeros(dv),zeros(ev),'U')
@test triu(Bidiagonal(dv,ev,'L'),2) == Bidiagonal(zeros(dv),zeros(ev),'L')
@test triu(Bidiagonal(dv,ev,'U'),-1) == Bidiagonal(dv,ev,'U')
@test triu(Bidiagonal(dv,ev,'L'),-1) == Bidiagonal(dv,ev,'L')
@test triu(Bidiagonal(dv,ev,'L')) == Bidiagonal(dv,zeros(ev),'L')
@test triu(Bidiagonal(dv,ev,'U')) == Bidiagonal(dv,ev,'U')
@test_throws ArgumentError triu(Bidiagonal(dv,ev,'U'),n+1)

@test istril(Bidiagonal(dv,ev,'L'))
@test !istril(Bidiagonal(dv,ev,'U'))
@test tril!(Bidiagonal(dv,ev,'U'),-1) == Bidiagonal(zeros(dv),zeros(ev),'U')
@test tril!(Bidiagonal(dv,ev,'L'),-1) == Bidiagonal(zeros(dv),ev,'L')
@test tril!(Bidiagonal(dv,ev,'U'),-2) == Bidiagonal(zeros(dv),zeros(ev),'U')
@test tril!(Bidiagonal(dv,ev,'L'),-2) == Bidiagonal(zeros(dv),zeros(ev),'L')
@test tril!(Bidiagonal(dv,ev,'U'),1) == Bidiagonal(dv,ev,'U')
@test tril!(Bidiagonal(dv,ev,'L'),1) == Bidiagonal(dv,ev,'L')
@test tril!(Bidiagonal(dv,ev,'U')) == Bidiagonal(dv,zeros(ev),'U')
@test tril!(Bidiagonal(dv,ev,'L')) == Bidiagonal(dv,ev,'L')
@test_throws ArgumentError tril!(Bidiagonal(dv,ev,'U'),n+1)

@test istriu(Bidiagonal(dv,ev,'U'))
@test !istriu(Bidiagonal(dv,ev,'L'))
@test triu!(Bidiagonal(dv,ev,'L'),1) == Bidiagonal(zeros(dv),zeros(ev),'L')
@test triu!(Bidiagonal(dv,ev,'U'),1) == Bidiagonal(zeros(dv),ev,'U')
@test triu!(Bidiagonal(dv,ev,'U'),2) == Bidiagonal(zeros(dv),zeros(ev),'U')
@test triu!(Bidiagonal(dv,ev,'L'),2) == Bidiagonal(zeros(dv),zeros(ev),'L')
@test triu!(Bidiagonal(dv,ev,'U'),-1) == Bidiagonal(dv,ev,'U')
@test triu!(Bidiagonal(dv,ev,'L'),-1) == Bidiagonal(dv,ev,'L')
@test triu!(Bidiagonal(dv,ev,'L')) == Bidiagonal(dv,zeros(ev),'L')
@test triu!(Bidiagonal(dv,ev,'U')) == Bidiagonal(dv,ev,'U')
@test_throws ArgumentError triu!(Bidiagonal(dv,ev,'U'),n+1)

debug && println("Linear solver")
Tfull = full(T)
Expand Down

0 comments on commit 9a566cb

Please sign in to comment.