Skip to content

Commit 8495a62

Browse files
committed
Respond to AI review
1 parent c1aef8c commit 8495a62

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

src/adjtrans.jl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,11 @@ function mul!(
133133
increase_nprod!(p)
134134
end
135135
conj!(res)
136+
vc = eltype(v) <: Real ? v : conj.(v) # avoid unnecessary allocations if v has real elements
136137
if use_p5!
137-
tprod!(res, conj.(v), conj(α), conj(β))
138+
tprod!(res, vc, conj(α), conj(β))
138139
else
139-
prod3!(res, tprod!, conj.(v), conj(α), conj(β), p.Mtu5)
140+
prod3!(res, tprod!, vc, conj(α), conj(β), p.Mtu5)
140141
end
141142
conj!(res)
142143
end
@@ -199,10 +200,11 @@ function mul!(
199200
increase_nprod!(p)
200201
end
201202
conj!(res)
203+
vc = eltype(v) <: Real ? v : conj.(v) # avoid unnecessary allocations when v has real elements
202204
if use_p5!
203-
ctprod!(res, conj.(v), conj(α), conj(β))
205+
ctprod!(res, vc, conj(α), conj(β))
204206
else
205-
prod3!(res, ctprod!, conj.(v), conj(α), conj(β), p.Mtu5)
207+
prod3!(res, ctprod!, vc, conj(α), conj(β), p.Mtu5)
206208
end
207209
conj!(res)
208210
end
@@ -234,7 +236,8 @@ function mul!(
234236
β,
235237
) where {T, S}
236238
p = op.parent
237-
mul!(res, p, conj.(v), α, β)
239+
vc = eltype(v) <: Real ? v : conj.(v) # avoid unnecessary allocations if v has real elements
240+
mul!(res, p, vc, α, β)
238241
conj!(res)
239242
end
240243

@@ -246,7 +249,7 @@ function mul!(
246249
β,
247250
) where {T, S}
248251
p = op.parent
249-
mul!(res, p, v, α, β) # this gets called for A'*v when v is real, so we can skip the conjugation
252+
mul!(res, p, v, α, β) # we can skip `conj.(v)` since it has real elements (this avoids unnecessary allocations)
250253
conj!(res)
251254
end
252255

test/test_adjtrans.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,14 @@ function test_adjtrans()
2727
v = rand(5) + im * rand(5)
2828
@test aopA * v == adjoint(A) * v
2929
@test topA * v == transpose(A) * v
30+
v = rand(5)
31+
@test aopA * v == adjoint(A) * v
32+
@test topA * v == transpose(A) * v
3033

3134
v = rand(3) + im * rand(3)
3235
@test copA * v == conj(A) * v
36+
v = rand(3)
37+
@test copA * v == conj(A) * v
3338
end
3439
end
3540

@@ -74,9 +79,15 @@ function test_derived_adjoint()
7479
v = rand(5) + im * rand(5)
7580
@test aopA * v == adjoint(A) * v
7681
@test topA * v == transpose(A) * v
82+
v = rand(5)
83+
@test aopA * v == adjoint(A) * v
84+
@test topA * v == transpose(A) * v
85+
7786

7887
v = rand(3) + im * rand(3)
7988
@test copA * v == conj(A) * v
89+
v = rand(3)
90+
@test copA * v == conj(A) * v
8091
end
8192
end
8293

@@ -121,9 +132,15 @@ function test_derived_transpose()
121132
v = rand(5) + im * rand(5)
122133
@test aopA * v == adjoint(A) * v
123134
@test topA * v == transpose(A) * v
135+
v = rand(5)
136+
@test aopA * v == adjoint(A) * v
137+
@test topA * v == transpose(A) * v
138+
124139

125140
v = rand(3) + im * rand(3)
126141
@test copA * v == conj(A) * v
142+
v = rand(3)
143+
@test copA * v == conj(A) * v
127144
end
128145
end
129146

0 commit comments

Comments
 (0)