void LTFAT_NAME(ltfatMexFnc)( int UNUSED(nlhs), mxArray *plhs[], int UNUSED(nrhs), const mxArray *prhs[] ) { int M, N, L, gl, W; // Get matrix dimensions. M= mxGetM(prhs[0]); N= ltfatGetN(prhs[0]); gl= mxGetNumberOfElements(prhs[1]); W = mxGetNumberOfElements(prhs[0])/(M*N); L=N*M; plhs[0] = ltfatCreateMatrix(L,W,LTFAT_MX_CLASSID,LTFAT_MX_COMPLEXITY); const LTFAT_TYPE* c = (const LTFAT_TYPE*) mxGetData(prhs[0]); const LTFAT_TYPE* g = (const LTFAT_TYPE*) mxGetData(prhs[1]); LTFAT_TYPE* f = (LTFAT_TYPE*) mxGetData(plhs[0]); if(gl<L) { LTFAT_NAME(idwiltiii_fb)(c,g,L,gl,W,M,f); } else { LTFAT_NAME(idwiltiii_long)(c,g,L,W,M,f); } }
void LTFAT_NAME(fftrealAtExit)() { if(LTFAT_NAME(p_old)!=0) { LTFAT_FFTW(destroy_plan)(LTFAT_NAME(p_old)); } }
static void LTFAT_NAME(dctMexAtExitFnc)() { if (LTFAT_NAME(p_old) != 0) { LTFAT_FFTW(destroy_plan)(LTFAT_NAME(p_old)); } }
void LTFAT_NAME(ltfatMexFnc)( int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] ) { // UGLY, but there are no cd_dwilt_long cs_dwilt_long functions // Other option is to use forwarder functions #undef LTFAT_NAME #ifdef LTFAT_SINGLE # define LTFAT_NAME(name) LTFAT_NAME_SINGLE(name) #else # define LTFAT_NAME(name) LTFAT_NAME_DOUBLE(name) #endif int M, N, L, W; mwSize ndim; mwSize dims[3]; // Get matrix dimensions. M=(int)mxGetScalar(prhs[2]); L=(int)mxGetScalar(prhs[3]); W = mxGetN(prhs[0]); N=L/M; dims[0]=2*M; dims[1]=N/2; if (W==1) { ndim=2; } else { ndim=3; dims[2]=W; } plhs[0] = ltfatCreateNdimArray(ndim,dims,LTFAT_MX_CLASSID,LTFAT_MX_COMPLEXITY); const LTFAT_TYPE* f = (const LTFAT_TYPE*) mxGetData(prhs[0]); const LTFAT_TYPE* g = (const LTFAT_TYPE*) mxGetData(prhs[1]); LTFAT_TYPE* cout = (LTFAT_TYPE*) mxGetData(plhs[0]); #ifdef LTFAT_COMPLEXTYPE LTFAT_NAME(dwilt_long)((const LTFAT_REAL (*)[2])f, (const LTFAT_REAL (*)[2])g, L, W, M, (LTFAT_REAL (*)[2]) cout); #else LTFAT_NAME(dwiltreal_long)(f,g,L, W, M, cout); #endif return; }
void LTFAT_NAME(ltfatMexFnc)( int UNUSED(nlhs), mxArray* plhs[], int UNUSED(nrhs), const mxArray* prhs[] ) { // Get inputs const mxArray* mxs = prhs[0]; const LTFAT_REAL* s = mxGetData(mxs); const LTFAT_REAL* tgrad = mxGetData(prhs[1]); const LTFAT_REAL* fgrad = mxGetData(prhs[2]); const double* maskDouble = mxGetData(prhs[3]); mwSize a = (mwSize)mxGetScalar(prhs[4]); LTFAT_REAL tol = (LTFAT_REAL)mxGetScalar(prhs[6]); const LTFAT_REAL* knownphase = mxGetData(prhs[8]); int phasetype = (int)mxGetScalar(prhs[7]); switch (phasetype) { case 0: phasetype = LTFAT_FREQINV; break; case 1: phasetype = LTFAT_TIMEINV; break; } // Get matrix dimensions. mwSize M = (int) mxGetScalar(prhs[5]); mwSize M2 = mxGetM(prhs[0]); mwSize N = ltfatGetN(prhs[0]); mwSize L = N * a; mwSize W = 1; if (mxGetNumberOfDimensions(mxs) > 2) W = mxGetDimensions(mxs)[2]; int* mask = ltfat_malloc(M2 * N * W * sizeof * mask); for (mwSize w = 0; w < M2 * N * W; w++ ) mask[w] = (int) maskDouble[w]; // Create output matrix and zero it. plhs[0] = ltfatCreateNdimArray(mxGetNumberOfDimensions(mxs), mxGetDimensions(mxs), LTFAT_MX_CLASSID, mxREAL); // Get pointer to output LTFAT_REAL* phase = mxGetData(plhs[0]); memcpy(phase, knownphase, M2 * N * W * sizeof * phase); if (phasetype == 2) LTFAT_NAME(maskedheapintreal)(s, tgrad, fgrad, mask, a, M, L, W, tol, phase ); else LTFAT_NAME(maskedheapintreal_relgrad)(s, tgrad, fgrad, mask, a, M, L, W, tol, phasetype, phase ); ltfat_free(mask); }
int main( int argc, char *argv[] ) { if (argc<3) { printf("Correct parameters: L, K, nrep\n"); return(1); } int nrep = 1; if (argc>3) { nrep = atoi(argv[3]); } const size_t L = atoi(argv[1]); const size_t K = atoi(argv[2]); LTFAT_REAL *f = (LTFAT_REAL*)ltfat_malloc(L*sizeof(LTFAT_REAL)); LTFAT_COMPLEXH *c = (LTFAT_COMPLEXH*)ltfat_malloc(K*sizeof(LTFAT_COMPLEXH)); LTFAT_NAME_COMPLEX(fillRand)(f,L); double o = 0.1; double deltao = 2.0*PI/100.0; double st0,st1; #ifndef CZT_WITH_PLAN st0=ltfat_time(); for (int jj=0;jj<nrep;jj++) { LTFAT_NAME(chzt)(f,L,1,K,deltao,o,c); } st1=ltfat_time(); #else LTFAT_NAME(chzt_plan) p = LTFAT_NAME(create_chzt_plan)(K,L); st0=ltfat_time(); for (int jj=0;jj<nrep;jj++) { LTFAT_NAME(chzt_with_plan)(p,f,1,deltao,o,c); } st1=ltfat_time(); LTFAT_NAME(destroy_chzt_plan)(p); #endif //printf("Length: %i, avr. %f ms \n",L,(st1-st0)/((double)nrep)); printf("%i, %f\n",L,(st1-st0)/((double)nrep)); ltfat_free(f); ltfat_free(c); }
LTFAT_API int LTFAT_NAME(fft)(LTFAT_COMPLEX in[], ltfat_int L, ltfat_int W, LTFAT_COMPLEX out[]) { LTFAT_NAME(fft_plan)* p = NULL; int status = LTFATERR_SUCCESS; CHECKSTATUS( LTFAT_NAME(fft_init)(L, W, in, out, FFTW_ESTIMATE, &p)); LTFAT_NAME(fft_execute)(p); LTFAT_NAME(fft_done)(&p); error: return status; }
LTFAT_EXTERN void LTFAT_NAME(dgtreal_ola)(const LTFAT_REAL *f, const LTFAT_REAL *g, const int L, const int gl, const int W, const int a, const int M, const int bl, LTFAT_COMPLEX *cout) { LTFAT_NAME(dgtreal_ola_plan) plan = LTFAT_NAME(dgtreal_ola_init)(g, gl, W, a, M, bl, FFTW_ESTIMATE); LTFAT_NAME(dgtreal_ola_execute)(plan, f, L, cout); LTFAT_NAME(dgtreal_ola_done)(plan); }
LTFAT_EXTERN void LTFAT_NAME(dgt_long)(const LTFAT_COMPLEX *f, const LTFAT_COMPLEX *g, const int L, const int W, const int a, const int M, LTFAT_COMPLEX *cout) { LTFAT_NAME(dgt_long_plan) plan = LTFAT_NAME(dgt_long_init)(f, g, L, W, a, M, cout, FFTW_ESTIMATE); LTFAT_NAME(dgt_long_execute)(plan); LTFAT_NAME(dgt_long_done)(plan); }
LTFAT_API void LTFAT_NAME(gabdualreal_fac)(const LTFAT_COMPLEX* gf, ltfat_int L, ltfat_int R, ltfat_int a, ltfat_int M, LTFAT_COMPLEX* gdualf) { ltfat_int h_a, h_m; LTFAT_COMPLEX* Sf; const LTFAT_COMPLEX zzero = (LTFAT_COMPLEX) 0.0; const LTFAT_COMPLEX alpha = (LTFAT_COMPLEX) 1.0; //{1.0, 0.0 }; ltfat_int N = L / a; ltfat_int c = ltfat_gcd(a, M, &h_a, &h_m); ltfat_int p = a / c; ltfat_int q = M / c; ltfat_int d = N / q; /* This is a floor operation. */ ltfat_int d2 = d / 2 + 1; Sf = LTFAT_NAME_COMPLEX(malloc)(p * p); /* Copy the contents of gf to gdualf because LAPACK overwrites it input * argument */ memcpy(gdualf, gf, sizeof(LTFAT_COMPLEX)*L * R); for (ltfat_int rs = 0; rs < c * d2; rs++) { LTFAT_NAME(gemm)(CblasNoTrans, CblasConjTrans, p, p, q * R, &alpha, gf + rs * p * q * R, p, gf + rs * p * q * R, p, &zzero, Sf, p); LTFAT_NAME(posv)(p, q * R, Sf, p, gdualf + rs * p * q * R, p); } /* Clear the work-array. */ ltfat_free(Sf); }
LTFAT_EXTERN void LTFAT_NAME_COMPLEX(dgt_fb)(const LTFAT_COMPLEX *f, const LTFAT_COMPLEX *g, const int L, const int gl, const int W, const int a, const int M, LTFAT_COMPLEX *cout) { LTFAT_NAME(dgt_fb_plan) plan = LTFAT_NAME(dgt_fb_init)(g, gl, a, M, FFTW_ESTIMATE); LTFAT_NAME(dgt_fb_execute)(plan, f, L, W, cout); LTFAT_NAME(dgt_fb_done)(plan); }
void LTFAT_NAME(ltfatMexFnc)( int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] ) { int a, M, N, L, W; double tol; const LTFAT_REAL *s, *tgrad, *fgrad; LTFAT_REAL *phase; // Get inputs s = (const LTFAT_REAL*) mxGetPr(prhs[0]); tgrad = (const LTFAT_REAL*) mxGetPr(prhs[1]); fgrad = (const LTFAT_REAL*) mxGetPr(prhs[2]); a = (int)mxGetScalar(prhs[3]); tol = mxGetScalar(prhs[4]); // Get matrix dimensions. M = mxGetM(prhs[0]); N = mxGetN(prhs[0]); L = N*a; W = 1; // Create output matrix and zero it. plhs[0] = ltfatCreateMatrix(M,N, LTFAT_MX_CLASSID, mxREAL); // Get pointer to output phase= (LTFAT_REAL*) mxGetPr(plhs[0]); LTFAT_NAME(heapint)(s,tgrad,fgrad, a, M, L, W,tol, phase); }
LTFAT_EXTERN void LTFAT_NAME_COMPLEX(idwiltiii_fb)(const LTFAT_COMPLEX *c, const LTFAT_COMPLEX *g, const ltfatInt L, const ltfatInt gl, const ltfatInt W, const ltfatInt M, LTFAT_COMPLEX *f) { const ltfatInt N = L / M; const ltfatInt M2 = 2 * M; const ltfatInt M4 = 4 * M; const LTFAT_REAL scalconst = 1.0 / sqrt(2.0); const LTFAT_COMPLEX eipi4 = cexp(I * PI / 4.0); const LTFAT_COMPLEX emipi4 = cexp(-I * PI / 4.0); LTFAT_COMPLEX *coef2 = ltfat_calloc(2 * M * N * W, sizeof * coef2); LTFAT_COMPLEX *f2 = ltfat_malloc(L * W * sizeof * f2); const LTFAT_COMPLEX *pcoef = c; LTFAT_COMPLEX *pcoef2 = coef2; PREPROC_COMPLEX LTFAT_NAME(idgt_fb)(coef2, g, L, gl, W, M, 2 * M, FREQINV, f2); POSTPROC_COMPLEX LTFAT_SAFEFREEALL(coef2, f2); }
LTFAT_EXTERN void LTFAT_NAME_REAL(idwiltiii_long)(const LTFAT_REAL *c, const LTFAT_REAL *g, const ltfatInt L, const ltfatInt W, const ltfatInt M, LTFAT_REAL *f) { const ltfatInt N = L / M; const ltfatInt M2 = 2 * M; const ltfatInt M4 = 4 * M; const LTFAT_REAL scalconst = 1.0 / sqrt(2.0); const LTFAT_COMPLEX eipi4 = cexp(I * PI / 4.0); const LTFAT_COMPLEX emipi4 = cexp(-I * PI / 4.0); LTFAT_COMPLEX *coef2 = ltfat_calloc(2 * M * N * W, sizeof * coef2); LTFAT_COMPLEX *f2 = ltfat_malloc(L * W * sizeof * f2); LTFAT_COMPLEX *g2 = ltfat_malloc(L * sizeof * g2); for (ltfatInt ii = 0; ii < L; ii++) g2[ii] = g[ii]; const LTFAT_REAL *pcoef = c; LTFAT_COMPLEX *pcoef2 = coef2; PREPROC_COMPLEX LTFAT_NAME(idgt_long)(coef2, g2, L, W, M, 2 * M, FREQINV, f2); POSTPROC_REAL LTFAT_SAFEFREEALL(coef2, f2, g2); }
void LTFAT_NAME(ltfatMexFnc)( int UNUSED(nlhs), mxArray *plhs[], int UNUSED(nrhs), const mxArray *prhs[] ) { int L, R, N, c, d, p, q; ltfatInt a,M,h_a,h_m; // Get matrix dimensions. L = mxGetM(prhs[0]); R = mxGetN(prhs[0]); a=(ltfatInt)mxGetScalar(prhs[1]); M=(ltfatInt)mxGetScalar(prhs[2]); N=L/a; c=gcd(a, M, &h_a, &h_m); p=a/c; q=M/c; d=N/q; plhs[0] = ltfatCreateMatrix(p*q*R, c*d,LTFAT_MX_CLASSID,mxCOMPLEX); LTFAT_COMPLEX* gf_combined = mxGetData(plhs[0]); const LTFAT_TYPE* g_combined = mxGetData(prhs[0]); LTFAT_NAME(wfac)(g_combined, L, R, a, M, gf_combined); }
void LTFAT_NAME(ltfatMexFnc)( int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] ) { int a, M, N, L, W, s0, s1, br; // Get matrix dimensions. L = mxGetM(prhs[0]); W = mxGetN(prhs[0]); a = (int)mxGetScalar(prhs[2]); M = (int)mxGetScalar(prhs[3]); s0 = (int)mxGetScalar(prhs[4]); s1 = (int)mxGetScalar(prhs[5]); br = (int)mxGetScalar(prhs[6]); N = L/a; mwSize dims[]= { M, N, W}; mwSize ndim=W>1?3:2; plhs[0] = ltfatCreateNdimArray(ndim,dims,LTFAT_MX_CLASSID,mxCOMPLEX); const LTFAT_COMPLEX* f_combined = (const LTFAT_COMPLEX*) mxGetData(prhs[0]); const LTFAT_COMPLEX* g_combined = (const LTFAT_COMPLEX*) mxGetData(prhs[1]); LTFAT_COMPLEX* out_combined = (LTFAT_COMPLEX*) mxGetData(plhs[0]); LTFAT_NAME(dgt_shear)(f_combined,g_combined,L,W,a,M,s0,s1,br,out_combined); }
void LTFAT_NAME(ltfatMexFnc)( int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] ) { int L, W, a, M, N, gl; // Get matrix dimensions. L=(int)mxGetScalar(prhs[2]); a=(int)mxGetScalar(prhs[3]); M=(int)mxGetScalar(prhs[4]); N=L/a; gl = mxGetM(prhs[1]); W = mxGetM(prhs[0])*mxGetN(prhs[0])/(M*N); plhs[0] = ltfatCreateMatrix(L, W,LTFAT_MX_CLASSID, mxCOMPLEX); const LTFAT_REAL _Complex* c_combined = (const LTFAT_REAL _Complex*) mxGetData(prhs[0]); const LTFAT_REAL _Complex* g_combined = (const LTFAT_REAL _Complex*) mxGetData(prhs[1]); LTFAT_REAL _Complex* f_combined = (LTFAT_REAL _Complex*) mxGetData(plhs[0]); //#ifdef LTFAT_COMPLEXTYPE LTFAT_NAME(idgt_fb)((const LTFAT_REAL (*)[2])c_combined, (const LTFAT_REAL (*)[2])g_combined, L,gl,W,a,M, (LTFAT_REAL (*)[2]) f_combined); /* #else NOT CALLING idgt_fb_r: TO DO: Do it better. LTFAT_NAME(idgt_fb_r)((const LTFAT_REAL (*)[2])c_combined, g_combined, L,gl,W,a,M,(LTFAT_REAL (*)[2]) f_combined); #endif */ return; }
void LTFAT_NAME(ltfatMexFnc)( int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] ) { int L, W, a, M, N; mwSize ndim; mwSize dims[3]; // Get matrix dimensions. L = mxGetM(prhs[0]); W = mxGetN(prhs[0]); a=(int)mxGetScalar(prhs[2]); M=(int)mxGetScalar(prhs[3]); N=L/a; dims[0]=M; dims[1]=N; dims[2]=W; ndim=3; if (W==1) { ndim=2; } plhs[0] = ltfatCreateNdimArray(ndim,dims,LTFAT_MX_CLASSID,mxCOMPLEX); const LTFAT_REAL _Complex* f_combined = (const LTFAT_REAL _Complex*) mxGetData(prhs[0]); const LTFAT_REAL _Complex* g_combined = (const LTFAT_REAL _Complex*) mxGetData(prhs[1]); LTFAT_REAL _Complex* out_combined = (LTFAT_REAL _Complex*) mxGetData(plhs[0]); LTFAT_NAME(dgt_long)((const LTFAT_REAL (*)[2])f_combined, (const LTFAT_REAL (*)[2])g_combined, L,W,a,M,(LTFAT_REAL (*)[2])out_combined); return; }
int main( int argc, char *argv[] ) { double *f, *g; ltfat_complex *c; int a, M, L, gl, W, N, bl, nrep, ii; double s0, s1; if (argc<8) { printf("Correct parameters: a, M, L, W, gl, bl, nrep\n"); return(1); } a = atoi(argv[1]); M = atoi(argv[2]); L = atoi(argv[3]); W = atoi(argv[4]); gl = atoi(argv[5]); bl = atoi(argv[6]); nrep = atoi(argv[7]); N=L/a; f = ltfat_malloc(L*W*sizeof(double)); g = ltfat_malloc(L*W*sizeof(double)); c = ltfat_malloc(M*N*W*sizeof(ltfat_complex)); LTFAT_NAME(dgtreal_ola_plan) plan = LTFAT_NAME(dgtreal_ola_init)((const double*)g, gl, W, a, M, bl, FFTW_PATIENT); s0 = ltfat_time(); for (ii=0;ii<nrep;ii++) { LTFAT_NAME(dgtreal_ola_execute)(plan,(const double*)f,L,c); } s1 = ltfat_time(); LTFAT_NAME(dgtreal_ola_done)(plan); printf("%i %i %i %i %i %i %f\n",a,M,L,W,gl,bl,(s1-s0)/nrep); ltfat_free(f); ltfat_free(g); ltfat_free(c); return(0); }
LTFAT_NAME(dgt_shearola_init)(const LTFAT_COMPLEX *g, const int gl, const int W, const int a, const int M, const int s0, const int s1, const int br, const int bl, unsigned flags) { LTFAT_NAME(dgt_shearola_plan) plan; plan.bl = bl; plan.gl = gl; plan.W = W; const int Lext = bl+gl; const int Nblocke = Lext/a; plan.buf = ltfat_malloc(Lext*W*sizeof(LTFAT_COMPLEX)); plan.gext = ltfat_malloc(Lext*sizeof(LTFAT_COMPLEX)); plan.cbuf = ltfat_malloc(M*Nblocke*W*sizeof(LTFAT_COMPLEX)); LTFAT_NAME(fir2long_c)(g, gl, Lext, plan.gext); /* Zero the last part of the buffer, it will always be zero. */ for (int w=0; w<W; w++) { for (int jj=bl; jj<Lext;jj++) { plan.buf[jj+w*Lext][0]=0.0; plan.buf[jj+w*Lext][1]=0.0; } } plan.plan = LTFAT_NAME(dgt_shear_init)((const LTFAT_COMPLEX*)plan.buf, (const LTFAT_COMPLEX*)plan.gext, Lext, W, a, M, s0, s1, br, plan.cbuf, flags); return (plan); }
LTFAT_EXTERN void LTFAT_NAME(circshift)(LTFAT_TYPE *in, LTFAT_TYPE *out, const ptrdiff_t L, const ptrdiff_t shift) { ptrdiff_t shiftMod = shift%L; if(in==out) { if(1) { LTFAT_TYPE *inTmp = (LTFAT_TYPE *)ltfat_malloc(L*sizeof(LTFAT_TYPE)); memcpy(inTmp,in,L*sizeof(LTFAT_TYPE)); LTFAT_NAME(circshift)(inTmp,out,L,shift); ltfat_free(inTmp); } else { int m,count,ii,jj; for(m=0,count=0;count!=L;m++) { LTFAT_TYPE t = in[m]; for(ii=m,jj=m+shiftMod; jj!=m; ii=jj,jj=jj+shiftMod<L?jj+shiftMod:jj+shiftMod-L,count++) { in[ii]=in[jj]; } in[ii]=t; count++; } } return; } if(shiftMod<0) { memcpy(out,in-shiftMod,(L+shiftMod)*sizeof(LTFAT_TYPE)); memcpy(out+(L+shiftMod),in,-shiftMod*sizeof(LTFAT_TYPE)); } else if(shiftMod>0) { memcpy(out+shiftMod,in,(L-shiftMod)*sizeof(LTFAT_TYPE)); memcpy(out,in+L-shiftMod,shiftMod*sizeof(LTFAT_TYPE)); } else { memcpy(out,in,L*sizeof(LTFAT_TYPE)); } }
LTFAT_API int LTFAT_NAME(idgt_fb)(const LTFAT_COMPLEX* cin, const LTFAT_TYPE* g, ltfat_int L, ltfat_int gl, ltfat_int W, ltfat_int a, ltfat_int M, const ltfat_phaseconvention ptype, LTFAT_COMPLEX* f) { LTFAT_NAME(idgt_fb_plan)* plan = NULL; int status = LTFATERR_SUCCESS; CHECKSTATUS( LTFAT_NAME(idgt_fb_init)(g, gl, a, M, ptype, FFTW_ESTIMATE, &plan)); CHECKSTATUS( LTFAT_NAME(idgt_fb_execute)(plan, cin, L, W, f)); error: if (plan) LTFAT_NAME(idgt_fb_done)(&plan); return status; }
void LTFAT_NAME(ltfatMexFnc)( int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] ) { // UGLY, will go away as soon as ltfat backend is unified to a naming convenion // Other option is to use forwarder functions #undef LTFAT_NAME #ifdef LTFAT_SINGLE # define LTFAT_NAME(name) LTFAT_NAME_SINGLE(name) #else # define LTFAT_NAME(name) LTFAT_NAME_DOUBLE(name) #endif int L, R, a, M, N, c, d, p, q,h_a,h_m; // Get matrix dimensions. L = mxGetM(prhs[0]); R = mxGetN(prhs[0]); a=(int)mxGetScalar(prhs[1]); M=(int)mxGetScalar(prhs[2]); N=L/a; c=gcd(a, M,&h_a, &h_m); p=a/c; q=M/c; d=N/q; plhs[0] = ltfatCreateMatrix(p*q*R, c*d,LTFAT_MX_CLASSID,mxCOMPLEX); LTFAT_REAL _Complex* gf_combined = (LTFAT_REAL _Complex*) mxGetData(plhs[0]); #ifdef LTFAT_COMPLEXTYPE const LTFAT_REAL _Complex* g_combined = (const LTFAT_REAL _Complex*) mxGetData(prhs[0]); LTFAT_NAME(wfac)((const LTFAT_REAL (*)[2])g_combined, L, R, a, M, (LTFAT_REAL (*)[2])gf_combined); #else const LTFAT_REAL* g_combined = (const LTFAT_REAL*) mxGetData(prhs[0]); LTFAT_NAME(wfac_r)(g_combined, L, R, a, M, (LTFAT_REAL (*)[2])gf_combined); #endif return; }
/* Calling convention: * cout=comp_col2diag(cin); */ void LTFAT_NAME(ltfatMexFnc)( int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] ) { int L = mxGetM(prhs[0]); plhs[0] = ltfatCreateMatrix(L, L, LTFAT_MX_CLASSID, LTFAT_MX_COMPLEXITY); #ifdef NOCOMPLEXFMTCHANGE LTFAT_REAL* cout_r = (LTFAT_REAL*) mxGetPr(plhs[0]); LTFAT_REAL* cin_r = (LTFAT_REAL*) mxGetPr(prhs[0]); LTFAT_NAME(fwd_col2diag)(cin_r,L,cout_r); #ifdef LTFAT_COMPLEXTYPE // Treat the imaginary part LTFAT_REAL* cin_i= (LTFAT_REAL*) mxGetPi(prhs[0]); LTFAT_REAL* cout_i= (LTFAT_REAL*) mxGetPi(plhs[0]); LTFAT_NAME(fwd_col2diag)(cin_i, L,cout_i); #endif #else LTFAT_TYPE* cin_r= (LTFAT_TYPE*) mxGetData(prhs[0]); LTFAT_TYPE* cout_r= (LTFAT_TYPE*) mxGetData(plhs[0]); LTFAT_NAME(col2diag)(cin_r, L,cout_r); #endif }
void LTFAT_NAME(ltfatMexFnc)( int UNUSED(nlhs), mxArray* plhs[], int UNUSED(nrhs), const mxArray* prhs[] ) { // Get inputs const mxArray* mxs = prhs[0]; const LTFAT_REAL* s = mxGetData(mxs); const LTFAT_REAL* tgrad = mxGetData(prhs[1]); const LTFAT_REAL* fgrad = mxGetData(prhs[2]); const LTFAT_REAL* cfreq = mxGetData(prhs[3]); mwSize a = (mwSize)mxGetScalar(prhs[4]); const int do_real = (int)mxGetScalar(prhs[5]); LTFAT_REAL tol = (LTFAT_REAL) mxGetScalar(prhs[6]); int phasetype = (int)mxGetScalar(prhs[7]); // Get matrix dimensions. mwSize M = ltfatGetN(mxs); mwSize N = mxGetM(mxs); mwSize L = N * a; mwSize W = 1; //phasetype--; if (mxGetNumberOfDimensions(mxs) > 2) W = mxGetDimensions(mxs)[2]; // Create empty output matrix plhs[0] = ltfatCreateNdimArray(mxGetNumberOfDimensions(mxs), mxGetDimensions(mxs), LTFAT_MX_CLASSID, mxREAL); // Get pointer to output LTFAT_REAL* phase = mxGetData(plhs[0]); if (phasetype == 1) LTFAT_NAME(ufilterbankheapint)(s, tgrad, fgrad, cfreq, a, M, L, W, do_real, tol, phase); else LTFAT_NAME(ufilterbankheapint_relgrad)(s, tgrad, fgrad, cfreq, a, M, L, W, do_real, tol, phase); }
/* Calling convention: * cout=comp_col2diag(cin); */ void LTFAT_NAME(ltfatMexFnc)(int UNUSED(nlhs), mxArray *plhs[], int UNUSED(nrhs), const mxArray *prhs[] ) { mwSize L = mxGetM(prhs[0]); plhs[0] = ltfatCreateMatrix(L, L, LTFAT_MX_CLASSID, LTFAT_MX_COMPLEXITY); #if defined(NOCOMPLEXFMTCHANGE) && !(MX_HAS_INTERLEAVED_COMPLEX) LTFAT_REAL* cout_r = mxGetData(plhs[0]); LTFAT_REAL* cin_r = mxGetData(prhs[0]); LTFAT_NAME(fwd_col2diag)(cin_r,L,cout_r); #ifdef LTFAT_COMPLEXTYPE // Treat the imaginary part LTFAT_REAL* cin_i= mxGetImagData(prhs[0]); LTFAT_REAL* cout_i= mxGetImagData(plhs[0]); LTFAT_NAME(fwd_col2diag)(cin_i, L,cout_i); #endif /* LTFAT_COMPLEXTYPE */ #else /* not NOCOMPLEXFMTCHANGE */ LTFAT_TYPE* cin_r= mxGetData(prhs[0]); LTFAT_TYPE* cout_r= mxGetData(plhs[0]); LTFAT_NAME(col2diag)(cin_r, L,cout_r); #endif /* NOCOMPLEXFMTCHANGE */ }
/* %COMP_ATROUSFILTERBANK_TD Uniform filterbank by conv2 % Usage: c=comp_atrousfilterbank_fft(f,g,a,offset); % % Input parameters: % f : Input data - L*W array. % g : Filterbank filters - filtLen*M array. % a : Filter upsampling factor - scalar. % offset: Delay of the filters - scalar or array of length M. % % Output parameters: % c : L*M*W array of coefficients % */ void LTFAT_NAME(ltfatMexFnc)( int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] ) { const mxArray* mxf = prhs[0]; const mxArray* mxg = prhs[1]; double* a = mxGetPr(prhs[2]); double* offset = mxGetPr(prhs[3]); // input data length unsigned int L = mxGetM(mxf); // number of channels unsigned int W = mxGetN(mxf); // filter number unsigned int M = mxGetN(mxg); // filter length unsigned int filtLen = mxGetM(mxg); // POINTER TO THE INPUT LTFAT_TYPE* fPtr = (LTFAT_TYPE*) mxGetPr(prhs[0]); // POINTER TO THE FILTERS LTFAT_TYPE** gPtrs = (LTFAT_TYPE**) mxMalloc(M*sizeof(LTFAT_TYPE*)); for(unsigned int m=0; m<M; m++) { gPtrs[m] = ((LTFAT_TYPE*) mxGetData(mxg)) + m*filtLen; } mwSize ndim = 3; mwSize dims[3]; dims[0] = L; dims[1] = M; dims[2] = W; plhs[0] = ltfatCreateNdimArray(ndim,dims,LTFAT_MX_CLASSID,LTFAT_MX_COMPLEXITY); // over all filters for(unsigned int m =0; m<M; m++) { // over all channels for(unsigned int w =0; w<W; w++) { // Obtain pointer to w-th column in input LTFAT_TYPE *fPtrCol = fPtr + w*L; LTFAT_TYPE *cPtrPlane = ((LTFAT_TYPE*) mxGetData(plhs[0])) + w*L*M; // Obtaing pointer to w-th column in m-th element of output cell-array LTFAT_TYPE *cPtrCol = cPtrPlane + m*L; LTFAT_NAME(atrousconvsub_td)(fPtrCol, L, cPtrCol, L, gPtrs[m], filtLen, (int)*a, -offset[m], ltfatExtStringToEnum("per")); } } }
void LTFAT_NAME(ltfatMexFnc)( int UNUSED(nlhs), mxArray *plhs[], int UNUSED(nrhs), const mxArray *prhs[] ) { const mxArray* mxf = prhs[0]; const mxArray* mxg = prhs[1]; double* aDouble = (double*) mxGetData(prhs[2]); double* offsetDouble = (double*) mxGetData(prhs[3]); ltfatExtType ext = ltfatExtStringToEnum( mxArrayToString(prhs[4]) ); // input data length mwSize L = mxGetM(mxf); // number of channels mwSize W = mxGetN(mxf); // filter number mwSize M = mxGetNumberOfElements(mxg); // POINTER TO THE INPUT LTFAT_TYPE* fPtr = mxGetData(prhs[0]); // POINTER TO THE FILTERS const LTFAT_TYPE* gPtrs[M]; ltfat_int filtLen[M]; ltfat_int a[M]; ltfat_int offset[M]; // POINTER TO OUTPUTS LTFAT_TYPE* cPtrs[M]; // C99 feature plhs[0] = mxCreateCellMatrix(M, 1); for(mwIndex m=0; m<M; ++m) { a[m]= (ltfat_int) aDouble[m]; offset[m] = (ltfat_int) offsetDouble[m]; filtLen[m] = (ltfat_int) mxGetNumberOfElements(mxGetCell(mxg,m)); mwSize outLen = (mwSize) filterbank_td_size(L,a[m],filtLen[m], offset[m],ext); mxSetCell(plhs[0], m, ltfatCreateMatrix(outLen, W,LTFAT_MX_CLASSID, LTFAT_MX_COMPLEXITY)); cPtrs[m] = mxGetData(mxGetCell(plhs[0],m)); gPtrs[m] = mxGetData(mxGetCell(mxg, m)); } LTFAT_NAME(filterbank_td)(fPtr,gPtrs,L,filtLen,W,a,offset,M,cPtrs,ext); }
LTFAT_EXTERN void LTFAT_NAME(atrousfilterbank_td)(const LTFAT_TYPE *f, const LTFAT_TYPE *g[], const ltfatInt L, const ltfatInt gl[], const ltfatInt W, const ltfatInt a[], const ltfatInt skip[], const ltfatInt M, LTFAT_TYPE *c, ltfatExtType ext) { for(ltfatInt m=0; m<M; m++) { for(ltfatInt w=0; w<W; w++) { LTFAT_NAME(atrousconvsub_td)(f+w*L, g[m], L, gl[m], a[m], skip[m],c + w*M*L + m*L, ext); } } }
void LTFAT_NAME(ltfatMexFnc)( int UNUSED(nlhs), mxArray *plhs[], int UNUSED(nrhs), const mxArray *prhs[] ) { mwSignedIndex L, R, a, M; // Get matrix dimensions. L=(mwSignedIndex)mxGetM(prhs[0]); R=(mwSignedIndex)mxGetN(prhs[0]); a=(mwSignedIndex)mxGetScalar(prhs[1]); M=(mwSignedIndex)mxGetScalar(prhs[2]); plhs[0] = ltfatCreateMatrix(L, R,LTFAT_MX_CLASSID,LTFAT_MX_COMPLEXITY); LTFAT_TYPE* gd_combined = mxGetData(plhs[0]); const LTFAT_TYPE* g_combined = mxGetData(prhs[0]); LTFAT_NAME(gabtight_long)(g_combined, L, R, a, M, gd_combined); }