How am I assigning this expression wrong?

Hello,

I have two things I want to mention related to the same problem.

  1. I came across this problem where I believe I’m using an expression holder as described in the documentation but I’m still getting an error that says there is a conversion problem. The weirder thing is that the minimization works for a specific dimension without throwing an error and throws this error for other dimensions. Here is what it looks like:
cvx_begin
    variable u(N^2)
    expression coeff(N, N)

    coeff = Phi(u);
    minimize(norm(coeff, 1))
    subject to
        norm(A * u - b, 2) <= eta
cvx_end

For example, when u is an 8x8 binary image, there are no problems even if I don’t declare coeff using ‘expression coeff(N, N)’ and at other dimensions like 16x16 or 32x32 for example, I get the following error:

coeff = Phi(u);
^^^^^^^
Caused by:
Error using double
Conversion to double from cvx is not possible.

Also the previous topics related to this error on the forum didn’t really help since I believe I’m correctly using expression.

  1. I don’t know if it is useful but Phi is a function that takes an NxN image and returns an NxN double image. Nothing in Phi is really specific to the dimension of the image so I’m not sure why it works for some dimensions and not others. There is technically another way I can output a flattened version of what Phi(u) outputs but that requires computing a very large matrix of size (N^2)x(N^2), let’s call it P, and then I can do the minimization:

minimize(norm(P*u, 1))

This actually works for all N but it is unfortunately very slow even for N = 64, and if I’m not mistaken using a function handle like Phi should make things faster if I can make it work for all dimensions. Please let me know if I’m mistaken about this.

Thank you for your help in advance!

You haven’t provided reproducible code, so it is hard to say what is going on. Maybe something in Phi isn’t correct, but you get away with it for certain dimensions. So perhaps a “bug” in Phi, or if not, perhaps a bug in CVX.

expression statement is only needed when using indexing on the LHS of an assignment. It is not needed when the expression is assigned 'all at once", as in
coeff = Phi(u); I think that in this case, the expression coeff(N, N) declaration is effectively overwritten (superseded) by coeff = Phi(u), and therefore that declaration has no actual effect.

Thank you Mark. Phi basically just returns the wavelet coefficients of the image up to a certain fixed scale. It is just a function handle:

Phi = @(u) FWT2_PO(reshape(u, N, N), scale, nVanishingMoments);

where FWT2_PO is the 2D wavelet transform provided by the Wavelab 850 library, the code for the function can be found here. scale and nVanishingMoments are two constants. This function uses a lot of auxiliary functions from the library so it is difficult to post the complete code. I’m sorry if that isn’t sufficient information, is there a way I can debug what Phi is doing wrong when CVX calls it?

I’ll leave you to do the debugging, sorting through the auxiliary functions, etc. You can insert statements, breakpoints, etc. to see what the various objects are (dimension and object type). Because u is a CVX variable, there is potential for things to violate CVX’s rules.