Skip to content

Commit 518eda6

Browse files
authored
Merge pull request #91 from JuliaAlgebra/bl/transpose
Implement transpose
2 parents c3a5b88 + bfdb3dc commit 518eda6

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

src/operators.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,14 @@ end
101101

102102
LinearAlgebra.adjoint(v::AbstractVariable) = v
103103
LinearAlgebra.adjoint(m::AbstractMonomial) = m
104-
LinearAlgebra.adjoint(t::T) where {T <: AbstractTerm} = LinearAlgebra.adjoint(coefficient(t)) * monomial(t)
104+
LinearAlgebra.adjoint(t::AbstractTerm) = LinearAlgebra.adjoint(coefficient(t)) * monomial(t)
105105
LinearAlgebra.adjoint(p::AbstractPolynomialLike) = polynomial(map(LinearAlgebra.adjoint, terms(p)))
106106

107+
LinearAlgebra.transpose(v::AbstractVariable) = v
108+
LinearAlgebra.transpose(m::AbstractMonomial) = m
109+
LinearAlgebra.transpose(t::AbstractTerm) = LinearAlgebra.transpose(coefficient(t)) * monomial(t)
110+
LinearAlgebra.transpose(p::AbstractPolynomialLike) = polynomial(map(LinearAlgebra.transpose, terms(p)))
111+
107112
LinearAlgebra.dot(p1::AbstractPolynomialLike, p2::AbstractPolynomialLike) = p1' * p2
108113
LinearAlgebra.dot(x, p::AbstractPolynomialLike) = x' * p
109114
LinearAlgebra.dot(p::AbstractPolynomialLike, x) = p' * x

test/monomial.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,9 @@ const MP = MultivariatePolynomials
4646
@test monic(x^2) == x^2
4747

4848
@test MP._div(2x^2*y[1]^3, x*y[1]^2) == 2x*y[1]
49+
50+
@test transpose(x) == x
51+
@test adjoint(x) == x
52+
@test transpose(x^2) == x^2
53+
@test adjoint(x^2) == x^2
4954
end

test/polynomial.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ const MP = MultivariatePolynomials
104104
end
105105

106106
@test (x + y)' == x + y
107+
@test transpose(x + y) == x + y
108+
@test transpose([1 2; 3 4] * x) == [1 3; 2 4] * x
107109

108110
@test removemonomials(4x^2*y + x*y + 2x, [x*y]) == 4x^2*y + 2x
109111

0 commit comments

Comments
 (0)