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

Add VcatAtom #607

Merged
merged 4 commits into from
Apr 30, 2024
Merged

Add VcatAtom #607

merged 4 commits into from
Apr 30, 2024

Conversation

odow
Copy link
Member

@odow odow commented Apr 29, 2024

x-ref #603

Copy link

codecov bot commented Apr 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.84%. Comparing base (0bd470b) to head (159b1be).

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

src/atoms/affine/HcatAtom.jl Outdated Show resolved Hide resolved
# 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))))
Copy link
Member Author

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.

Copy link
Collaborator

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

Copy link
Collaborator

@ericphanson ericphanson Apr 29, 2024

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.

Copy link
Member Author

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.

Copy link
Member

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

@odow odow merged commit cc6a9b0 into master Apr 30, 2024
10 checks passed
@odow odow deleted the od/Vcat branch April 30, 2024 09:40
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.

3 participants