|
I am stumped: I can see that before I return from a MEX
routine, the output argument contains correct data. Once I
get back the output into Matlab, it is full of -1.#INF.
Why? What am I doing wrong? If you can see it, please tell me.
Thanks,
Petr
#include "mex.h"
#include "colsolconfig.h"
static int decomp_double(double *a, COLSOL_Index *maxa,
mwIndex neq);
static int decomp_float(float *a, COLSOL_Index *maxa,
mwIndex neq);
void mexFunction(
int nargout,
mxArray *pargout[ ],
int nargin,
const mxArray *pargin[ ])
{
mwIndex neq=0;
COLSOL_Index *MAXA=0;
if (!((nargin == 2))) {
mexErrMsgTxt ("Usage:\n" "
A=colsoldecomp(A,MAXA) ;") ;
}
#ifdef LARGEARRAYDIMS
if (!mxIsUint64(pargin [1])) {
mexErrMsgTxt ("colsoldecomp: MAXA must be uint64") ;
}
#else
if (!mxIsUint32(pargin [1])) {
mexErrMsgTxt ("colsoldecomp: MAXA must be uint32") ;
}
#endif
MAXA = (COLSOL_Index *) mxGetData (pargin [1]) ;
if (mxIsComplex (pargin [0])) {
mexErrMsgTxt ("colsoldecomp: A must be a real vector") ;
}
neq = max(mxGetM(pargin [1]),mxGetN(pargin [1]))-1;
if (neq<=0) {
mexErrMsgTxt ("colsoldecomp: MAXA empty, no
equations?") ;
}
printf ("nargout =%d\n",nargout);
if (mxIsClass(pargin [0], "double")) {
double *Ain= mxGetPr (pargin [0]) ;
double *Aout= 0 ;
int n;
pargout [0] = mxCreateDoubleMatrix (mxGetM(pargin
[0]), mxGetN(pargin [0]), mxREAL) ;
Aout= mxGetPr (pargout [0]) ;
//correct before modification
for (n = 0; n < MAXA [neq]; ++n) { Aout[n] =Ain[n]; }
for (n = 0; n < MAXA [neq]; ++n) { printf ("A [%d]
=%g\n",n,Aout[n]); }
if (! (decomp_double(Aout, MAXA, neq)==0)) {
mexErrMsgTxt ("colsoldecomp: A factorization
failed") ;
}
//correct after modification
for (n = 0; n < MAXA [neq]; ++n) { printf ("A [%d]
=%g\n",n,Aout [n]); }
} else if (mxIsClass(pargin [0], "single")) {
...
}
//return and find garbage. Why?
}
|