Reshape error for " a' * a " in scalar case

Hi,

I’m fairly new to CVX, and I’ve encountered some behavior of CVX that is unintuitive to me.
The expression: a’ * a, causes an error in “cvx/reshape”, when the dimension is 1x1 (scalar).

Case 1: 1x1 (does not work)

clear all;
close all;
clc; 

cvx_begin
    variable p(1,1) complex
    minimize(p' * p)
cvx_end

Case 2: 2x1 (does work)

clear all;
close all;
clc; 

cvx_begin
    variable p(2,1) complex
    minimize(p' * p)
cvx_end

Error occurring in CVX:

Error using cvx/reshape
To RESHAPE the number of elements must not change.

Error in geo_mean_cone (line 339)
    xt( map(1,:), : ) == reshape( cone(1,1,:,:), [nm,nv] );

Error in cvx/pow_cvx (line 208)
                { cat( nd, yt, ones(sz) ), cvx_accept_convex(xt) } == geo_mean_cone( sw, nd, [1/pt,1-1/pt], 'cabs' );

Error in cvx/pow_abs (line 13)
y = pow_cvx( x, p, 'pow_abs' );

Error in cvx/square_abs (line 6)
cvx_optval = pow_abs( x, 2 );

Error in  .*  (line 257)
                cvx_optval = alpha .* square_abs( y );

Error in  *  (line 36)
    z = feval( oper, x, y );

Error in Testscrpt3 (line 7)
    minimize(p' * p)

Maybe I’m missing something in the User Guide (or about convex optimization in general) , but I couldn’t find any reason why the scalar case wouldn’t work.

Best Regards
BL

I have found some information in the CVX User-Guide concerning the DCP-ruleset that CVX uses to evaluate the convexity of expressions: https://cvxr.com/cvx/doc/dcp.html

The section “Scalar quadratic functions”, directly mentions my constructed case.

In its pure form, the DCP ruleset forbids 
even the use of simple quadratic expressions such as x * x 
(assuming x is a scalar variable). 
For practical reasons, we have chosen to make an exception 
to the ruleset to allow for the recognition of certain specific 
quadratic forms that map directly to certain convex quadratic functions
(or their concave negatives) in the CVX atom library:
Scalar quadratic form CVX function
x .* x square( x ) (real x)
conj( x ) .* x square_abs( x )
y’ * y sum_square_abs( y )
(A*x-b)'Q(Ax-b) quad_form( A*x - b, Q )

Accordingly, I should have used the function sum_square_abs(p), to comply with the DCP ruleset.

Don’t know whether that’s a bug or feature.

1 Like