Skip to content

Commit a0f5016

Browse files
authored
keep the FunctionMap promise, and test (#82)
1 parent f2c533c commit a0f5016

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/functionmap.jl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function A_mul_B!(y::AbstractVector, A::FunctionMap, x::AbstractVector)
5656
end
5757

5858
function At_mul_B!(y::AbstractVector, A::FunctionMap, x::AbstractVector)
59-
issymmetric(A) && return A_mul_B!(y, A, x)
59+
(issymmetric(A) || (isreal(A) && ishermitian(A))) && return A_mul_B!(y, A, x)
6060
(length(x) == A.M && length(y) == A.N) || throw(DimensionMismatch("At_mul_B!"))
6161
if A.fc !== nothing
6262
if !isreal(A)
@@ -67,17 +67,27 @@ function At_mul_B!(y::AbstractVector, A::FunctionMap, x::AbstractVector)
6767
conj!(y)
6868
end
6969
return y
70+
elseif ishermitian(A) # but !isreal(A)
71+
x = conj(x)
72+
A_mul_B!(y, A, x)
73+
conj!(y)
74+
return y
7075
else
7176
error("transpose not implemented for $A")
7277
end
7378
end
7479

7580
function Ac_mul_B!(y::AbstractVector, A::FunctionMap, x::AbstractVector)
76-
ishermitian(A) && return A_mul_B!(y, A, x)
81+
(ishermitian(A) || (isreal(A) && issymmetric(A))) && return A_mul_B!(y, A, x)
7782
(length(x) == A.M && length(y) == A.N) || throw(DimensionMismatch("Ac_mul_B!"))
7883
if A.fc !== nothing
7984
ismutating(A) ? A.fc(y, x) : copyto!(y, A.fc(x))
8085
return y
86+
elseif issymmetric(A) # but !isreal(A)
87+
x = conj(x)
88+
A_mul_B!(y, A, x)
89+
conj!(y)
90+
return y
8191
else
8292
error("adjoint not implemented for $A")
8393
end

test/functionmap.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,13 @@ using Test, LinearMaps, LinearAlgebra
7575
v = rand(ComplexF64, 10)
7676
@test @inferred (2 * L)' * v 2 * v
7777
@test @inferred transpose(2 * L) * v 2 * v
78+
79+
L = LinearMap{ComplexF64}(identity, 10; issymmetric=true)
80+
@test L * v == v
81+
@test adjoint(L) * v == v
82+
@test transpose(L) * v == v
83+
L = LinearMap{ComplexF64}(identity, 10; ishermitian=true)
84+
@test L * v == v
85+
@test adjoint(L) * v == v
86+
@test transpose(L) * v == v
7887
end

0 commit comments

Comments
 (0)