JuliaSmoothOptimizers / LinearOperators.jl

Linear Operators for Julia
Other
150 stars 32 forks source link

Scalar product returns an Array #221

Closed tmigot closed 2 years ago

tmigot commented 2 years ago

Using InverseLBFGSOperator, I got the following issue:

using LinearOperators
n = 3
g = rand(n)
H = InverseLBFGSOperator(n)
g' * H * g # returns an Array of size 1
g' * (H * g) # returns a Number
geoffroyleconte commented 2 years ago

With the priority of operations, I think that g' * H is an AbstractLinearOperator, and multiplying by a vector returns a vector. Is this really an issue? Even if the result should be of size 1, the user might want to keep the output of the product as a vector.

geoffroyleconte commented 2 years ago

Actually we could try to implement g' * H = a which is (H' * g)' = a. However if the user needs g' * H as an AbstractLinearOperator he would have to manually create opgT = LinearOperator(g') and then do opgT * H. @dpo what do you think about this?

tmigot commented 2 years ago

I am not sure how to implement it. I think we should be consistent with the way matrices are working:

n = 3
g = rand(n)
H = rand(n, n)
g' * H * g # returns a Number
g' * (H * g) # returns a Number