JuliaSmoothOptimizers / JuliaSmoothOptimizers/LinearOperators.jl

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

Open
#103 3 comments 0 reactions 0 assignees View on GitHub
enhancement up-for-grabs
Dominant language
Julia
Stars
209
Forks
46
Avg merge
6h 50m
Merged PRs (30d)
1

Description

`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.

```julia
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

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.