Skip to content

Commit a17879e

Browse files
committed
Merge branch 'master' of github.com:JuliaLang/julia
2 parents b2f91fa + 884d5df commit a17879e

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

base/linalg.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ include("linalg/diagonal.jl")
208208
include("linalg/bidiag.jl")
209209
include("linalg/rectfullpacked.jl")
210210
include("linalg/givens.jl")
211-
211+
include("linalg/special.jl")
212212
include("linalg/bitarray.jl")
213213

214214
include("linalg/sparse.jl")

base/linalg/diagonal.jl

-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ isposdef(D::Diagonal) = all(D.diag .> 0)
2323

2424
+(Da::Diagonal, Db::Diagonal) = Diagonal(Da.diag + Db.diag)
2525
-(Da::Diagonal, Db::Diagonal) = Diagonal(Da.diag - Db.diag)
26-
-{T}(D::Diagonal{T}, M::AbstractMatrix{T}) = full(D) - M
27-
-{T}(M::AbstractMatrix{T}, D::Diagonal{T}) = M - full(D)
2826

2927
*{T<:Number}(x::T, D::Diagonal) = Diagonal(x * D.diag)
3028
*{T<:Number}(D::Diagonal, x::T) = Diagonal(D.diag * x)

base/linalg/special.jl

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#Methods operating on different special matrix types
2+
3+
#Constructs two method definitions taking into account (assumed) commutativity
4+
# e.g. @commutative f{S,T}(x::S, y::T) = x+y is the same is defining
5+
# f{S,T}(x::S, y::T) = x+y
6+
# f{S,T}(y::T, x::S) = f(x, y)
7+
macro commutative(myexpr)
8+
@assert myexpr.head===:(=) || myexpr.head===:function #Make sure it is a function definition
9+
y = copy(myexpr.args[1].args[2:end])
10+
reverse!(y)
11+
reversed_call = Expr(:(=), Expr(:call,myexpr.args[1].args[1],y...), myexpr.args[1])
12+
esc(Expr(:block, myexpr, reversed_call))
13+
end
14+
15+
for op in (:+, :-)
16+
#matrixtype1 is the sparser matrix type
17+
for (idx, matrixtype1) in enumerate([:Diagonal, :Bidiagonal, :Tridiagonal, :Triangular, :Matrix])
18+
#matrixtype2 is the denser matrix type
19+
for matrixtype2 in [:Diagonal, :Bidiagonal, :Tridiagonal, :Triangular, :Matrix][idx+1:end]
20+
@eval begin #TODO quite a few of these conversions are NOT defined...
21+
($op)(A::($matrixtype1), B::($matrixtype2)) = ($op)(convert(($matrixtype2), A), B)
22+
($op)(A::($matrixtype2), B::($matrixtype1)) = ($op)(A, convert(($matrixtype2), B))
23+
end
24+
end
25+
end
26+
27+
#matrixtype1 is the sparser matrix type
28+
for (idx, matrixtype1) in enumerate([:SymTridiagonal])
29+
#matrixtype2 is the denser matrix type
30+
for matrixtype2 in [:Tridiagonal, :Triangular, :Matrix][idx+1:end]
31+
@eval begin
32+
($op)(A::($matrixtype1), B::($matrixtype2)) = ($op)(convert(($matrixtype2), A), B)
33+
($op)(A::($matrixtype2), B::($matrixtype1)) = ($op)(A, convert(($matrixtype2), B))
34+
end
35+
end
36+
end
37+
end
38+

0 commit comments

Comments
 (0)