Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/adjtrans.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export AdjointLinearOperator, TransposeLinearOperator, adjoint, transpose
export AdjointLinearOperator, TransposeLinearOperator, ConjugateLinearOperator,
adjoint, transpose, conj

# From julialang:stdlib/LinearAlgebra/src/adjtrans.jl
struct AdjointLinearOperator{T} <: AbstractLinearOperator{T}
Expand Down Expand Up @@ -37,6 +38,7 @@ size(A :: ConjugateLinearOperator, d :: Int) = size(A.parent, d)
for f in [:hermitian, :ishermitian, :symmetric, :issymmetric]
@eval begin
$f(A :: AdjTrans) = $f(A.parent)
$f(A :: ConjugateLinearOperator) = $f(A.parent)
end
end

Expand Down Expand Up @@ -89,14 +91,17 @@ end

function *(op :: ConjugateLinearOperator, v :: AbstractVector)
p = op.parent
return conj.(p * v)
return conj.(p * conj.(v))
end

-(op :: AdjointLinearOperator) = adjoint(-op.parent)
-(op :: AdjointLinearOperator) = adjoint(-op.parent)
-(op :: TransposeLinearOperator) = transpose(-op.parent)
-(op :: ConjugateLinearOperator) = conj(-op.parent)

*(op :: AdjointLinearOperator, x :: Number) = adjoint(op.parent * x)
*(op :: AdjointLinearOperator, x :: Number) = adjoint(op.parent * conj(x))
*(op :: TransposeLinearOperator, x :: Number) = transpose(op.parent * x)
*(op :: ConjugateLinearOperator, x :: Number) = conj(op.parent * conj(x))

*(x :: Number, op :: AdjointLinearOperator) = adjoint(x * op.parent)
*(x :: Number, op :: AdjointLinearOperator) = adjoint(conj(x) * op.parent)
*(x :: Number, op :: TransposeLinearOperator) = transpose(x * op.parent)
*(x :: Number, op :: ConjugateLinearOperator) = conj(conj(x) * op.parent)
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ using Test, TestSetExtensions, LinearOperators
include("test_aux.jl")

include("test_linop.jl")
include("test_adjtrans.jl")
include("test_cat.jl")
include("test_lbfgs.jl")
include("test_lsr1.jl")
Expand Down
38 changes: 38 additions & 0 deletions test/test_adjtrans.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
function test_adjtrans()
@testset ExtendedTestSet "Adjoint/Transpose/Conjugate" begin
A = rand(5,3) + im * rand(5,3)
opA = LinearOperator(A)

aopA = AdjointLinearOperator(opA)
copA = ConjugateLinearOperator(opA)
topA = TransposeLinearOperator(opA)

for (foo,fop) in [(adjoint, aopA),
(conj, copA),
(transpose, topA)]
@test foo(opA) === fop
@test Matrix(fop) == foo(A)
@test foo(fop) === opA

@test Matrix(-fop) == foo(-A)
@test Matrix((2 + 3im) * fop) == (2 + 3im) * foo(A)
@test Matrix(fop * (2 + 3im)) == foo(A) * (2 + 3im)
end

@test adjoint(topA) === copA
@test adjoint(copA) === topA
@test conj(aopA) === topA
@test conj(topA) === aopA
@test transpose(copA) === aopA
@test transpose(aopA) === copA

v = rand(5) + im * rand(5)
@test aopA * v == adjoint(A) * v
@test topA * v == transpose(A) * v

v = rand(3) + im * rand(3)
@test copA * v == conj(A) * v
end
end

test_adjtrans()
8 changes: 8 additions & 0 deletions test/test_linop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ function test_linop()
@testset ExtendedTestSet "Basic operations" begin
for op = (LinearOperator(A1), LinearOperator(A1')',
transpose(LinearOperator(transpose(A1))),
conj(LinearOperator(conj(A1))),
PreallocatedLinearOperator(A1))
show(op);

Expand Down Expand Up @@ -437,6 +438,13 @@ function test_linop()
A = simple_matrix(ComplexF64, 5, 5)
@test_throws LinearOperatorException opCholesky(A, check=true) # Not Hermitian / positive definite
@test_throws LinearOperatorException opCholesky(-A'*A, check=true) # Not positive definite

# Adjoint of a symmetric non-hermitian
A = simple_matrix(ComplexF64, 3, 3)
A = A + transpose(A)
op = LinearOperator(3, 3, true, false, v -> A * v)
v = rand(3)
@test op' * v ≈ A' * v
end

@testset ExtendedTestSet "Type specific operator" begin
Expand Down