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
11 changes: 11 additions & 0 deletions src/adjtrans.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function show(io :: IO, op :: ConjugateLinearOperator)
end

function *(op :: AdjointLinearOperator, v :: AbstractVector)
length(v) == size(op.parent, 1) || throw(LinearOperatorException("shape mismatch"))
p = op.parent
ishermitian(p) && return p * v
p.ctprod !== nothing && return p.ctprod(v)
Expand All @@ -71,6 +72,7 @@ function *(op :: AdjointLinearOperator, v :: AbstractVector)
end

function *(op :: TransposeLinearOperator, v :: AbstractVector)
length(v) == size(op.parent, 1) || throw(LinearOperatorException("shape mismatch"))
p = op.parent
issymmetric(p) && return p * v
p.tprod !== nothing && return p.tprod(v)
Expand All @@ -89,3 +91,12 @@ function *(op :: ConjugateLinearOperator, v :: AbstractVector)
p = op.parent
return conj.(p * v)
end

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

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

*(x :: Number, op :: AdjointLinearOperator) = adjoint(x * op.parent)
*(x :: Number, op :: TransposeLinearOperator) = transpose(x * op.parent)
13 changes: 12 additions & 1 deletion test/test_linop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ function test_linop()
A1 = simple_matrix(ComplexF64, nrow, ncol)

@testset "Basic operations" begin
for op = (LinearOperator(A1), PreallocatedLinearOperator(A1))
for op = (LinearOperator(A1), LinearOperator(A1')',
transpose(LinearOperator(transpose(A1))),
PreallocatedLinearOperator(A1))
show(op);

@testset "Data type" begin
Expand Down Expand Up @@ -471,6 +473,15 @@ function test_linop()
mul!(y, op, x)
@test y == [2.0; 1.0]
end

# Issue #107
@testset "Unary and scalar operations on Adjoint and Transpose operators" begin
op = LinearOperator(rand(5, 3))
for adjtrans in [adjoint, transpose]
@test Matrix(adjtrans(-op)) == Matrix(-adjtrans(op))
@test Matrix(adjtrans(2 * op)) == Matrix(2 * adjtrans(op))
end
end
end

test_linop()