Convex.jl icon indicating copy to clipboard operation
Convex.jl copied to clipboard

Scalar indexing of row of matrix creates row vector, causing incorrect `dot`

Open ericphanson opened this issue 1 year ago • 1 comments

julia> x = Variable(2,2)
Variable
size: (2, 2)
sign: real
vexity: affine
id: 936…769

julia> set_value!(x, ones(2,2))
2×2 Matrix{Float64}:
 1.0  1.0
 1.0  1.0

julia> evaluate(x[2, :])
1×2 Matrix{Float64}:
 1.0  1.0

julia> evaluate(x)[2, :]
2-element Vector{Float64}:
 1.0
 1.0

In particular this causes dot to be incorrect: https://discourse.julialang.org/t/convex-jl-constraints-not-enforced/102439/2.

ericphanson avatar Aug 03 '23 12:08 ericphanson

The proper fix for this I think is to respect the difference between e.g. a 1x1 matrix and an scalar, but Convex.jl still has the MATLABism of conflating those all over the codebase, treating everything as a matrix.

That is a pretty big lift though. But this bug is pretty bad, it would be good to find a quicker fix, maybe restricted to getindex.

ericphanson avatar Dec 29 '23 15:12 ericphanson