Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matrix(op) may generate incorrect result if op * x changes x #103

Open
andreasvarga opened this issue Oct 23, 2019 · 3 comments
Open

Matrix(op) may generate incorrect result if op * x changes x #103

andreasvarga opened this issue Oct 23, 2019 · 3 comments

Comments

@andreasvarga
Copy link

andreasvarga commented Oct 23, 2019

Matrix(op) may generate incorrect result in the case when op * x changes the values stored in x. Typical example is when op is a linear equation solver which overwrites the result in the provided right hand side. Then the repeated computation of op * ei in the following code may lead to a change of ei after each execution of op * ei. A solution would be to move

ei = zeros(eltype(op), n)

inside the loop. Otherwise, the change of x when computing op * x must be explicitly forbiden.

function Base.Matrix(op :: AbstractLinearOperator)
  (m, n) = size(op)
  A = Array{eltype(op)}(undef, m, n)
  ei = zeros(eltype(op), n)
  for i = 1 : n
    ei[i] = 1
    A[:, i] = op * ei
    ei[i] = 0
  end
  return A
end
@dpo
Copy link
Member

dpo commented Oct 23, 2019

In-place operators are not supported at this time, but they would be a welcome addition. Again, I would recommend creating a special type InPlaceOperator <: AbstractLinearOperator and redefining Matrix(op) for them. I'll be happy to review a pull request!

@andreasvarga
Copy link
Author

andreasvarga commented Oct 24, 2019 via email

@dpo
Copy link
Member

dpo commented Oct 24, 2019

If L is an arbitrary linear operator, the condition Matrix(L)’ = Matrix(L’) must always be fulfilled?

Yes it should be. If you find a counterexample, please open a new issue. Note also that we're currently revising the design of adjoint and transpose operators in #104.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants