-
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
Add VcatAtom #607
Add VcatAtom #607
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #607 +/- ##
=======================================
Coverage 97.84% 97.84%
=======================================
Files 87 88 +1
Lines 5050 5066 +16
=======================================
+ Hits 4941 4957 +16
Misses 109 109 ☔ View full report in Codecov by Sentry. |
# hcat(x^T, y^T)^T = [1 3; 2 4; 5 7; 6 8] | ||
# so our final connic form produces the desired | ||
# [1, 2, 5, 6, 3, 4, 7, 8] | ||
return conic_form!(context, transpose(reduce(hcat, transpose.(x.children)))) |
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.
This part is not nice, but I don't know an alternative.
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.
One option is to manually build the operator we want to do:
return reshape(P * vec(x), size(x)...) |
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.
actually, I think that permutedims_matrix
function already does what we need:
julia> x = [1 3; 2 4]
2×2 Matrix{Int64}:
1 3
2 4
julia> y = [5 7; 6 8]
2×2 Matrix{Int64}:
5 7
6 8
julia> M = permutedims_matrix((size(x, 1),size(x,2),size(y,1)), (1,3,2))
8×8 SparseMatrixCSC{Bool, Int64} with 8 stored entries:
1 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ 1 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ 1 ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ 1 ⋅ ⋅
⋅ ⋅ 1 ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ 1 ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 1 ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 1
julia> reshape(M * vcat(vec(x),vec(y)), size(x,1) + size(y,1), size(x,2))
4×2 Matrix{Int64}:
1 3
2 4
5 7
6 8
Here I'm using the fact that permutedims_matrix
is actually the matrix implementation of X -> vec(permutedims(reshape(X, dims), p))
where here dims = (size(x, 1),size(x,2),size(y,1)
which corresponds to concatenating x
and y
in a new 3rd dimension, then (1,3,2)
does the transposing business to swap the last 2 dimensions. We end up with a vector of course, but I reshape it to the intended output dimensions to show we got it right.
To actually operate on the vectorized level in Convex IIIC we'd need to do something like z = operate(vcat, x, y)
, then generate M
and apply it on the vectorized level with operate(*, M, z)
, I think. We don't need to bother with the final reshaping since the dimensions are stored on the AbstractExpr level not the vectorized level.
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've kept as-is for now. It wasn't obvious how to generalize this to the n-ary case, and what we currently have works.
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.
We can try this refactoring in a separate PR
x-ref #603