-
Notifications
You must be signed in to change notification settings - Fork 121
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
[breaking] scalar row indexing produces column vector #624
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #624 +/- ##
=======================================
Coverage 97.82% 97.82%
=======================================
Files 88 88
Lines 5140 5141 +1
=======================================
+ Hits 5028 5029 +1
Misses 112 112 ☔ View full report in Codecov by Sentry. |
The doc failure seems suspicious. |
This isn't quite correct. Here's a reproducer from the docs: julia> using Convex
julia> import MathOptInterface as MOI
julia> x = Variable(2, 2)
Variable
size: (2, 2)
sign: real
vexity: affine
id: 885…241
julia> context = Convex.Context{Float64}(MOI.Utilities.Model{Float64});
julia> Y = [1 2; 3 4]
2×2 Matrix{Int64}:
1 2
3 4
julia> Convex.to_vaf(Convex.conic_form!(context, x[1, :] .* Y[1, :]'))
┌ ┐
│0.0 + 1.0 MOI.VariableIndex(1)│
│0.0 + 1.0 MOI.VariableIndex(3)│
│0.0 + 2.0 MOI.VariableIndex(1)│
│0.0 + 2.0 MOI.VariableIndex(3)│
└ ┘
julia> Convex.to_vaf(Convex.conic_form!(context, x[1:1, :] .* Y[1, :]'))
┌ ┐
│0.0 + 1.0 MOI.VariableIndex(1)│
│0.0 + 2.0 MOI.VariableIndex(3)│
└ ┘ These two calls should be the same. |
Okay, perhaps the docs are wrong, because: julia> a = [1, 2]
2-element Vector{Int64}:
1
2
julia> a .* a'
2×2 Matrix{Int64}:
1 2
2 4 |
@@ -18,7 +18,7 @@ W = ComplexVariable(n, n); | |||
objective = real(sum(diag(W))); | |||
c1 = Constraint[]; | |||
for i in 2:n | |||
push!(c1, sum(W[i, :] .* (Y[i, :]')) == inj[i]) | |||
push!(c1, sum(W[i, :] .* conj(Y[i, :])) == inj[i]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooooofff. This is pretty subtle...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! Btw maybe this could be dot
? It used to be bugged in the complex case so maybe the original author didn’t use it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to use dot
. Yeah, I assume the previous code was just trial and error to find what worked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is worth it. The next version might break existing code, but it's arguably a bug fix because the current code departs from regular Julia. There's a strong chance that any breakage is likely a bug to begin with.
fixes #509
There could be other issues like this out there, but at least this fixes that particular one, and I can't quite think of others off the top of my head.