[Csdp] Error "Function is not defined for sparse inputs." during writesdp.m

Brian Borchers borchers at nmt.edu
Wed Nov 10 15:02:38 EST 2010


On Tue, Nov 9, 2010 at 4:30 PM, Henri Kjellberg
<henrikjellberg at gmail.com> wrote:
> Hi,
> I am exporting a model from yalmip and attempting to run it in CSDP.
> [mdl] = export(F,obj,sdpsettings('solver','csdp'));
>  When I try and feed the model to csdp.m I get the following error:
> ??? Error using ==> fprintf
> Function is not defined for sparse inputs.
> Error in ==> writesdpa at 325
>     fprintf(fid,'%d %d %d %d %.18e\n',[0 nsdpblocks+1 i i -c(i)]);
> Error in ==> csdp at 165
> ret=writesdpa([fname '.dat-s'],At,b,c,K,pars);
> Error in ==> sdpControl at 126
> csdp(mdl.At,mdl.b,mdl.C,mdl.K,mdl.pars)
> Is my model incompatible with CSDP or am I doing something else wrong?
> I am running MATLAB 2010 on an OpenSuse 11.2 desktop if that matters...

It turns out that the Mathworks has made an incompatible change to the
MATLAB language in R2010a that breaks the MATLAB interface to CSDP
(and will probably break many other codes as well...)  The change is
described in the release notes as:

>Change in Indexing for Sparse Matrix Input

>Now subscripted reference into a sparse matrix always returns a sparse
>matrix. In previous versions of MATLAB, using a double scalar to index
>into a sparse matrix resulted in full scalar output.

Consider the following example:

>> c=sparse([1; 2; 0; 0; 5]);
>> fprintf(1,'c(5) is %f\n',c(5))

??? Error using ==> fprintf
Function is not defined for sparse inputs.

There's a relatively simple workaround:
 >> fprintf(1,'c(5) is %f\n',full(c(5)))
c(5) is 5.000000

I've modified the MATLAB code in CSDP to use the "full()" work around.
 The modified code is available in the subversion repository in the
trunk version of CSDP.   If you've encountered this "fprintf Function
is not defined for sparse inputs" error message while using CSDP, then
you'll want the updated version of the MATLAB interface.

-- 
Brian Borchers                          borchers at nmt.edu
Department of Mathematics      http://www.nmt.edu/~borchers/
New Mexico Tech                       Phone: (575) 322-2592
Socorro, NM 87801                   FAX: (575) 835-5366




More information about the Csdp mailing list