cvxr / CVX

A MATLAB system for disciplined convex programming
Other
226 stars 83 forks source link

CVX blkdiag bug #23

Open JBurniston opened 4 months ago

JBurniston commented 4 months ago

Copying Issue over from the forms.

The CVX override for Matlab’s blkdiag function has a crippling bug. Using blkdiag seems to create some sort of corrupted expression. Attempting to use many different types of basic operations on this expression causes errors in a reshape step. Here is a minimum working example.

dim1 = 2;
dim2 = 8;

cvx_begin sdp
variable rho1(dim1,dim1) Hermitian semidefinite;
variable rho2(dim2,dim2) Hermitian semidefinite;

expression rho(dim1+dim2,dim1+dim2)

%version 1 works
% rho(1:dim1,1:dim1) = rho1;
% rho(dim1+1:end,dim1+1:end) = rho2;

%version 2 cvx fails
rho = blkdiag(rho1,rho2);

identity = eye(dim1+dim2);
rho = rho*identity; % <-- error here

minimize trace(rho)

cvx_end

and the error:

Error using reshape
Number of elements must not change. Use [] as one of the size inputs to automatically
calculate the appropriate size for that dimension.

Error in cvx_reshape (line 52)
        x = reshape( x, s );

Error in  *  (line 173)
    z2 = cvx_reshape( xA, [ nA * sx( 1 ), sx( 2 ) ] );

Error in cvxBlkDiagTest (line 19)
rho = rho*identity; % <-- error here

It is likely linked to About”blkdiag”. Dimensions with subscripts do not match.