Skip to content

Commit

Permalink
+/- interop for the Triangular types
Browse files Browse the repository at this point in the history
  • Loading branch information
kshyatt committed Sep 11, 2015
1 parent 7cd05db commit f0a35cb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
18 changes: 18 additions & 0 deletions base/linalg/special.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,24 @@ for op in (:+, :-)
end
end
end

for matrixtype1 in (:Diagonal,)
for (matrixtype2,matrixtype3) in ((:UpperTriangular,:UpperTriangular),
(:UnitUpperTriangular,:UpperTriangular),
(:LowerTriangular,:LowerTriangular),
(:UnitLowerTriangular,:LowerTriangular))
@eval begin
($op)(A::($matrixtype1), B::($matrixtype2)) = ($op)(convert(($matrixtype3), A), B)
($op)(A::($matrixtype2), B::($matrixtype1)) = ($op)(A, convert(($matrixtype3), B))
end
end
end
for matrixtype in (:SymTridiagonal,:Tridiagonal,:Bidiagonal,:Matrix)
@eval begin
($op)(A::AbstractTriangular, B::($matrixtype)) = ($op)(full(A), B)
($op)(A::($matrixtype), B::AbstractTriangular) = ($op)(A, full(B))
end
end
end

A_mul_Bc!(A::AbstractTriangular, B::QRCompactWYQ) = A_mul_Bc!(full!(A),B)
Expand Down
11 changes: 11 additions & 0 deletions test/linalg/special.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@ let a=[1.0:n;]
@test_approx_eq full(B - convert(Spectype,A)) full(B - A)
@test_approx_eq full(convert(Spectype,A) - B) full(A - B)
end

C = rand(n,n)
for TriType in [Base.LinAlg.UnitLowerTriangular, Base.LinAlg.UnitUpperTriangular, UpperTriangular, LowerTriangular]
D = TriType(C)
for Spectype in [Diagonal, Bidiagonal, Tridiagonal, Matrix]
@test full(D + convert(Spectype,A)) full(D + A)
@test full(convert(Spectype,A) + D) full(A + D)
@test full(D - convert(Spectype,A)) full(D - A)
@test full(convert(Spectype,A) - D) full(A - D)
end
end
end

#Triangular Types and QR
Expand Down

0 comments on commit f0a35cb

Please sign in to comment.