JuliaSmoothOptimizers / LinearOperators.jl

Linear Operators for Julia
Other
150 stars 32 forks source link

Bug: adjoint(opEye()) * randn(10) #308

Closed JakobAsslaender closed 7 months ago

JakobAsslaender commented 9 months ago

Hi everyone,

I observed the following bug:

julia> adjoint(opEye()) * randn(10)
ERROR: type opEye has no field nrow
Stacktrace:
 [1] getproperty(x::opEye, f::Symbol)
   @ Base ./Base.jl:37
 [2] size(op::opEye)
   @ LinearOperators ~/.julia/packages/LinearOperators/WS4fM/src/abstract.jl:194
 [3] size(A::AdjointLinearOperator{Any, opEye})
   @ LinearOperators ~/.julia/packages/LinearOperators/WS4fM/src/adjtrans.jl:62
 [4] *(op::AdjointLinearOperator{Any, opEye}, v::Vector{Float64})
   @ LinearOperators ~/.julia/packages/LinearOperators/WS4fM/src/operations.jl:41
 [5] top-level scope
   @ REPL[3]:1

I think the problem is that *(A::opEye, x) has a special implementation, but for the adjoint, it falls back to the generic implementation of *(A::AdjointLinearOperator, x) which assumes a fully-described LinearOperator.

The bug should be fixed (or rather avoided) when adding the following code

adjoint(A::opEye) = A
transpose(A::opEye) = A
conj(A::opEye) = A

which will ensure that the *(A::opEye, x) implementations are used. But I am sure there are other solutions.

Happy to create a PR -- LMK. Thanks. -ja

geoffroyleconte commented 9 months ago

Hi, thank you for spotting this, I opened a PR with your suggestions: https://github.com/JuliaSmoothOptimizers/LinearOperators.jl/pull/309

dpo commented 7 months ago

Fixed in #309.