cvxpy / cvxpy

A Python-embedded modeling language for convex optimization problems.
https://www.cvxpy.org
Apache License 2.0
5.35k stars 1.05k forks source link

How to define Toeplitz matrix for CVXPY variable and how to get sub/super diagonal of a CVXPY variable #1412

Open liaochunyang opened 3 years ago

liaochunyang commented 3 years ago

Is your feature request related to a problem? Please describe. I am trying to use CVXPY to solve two semidefinite programming problems. The first one contains a constraint that a Toeplitz is SPD. I define u = cvxpy.Variable(5) and I hope to return its Toeplitz matrix, whose definition can be found in this link: https://en.wikipedia.org/wiki/Toeplitz_matrix. Is there a quick way to define it? It can be done by using matrix multiplication, but the code is long.

Second semidefinite programming problem has a constraint that I need to compute the sum for each super diagonal for a variable Q defined as Q=cvxpy.Variable((N,N)). Again, it can be done by using matrix multiplication, is there a command for this purpose?

Describe the solution you'd like

Describe alternatives you've considered Both of them can be done by using matrix multiplication, but I expect some quick solutions.

Additional context Add any other context.

SteveDiamond commented 3 years ago

Sorry, neither of these operations have built in support. In the end cvxpy supports things like this via internal matrix multiplication representations, more or less like you're doing now. If you've already done the work though, then it should be fairly easy to wrap things up as simple functions, right?

liaochunyang commented 3 years ago

Thank you very much! I've done the work by using matrix multiplication, which is not hard.