|
"James Tursa" <aclassyguy_with_a_k_not_a_c@hotmail.com> wrote in message <h619lq$hka$1@fred.mathworks.com>...
> "David Hanau" <hanaud@gmail.com.REMTHIS> wrote in message <h61543$anv$1@fred.mathworks.com>...
> >
> > Compiling C functions with Lcc in Matlab is have the following (classic) error:
> >
> > Error sparsesvd_partialeig_matlab.c: 86 operands of = have illegal types `pointer to incomplete struct mxArray_tag defined at C:\MATLAB6p1\extern\include\matrix.h 154' and `int'
> >
> > for the last line of this code:
> >
> > mxArray *output[3],*input[4];
> >
> > mexEvalString("options.disp=0;"); // for use in calling Matlab function eigs
> > mexEvalString("options.maxit=500;"); // for use in calling Matlab function eigs
> > input[0] = mxCreateDoubleMatrix(n,n,mxREAL); // for use in calling Matlab function eigs
> > input[1] = mxCreateDoubleMatrix(1,1,mxREAL);
> > input[2]= mxCreateString("la");
> > input[3]= mexGetVariable("caller","options");
> >
>
> I think you will have to post your complete routine, if it isn't too long.
>
> James Tursa
This code works and the last releave of MatLab bur not on my V6.1
I post only part of my files. They are really big and I don't think the rest of the code would be relevant here.
the sparseesvd.h:
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <mex.h>
#include <matrix.h>
#include <string.h>
#ifdef WIN32
#include <malloc.h>
extern void dsaupd();
extern void dseupd();
#endif
the sparse_rank_one_partialeig_matlab.c
#include "sparsesvd.h"
void sparse_rank_one_partialeig_matlab(double *Amat, int n, double rho, double gapchange, int MaxIter, double *Xmat, double *Umat, double *uvec, double *Fmat, double *iters, int info, int numeigs, int addeigs, int checkgap, double perceigs, int check_for_more_eigs, double *dualitygap_alliter, double *cputime_alliter, double *perceigs_alliter)
{
// Hard parameters
int Nperiod=imaxf(1,info),dspca_finished=0;
int work_size=3*n+n*n,changedmu=0;
// Working variables
double d1,sig1,d2,sig2,norma12,mu,Ntheo,L;
double alpha,gapk;
double dmax=0.0,fmu,lambda;
int n2=n*n,incx=1,precision_flag=0,iteration_flag=0,error_flag=0;
int lwork,inflapack,indmax,k=0,i,j;
double cputime,last_time=(double)clock();double start_time=(double)clock();int left_h=0,left_m=0,left_s=0;
char jobz[1],uplo[1];
double *Vmat=(double *) calloc(n*n,sizeof(double));
double *bufmata=(double *) calloc(n*n,sizeof(double));
double *bufmatb=(double *) calloc(n*n,sizeof(double));
double *workvec=(double *) calloc(work_size,sizeof(double));
double *hvec=(double *) calloc(n,sizeof(double));
int work_size3=8*n;
double *workvec2=(double *) calloc(work_size3,sizeof(double));
int *iwork=(int *) calloc(5*n,sizeof(int));
double *numeigs_matlab=(double *) calloc(1,sizeof(double));
double *evector_temp=(double *) calloc(n*n,sizeof(double));
double *evalue=(double *) calloc(n*n,sizeof(double));
double *evector_store=(double *) calloc(n*n,sizeof(double));
double eigcut,tolweight=.75,tol=.01;
int *count=(int *) calloc(n,sizeof(int));
mxArray *output[3],*input[4];
double *Fmattemp=(double *) calloc(n*n,sizeof(double));
double *Xmattemp=(double *) calloc(n*n,sizeof(double));
int checkgap_count=0; // added for test variables
// Start...
if (info>=1)
{
mexPrintf("DSPCA starting ... \n");
mexEvalString("drawnow;");
}
// Test malloc results
if ((Fmat==NULL) || (Vmat==NULL) || (bufmata==NULL) || (bufmatb==NULL)|| (workvec==NULL) || (hvec==NULL) ||(evector_temp==NULL)||(evector_store==NULL)||(evalue==NULL)||(iwork==NULL)||(workvec2==NULL)||(numeigs_matlab==NULL)||(Fmattemp==NULL)||(Xmattemp==NULL))
{
mexPrintf("DSPCA: memory allocation failed ... \n");
mexEvalString("drawnow;");return;
}
eigcut=(1-tolweight)*(tol/10)/(rho*pow(n,1.5)); // scale delta (tol/10) to get eig threshold
tol=tolweight*tol; // scale of .5 for partial eig precision
mexEvalString("options.disp=0;"); // for use in calling Matlab function eigs
mexEvalString("options.maxit=500;"); // for use in calling Matlab function eigs
input[0] = mxCreateDoubleMatrix(n,n,mxREAL); // for use in calling Matlab function eigs
input[1] = mxCreateDoubleMatrix(1,1,mxREAL);
input[2]= mxCreateString("la");
input[3]= mexGetVariable("caller","options");
// First, compute some local params
d1=rho*rho*n*n/2.0;sig1=1.0;d2=log(n);sig2=0.5;norma12=1.0;mu=tol/(2.0*d2);
Ntheo=(4.0*norma12*sqrt(d1*d2/(sig1*sig2)))/tol;Ntheo=ceil(Ntheo);
L=(d2*norma12*norma12)/(2.0*sig2*tol);
alpha=0.0;cblas_dscal(n2,alpha,Xmat,incx);
cputime=start_time;
*count=0;
// eigenvalue decomposition of A+X
cblas_dcopy(n2,Xmat,incx,Vmat,incx);
alpha=1.0;
cblas_daxpy(n2,alpha,Amat,incx,Vmat,incx);
symmetrize(Vmat,bufmata,n); // symmetrize A+X so no precision problems
// do partial eigenvalue approximation to exp(A+X)
cblas_dcopy(n2,bufmata,incx,Vmat,incx);
*numeigs_matlab=1.0*numeigs;
fmu=partial_eig_matlab(n,k,mu,eigcut,bufmata,bufmatb,numeigs_matlab,
evector_temp,evector_store,evalue,input,output,
hvec,Vmat,Umat,workvec,count,dmax,addeigs,perceigs,check_for_more_eigs);
numeigs=(int)(*numeigs_matlab);
}
|