Skip to content

Commit

Permalink
Merge pull request #7648 from JuliaLang/cjh/fix-5927
Browse files Browse the repository at this point in the history
Defines +,- for Triangular matrices
  • Loading branch information
jiahao committed Jul 18, 2014
2 parents 465b3d8 + 993fc66 commit b6aff90
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions base/linalg/triangular.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ function Triangular{T}(A::AbstractMatrix{T}, uplo::Symbol, isunit::Bool=false)
return Triangular{T,typeof(A),uplo,isunit}(A)
end

+{T, MT, uplo}(A::Triangular{T, MT, uplo}, B::Triangular{T, MT, uplo}) = Triangular(A.data + B.data, uplo)
+{T, MT, uplo1, uplo2}(A::Triangular{T, MT, uplo1}, B::Triangular{T, MT, uplo2}) = full(A) + full(B)
-{T, MT, uplo}(A::Triangular{T, MT, uplo}, B::Triangular{T, MT, uplo}) = Triangular(A.data - B.data, uplo)
-{T, MT, uplo1, uplo2}(A::Triangular{T, MT, uplo1}, B::Triangular{T, MT, uplo2}) = full(A) - full(B)

######################
# BlasFloat routines #
######################
Expand Down
2 changes: 1 addition & 1 deletion test/linalg4.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ for relty in (Float32, Float64, BigFloat), elty in (relty, Complex{relty})
debug && println("Binary operations")
B = convert(Matrix{elty}, randn(n, n))
for (M2, TM2) in ((triu(B), Triangular(B, :U)), (tril(B), Triangular(B, :L)))
for op in (*,) #+, - not implemented
for op in (*, +, -)
@test_approx_eq full(op(TM, TM2)) op(M, M2)
@test_approx_eq full(op(TM, M2)) op(M, M2)
@test_approx_eq full(op(M, TM2)) op(M, M2)
Expand Down

0 comments on commit b6aff90

Please sign in to comment.