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

[breaking] scalar row indexing produces column vector #624

Merged
merged 6 commits into from
May 6, 2024

Conversation

ericphanson
Copy link
Collaborator

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.

Copy link

codecov bot commented May 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.82%. Comparing base (bb17c4c) to head (2cb537e).
Report is 2 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

@odow
Copy link
Member

odow commented May 5, 2024

The doc failure seems suspicious.

@odow
Copy link
Member

odow commented May 6, 2024

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: 885241

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.

@odow
Copy link
Member

odow commented May 6, 2024

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])
Copy link
Member

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

Copy link
Collaborator Author

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

Copy link
Member

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.

@odow odow changed the title Scalar row indexing produces column vector [breaking] scalar row indexing produces column vector May 6, 2024
Copy link
Member

@odow odow left a 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.

@ericphanson ericphanson merged commit de4bff2 into master May 6, 2024
10 checks passed
@ericphanson ericphanson deleted the eph/fix-509 branch May 6, 2024 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Scalar indexing of row of matrix creates row vector, causing incorrect dot
2 participants