void LTFAT_NAME(fftblMexAtExitFnc)() { if(LTFAT_NAME(oldPlans)!=0) { for(mwIndex m=0; m<LTFAT_NAME(oldM); m++) { if(LTFAT_NAME(oldPlans)[m]!=0) { LTFAT_NAME(upconv_fftbl_done)(LTFAT_NAME(oldPlans)[m]); } } ltfat_free(LTFAT_NAME(oldPlans)); LTFAT_NAME(oldPlans) = 0; } if(LTFAT_NAME(oldLc)!=0) { ltfat_free(LTFAT_NAME(oldLc)); LTFAT_NAME(oldLc) = 0; } LTFAT_NAME(oldM) = 0; LTFAT_NAME(oldW) = 0; #ifdef _DEBUG mexPrintf("Exit fnc called: %s\n",__PRETTY_FUNCTION__); #endif }
LTFAT_EXTERN void LTFAT_NAME(gabdual_long)(const LTFAT_TYPE *g, const int L, const int R, const int a, const int M, LTFAT_TYPE *gd) { #ifdef LTFAT_COMPLEXTYPE const int wfs = L; #else const int wfs = L; /* wfacreal_size(L,a,M); */ #endif LTFAT_COMPLEX *gf = ltfat_malloc(wfs*R*sizeof(LTFAT_COMPLEX)); LTFAT_COMPLEX *gdf = ltfat_malloc(wfs*R*sizeof(LTFAT_COMPLEX)); #ifdef LTFAT_COMPLEXTYPE LTFAT_NAME_REAL(wfac)(g, L, R, a, M, gf); LTFAT_NAME_REAL(gabdual_fac)((const LTFAT_COMPLEX *)gf,L,R,a,M,gdf); LTFAT_NAME_REAL(iwfac)((const LTFAT_COMPLEX *)gdf,L,R,a,M,gd); #else LTFAT_NAME_REAL(wfacreal)(g, L, R, a, M, gf); LTFAT_NAME_REAL(gabdualreal_fac)((const LTFAT_COMPLEX *)gf,L,R,a,M,gdf); LTFAT_NAME_REAL(iwfacreal)((const LTFAT_COMPLEX *)gdf,L,R,a,M,gd); #endif ltfat_free(gdf); ltfat_free(gf); }
int TEST_NAME(test_fftrealcircshift)() { ltfatInt L[] = {111, 1, 100}; ltfatInt shift[] = { -5, 0, 1, -1000, 10540, 5660}; for (unsigned int lId = 0; lId < ARRAYLEN(L); lId++) { LTFAT_COMPLEX* fin = LTFAT_NAME_COMPLEX(malloc)(L[lId]); TEST_NAME_COMPLEX(fillRand)(fin, L[lId]); LTFAT_COMPLEX* fout = LTFAT_NAME_COMPLEX(malloc)(L[lId]); TEST_NAME_COMPLEX(fillRand)(fout, L[lId]); for (unsigned int shiftId = 0; shiftId < ARRAYLEN(shift); shiftId++) { mu_assert( LTFAT_NAME_COMPLEX(fftrealcircshift)(fin, L[lId], shift[shiftId], fout) == 0, "fftrealcirschift"); mu_assert( LTFAT_NAME_COMPLEX(fftrealcircshift)(fin, L[lId], shift[shiftId], fin) == 0, "fftrealcirschift inplace"); } ltfat_free(fin); ltfat_free(fout); } LTFAT_COMPLEX* fin = LTFAT_NAME_COMPLEX(malloc)(L[0]); TEST_NAME_COMPLEX(fillRand)(fin, L[0]); LTFAT_COMPLEX* fout = LTFAT_NAME_COMPLEX(malloc)(L[0]); TEST_NAME_COMPLEX(fillRand)(fout, L[0]); // Inputs can be checked only once mu_assert( LTFAT_NAME_COMPLEX(fftrealcircshift)(NULL, L[0], shift[0], fin) == LTFATERR_NULLPOINTER, "First is null"); mu_assert( LTFAT_NAME_COMPLEX(fftrealcircshift)(fin, L[0], shift[0], NULL) == LTFATERR_NULLPOINTER, "Last is null"); mu_assert( LTFAT_NAME_COMPLEX(fftrealcircshift)(fin, 0, shift[0], fout) == LTFATERR_BADSIZE, "Zero length"); mu_assert( LTFAT_NAME_COMPLEX(fftrealcircshift)(fin, -1, shift[0], fout) == LTFATERR_BADSIZE, "Negative length"); mu_assert( LTFAT_NAME_COMPLEX(fftrealcircshift)(NULL, -1, shift[0], fout) < LTFATERR_SUCCESS, "Multiple wrong inputs"); ltfat_free(fin); ltfat_free(fout); return 0; }
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); }
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_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)); } }
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); }
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_API void* ltfat_realloc (void* ptr, size_t nold, size_t nnew) { void* outp = ltfat_malloc(nnew); if (!outp) return NULL; if (ptr) { memcpy(outp, ptr, nold < nnew ? nold : nnew); ltfat_free(ptr); } return outp; }
LTFAT_EXTERN void fbreassOptOut_destroy(fbreassOptOut* oo) { for (ltfatInt ii = 0; ii < oo->l; ii++) { if (oo->repos[ii] && oo->reposlmax[ii] > 0) { ltfat_free(oo->repos[ii]); } } LTFAT_SAFEFREEALL(oo->repos, oo->reposl, oo->reposlmax, oo); oo = NULL; }
int main() { all_tests(); if (ft.noOfFailedTests > 0) { printf("\n----------------\nFAILED TESTS %d: \n\n", ft.noOfFailedTests); for (int ii = 0; ii < ft.noOfFailedTests; ii++) { printf(" %s\n", ft.failedTests[ii]); } ltfat_free(ft.failedTests); } else { printf("\n----------------\nALL TESTS PASSED\n"); } }
LTFAT_EXTERN void LTFAT_NAME(pfilt_fir_rr)(const LTFAT_REAL *f, const LTFAT_REAL *g, const ltfatInt L, const ltfatInt gl, const ltfatInt W, const ltfatInt a, LTFAT_REAL *cout) { /* --------- initial declarations -------------- */ ltfatInt l, n, w; LTFAT_REAL *gw; LTFAT_REAL *gb; LTFAT_REAL fw; const LTFAT_REAL *fbd; /* ----------- calculation of parameters and plans -------- */ const ltfatInt N=L/a; /* These are floor operations. */ const ltfatInt glh=gl/2; /* This is a ceil operation. */ const ltfatInt glh_d_a=(ltfatInt)ceil((glh*1.0)/(a)); gw = (LTFAT_REAL*)ltfat_malloc(gl*sizeof(LTFAT_REAL)); /* ---------- main body ----------- */ /* Do the fftshift of g to place the center in the middle and * conjugate it. */ for (l=0; l<glh; l++) { gw[l]=g[l+(gl-glh)]; } for (l=glh; l<gl; l++) { gw[l]=g[l-glh]; } for (w=0; w<W; w++) { /*----- Handle the first boundary using periodic boundary conditions.*/ for (n=0; n<glh_d_a; n++) { gb=gw; fbd=f+L-(glh-n*a)+L*w; fw=0.0; for (l=0; l<glh-n*a; l++) { fw +=fbd[l]*gb[l]; } fbd=f-(glh-n*a)+L*w; for (l=glh-n*a; l<gl; l++) { fw +=fbd[l]*gb[l]; } cout[n+w*N]=fw; } /* ----- Handle the middle case. --------------------- */ for (n=glh_d_a; n<(L-(gl+1)/2)/a+1; n++) { gb=gw; fbd=f+(n*a-glh+L*w); fw=0; for (l=0; l<gl; l++) { fw +=fbd[l]*gb[l]; } cout[n+w*N]=fw; } /* Handle the last boundary using periodic boundary conditions. */ for (n=(L-(gl+1)/2)/a+1; n<N; n++) { gb=gw; fbd=f+(n*a-glh+L*w); fw=0; for (l=0; l<L-n*a+glh; l++) { fw +=fbd[l]*gb[l]; } fbd=f-(L-n*a+glh)+L*w; for (l=L-n*a+glh; l<gl; l++) { fw +=fbd[l]*gb[l]; } cout[n+w*N]=fw; } } /* ----------- Clean up ----------------- */ ltfat_free(gw); }
LTFAT_EXTERN void LTFAT_NAME(idgt_fb)(const LTFAT_COMPLEX *cin, const LTFAT_COMPLEX *g, const int L, const int gl, const int W, const int a, const int M, LTFAT_COMPLEX *f) { /* --------- initial declarations -------------- */ const int N=L/a; int ep, sp; /* This is a floor operation. */ const int glh=gl/2; /* This is a ceil operation. */ const int glh_d_a=(int)ceil((glh*1.0)/(a)); LTFAT_COMPLEX *fw; LTFAT_COMPLEX *cbuf = (LTFAT_COMPLEX*)ltfat_malloc(M*sizeof(LTFAT_COMPLEX)); /* Create plan. In-place. */ LTFAT_FFTW(plan) p_small = LTFAT_FFTW(plan_dft_1d)(M, cbuf, cbuf, FFTW_BACKWARD, FFTW_MEASURE); /* % The fftshift actually makes some things easier. */ LTFAT_COMPLEX *gw = (LTFAT_COMPLEX*)ltfat_malloc(gl*sizeof(LTFAT_COMPLEX)); for (int l=0;l<glh;l++) { gw[l][0] = g[l+(gl-glh)][0]; gw[l][1] = g[l+(gl-glh)][1]; } for (int l=glh;l<gl;l++) { gw[l][0] = g[l-glh][0]; gw[l][1] = g[l-glh][1]; } LTFAT_COMPLEX *ff = (LTFAT_COMPLEX*)ltfat_malloc(gl*sizeof(LTFAT_COMPLEX)); for (int w=0; w<W; w++) { fw=f+w*L; for (int l=0;l<L;l++) { fw[l][0]=0.0; fw[l][1]=0.0; } /* ----- Handle the first boundary using periodic boundary conditions. --- */ for (int n=0; n<glh_d_a; n++) { THE_SUM; sp=positiverem(n*a-glh,L); ep=positiverem(n*a-glh+gl-1,L); /* % Add the ff vector to f at position sp. */ for (int ii=0;ii<L-sp;ii++) { fw[sp+ii][0]+=ff[ii][0]; fw[sp+ii][1]+=ff[ii][1]; } for (int ii=0; ii<ep+1;ii++) { fw[ii][0] +=ff[L-sp+ii][0]; fw[ii][1] +=ff[L-sp+ii][1]; } } /* ----- Handle the middle case. --------------------- */ for (int n=glh_d_a; n<(L-(gl+1)/2)/a+1; n++) { THE_SUM; sp=positiverem(n*a-glh,L); ep=positiverem(n*a-glh+gl-1,L); /* Add the ff vector to f at position sp. */ for (int ii=0;ii<ep-sp+1;ii++) { fw[ii+sp][0] += ff[ii][0]; fw[ii+sp][1] += ff[ii][1]; } } /* Handle the last boundary using periodic boundary conditions. */ for (int n=(L-(gl+1)/2)/a+1; n<N; n++) { THE_SUM; sp=positiverem(n*a-glh,L); ep=positiverem(n*a-glh+gl-1,L); /* Add the ff vector to f at position sp. */ for (int ii=0;ii<L-sp;ii++) { fw[sp+ii][0]+=ff[ii][0]; fw[sp+ii][1]+=ff[ii][1]; } for (int ii=0; ii<ep+1;ii++) { fw[ii][0] +=ff[L-sp+ii][0]; fw[ii][1] +=ff[L-sp+ii][1]; } } } ltfat_free(cbuf); ltfat_free(ff); ltfat_free(gw); LTFAT_FFTW(destroy_plan)(p_small); }
LTFAT_API void ltfat_safefree(const void* ptr) { if (ptr) ltfat_free((void*)ptr); }
/* wfac for real valued input. Produces only half the output coefficients of wfac_r */ LTFAT_EXTERN void LTFAT_NAME(wfacreal)(const LTFAT_REAL *g, const int L, const int R, const int a, const int M, LTFAT_COMPLEX *gf) { int h_a, h_m; LTFAT_REAL *gfp; int s; int rem, negrem; LTFAT_FFTW(plan) p_before; const int b=L/M; const int c=gcd(a, M,&h_a, &h_m); const int p=a/c; const int q=M/c; const int d=b/p; /* This is a floor operation. */ const int d2= d/2+1; const double sqrtM=sqrt(M); LTFAT_REAL *sbuf = (LTFAT_REAL*)ltfat_malloc(d*sizeof(LTFAT_REAL)); LTFAT_COMPLEX *cbuf = (LTFAT_COMPLEX*)ltfat_malloc(d2*sizeof(LTFAT_COMPLEX)); /* Create plan. In-place. */ p_before = LTFAT_FFTW(plan_dft_r2c_1d)(d, sbuf, cbuf, FFTW_MEASURE); const int ld3=2*c*p*q*R; gfp=(LTFAT_REAL*)gf; for (int r=0;r<c;r++) { for (int w=0;w<R;w++) { for (int l=0;l<q;l++) { for (int k=0;k<p;k++) { negrem = positiverem(k*M-l*a,L); for (s=0;s<d;s++) { rem = (negrem+s*p*M)%L; sbuf[s] = sqrtM*g[r+rem+L*w]; } LTFAT_FFTW(execute)(p_before); for (s=0;s<d2;s++) { gfp[s*ld3] = cbuf[s][0]; gfp[s*ld3+1]= cbuf[s][1]; } gfp+=2; } } } } ltfat_free(sbuf); }
/* wfac for real valued input. */ LTFAT_EXTERN void LTFAT_NAME(wfac_r)(const LTFAT_REAL *g, const int L, const int R, const int a, const int M, LTFAT_COMPLEX *gf) { int h_a, h_m; LTFAT_REAL *sbuf, *gfp; int s; int rem, negrem; LTFAT_FFTW(plan) p_before; const int b=L/M; const int c=gcd(a, M,&h_a, &h_m); const int p=a/c; const int q=M/c; const int d=b/p; const double sqrtM=sqrt(M); sbuf = (LTFAT_REAL*)ltfat_malloc(2*d*sizeof(LTFAT_REAL)); /* Create plan. In-place. */ p_before = LTFAT_FFTW(plan_dft_1d)(d, (LTFAT_COMPLEX*)sbuf, (LTFAT_COMPLEX*)sbuf, FFTW_FORWARD, FFTW_MEASURE); const int ld3=c*p*q*R; gfp=(LTFAT_REAL*)gf; for (int r=0;r<c;r++) { for (int w=0;w<R;w++) { for (int l=0;l<q;l++) { for (int k=0;k<p;k++) { negrem = positiverem(k*M-l*a,L); for (s=0;s<d;s++) { rem = (negrem+s*p*M)%L; sbuf[2*s] = sqrtM*g[r+rem+L*w]; sbuf[2*s+1] = 0.0; } LTFAT_FFTW(execute)(p_before); for (s=0;s<2*d;s+=2) { gfp[s*ld3] = sbuf[s]; gfp[s*ld3+1]= sbuf[s+1]; } gfp+=2; } } } } ltfat_free(sbuf); }
int TEST_NAME(test_pgauss)() { ltfatInt L[] = { 111, 1, 100 }; double w[] = { 0.001, 0.1, 0.2 }; double c_t[] = { 0.0, 0.1, -0.2 }; double c_f[] = { 0.0, 0.1, -0.2 }; for (unsigned int lId = 0; lId < ARRAYLEN(L); lId++) { LTFAT_TYPE* fin = LTFAT_NAME(malloc)(L[lId]); TEST_NAME(fillRand)(fin, L[lId]); LTFAT_COMPLEX* fincmplx = LTFAT_NAME_COMPLEX(malloc)(L[0]); TEST_NAME_COMPLEX(fillRand)(fincmplx, L[0]); for (unsigned int wId = 0; wId < ARRAYLEN(w); wId++) { for (unsigned int ctId = 0; ctId < ARRAYLEN(c_t); ctId++) { mu_assert( LTFAT_NAME(pgauss)( L[lId], w[wId], c_t[ctId], fin) == LTFATERR_SUCCESS, "pgauss"); for (unsigned int cfId = 0; cfId < ARRAYLEN(c_f); cfId++) { mu_assert( LTFAT_NAME(pgauss_cmplx)( L[lId], w[wId], c_t[ctId], c_f[cfId], fincmplx) == LTFATERR_SUCCESS, "pgauss"); } } } ltfat_free(fin); ltfat_free(fincmplx); } LTFAT_TYPE* fin = LTFAT_NAME(malloc)(L[0]); TEST_NAME(fillRand)(fin, L[0]); LTFAT_COMPLEX* fincmplx = LTFAT_NAME_COMPLEX(malloc)(L[0]); TEST_NAME_COMPLEX(fillRand)(fincmplx, L[0]); mu_assert( LTFAT_NAME(pgauss)( L[0], w[0], c_t[0], NULL) == LTFATERR_NULLPOINTER, "pgauss Array is null"); mu_assert( LTFAT_NAME(pgauss)( 0, w[0], c_t[0], fin) == LTFATERR_BADSIZE, "pgauss L is wrong"); mu_assert( LTFAT_NAME(pgauss)( L[0], 0.0, c_t[0], fin) == LTFATERR_NOTPOSARG, "pgauss Wrong t-f ratio"); mu_assert( LTFAT_NAME(pgauss_cmplx)( L[0], w[0], c_t[0], c_f[0], NULL) == LTFATERR_NULLPOINTER, "pgauss cmplx Array is null"); mu_assert( LTFAT_NAME(pgauss_cmplx)( 0, w[0], c_t[0], c_f[0], fincmplx) == LTFATERR_BADSIZE, "pgauss cmplx L is wrong"); mu_assert( LTFAT_NAME(pgauss_cmplx)( L[0], 0.0, c_t[0], c_f[0], fincmplx) == LTFATERR_NOTPOSARG, "pgauss cmplx Wrong t-f ratio"); ltfat_free(fin); ltfat_free(fincmplx); return 0; }
void dgt_fac(ltfat_complex *f, ltfat_complex *gf, const int L, const int W, const int R, const int a, const int M, ltfat_complex *cout, int dotime) { /* --------- initial declarations -------------- */ int b, N, c, d, p, q, h_a, h_m; double *gbase, *fbase, *cbase; int l, k, r, s, u, w, rw, nm, mm, km; int ld2a, ld1b, ld3b; int ld4c, ld5c; int rem; fftw_plan p_before, p_after, p_veryend; double *ff, *cf, *ffp, *sbuf, *fp, *cfp; double scalconst; double st0, st1, st6, st7; /* ----------- calculation of parameters and plans -------- */ if (dotime) { st0=ltfat_time(); } b=L/M; N=L/a; c=gcd(a, M,&h_a, &h_m); p=a/c; q=M/c; d=b/p; h_a=-h_a; /* Scaling constant needed because of FFTWs normalization. */ scalconst=1.0/((double)d*sqrt((double)M)); ff = (double*)ltfat_malloc(2*d*p*q*W*sizeof(double)); cf = (double*)ltfat_malloc(2*d*q*q*W*R*sizeof(double)); sbuf = (double*)ltfat_malloc(2*d*sizeof(double)); /* Create plans. In-place. */ p_before = fftw_plan_dft_1d(d, (ltfat_complex*)sbuf, (ltfat_complex*)sbuf, FFTW_FORWARD, FFTW_MEASURE); p_after = fftw_plan_dft_1d(d, (ltfat_complex*)sbuf, (ltfat_complex*)sbuf, FFTW_BACKWARD, FFTW_MEASURE); /* Create plan. In-place. */ p_veryend = fftw_plan_many_dft(1, &M, N*R*W, cout, NULL, 1, M, cout, NULL, 1, M, FFTW_FORWARD, FFTW_OPTITYPE); if (dotime) { st1=ltfat_time(); printf("DGT_FAC_7: Planning phase %f\n",st1-st0); } /* Leading dimensions of the 4dim array. */ ld2a=2*p*q*W; /* Leading dimensions of cf */ ld1b=q*R; ld3b=2*q*R*q*W; /* --------- main loop begins here ------------------- */ for (r=0;r<c;r++) { /* ---------- compute signal factorization ----------- */ ffp=ff; fp=(double*)f+2*r; if (p==1) /* Integer oversampling case */ { for (w=0;w<W;w++) { for (l=0;l<q;l++) { for (s=0;s<d;s++) { rem = 2*((s*M+l*a)%L); sbuf[2*s] = fp[rem]; sbuf[2*s+1] = fp[rem+1]; } fftw_execute(p_before); for (s=0;s<d;s++) { ffp[s*ld2a] = sbuf[2*s]*scalconst; ffp[s*ld2a+1] = sbuf[2*s+1]*scalconst; } ffp+=2; } fp+=2*L; } fp-=2*L*W; } else { /* rational sampling case */ for (w=0;w<W;w++) { for (l=0;l<q;l++) { for (k=0;k<p;k++) { for (s=0;s<d;s++) { rem = 2*positiverem(k*M+s*p*M-l*h_a*a, L); sbuf[2*s] = fp[rem]; sbuf[2*s+1] = fp[rem+1]; } fftw_execute(p_before); for (s=0;s<d;s++) { ffp[s*ld2a] = sbuf[2*s]*scalconst; ffp[s*ld2a+1] = sbuf[2*s+1]*scalconst; } ffp+=2; } } fp+=2*L; } fp-=2*L*W; } /* ----------- compute matrix multiplication ----------- */ /* Do the matmul */ if (p==1) { /* Integer oversampling case */ /* Rational oversampling case */ for (s=0;s<d;s++) { gbase=(double*)gf+2*(r+s*c)*q*R; fbase=ff+2*s*q*W; cbase=cf+2*s*q*q*W*R; for (nm=0;nm<q*W;nm++) { for (mm=0;mm<q*R;mm++) { cbase[0]=gbase[0]*fbase[0]+gbase[1]*fbase[1]; cbase[1]=gbase[0]*fbase[1]-gbase[1]*fbase[0]; gbase+=2; cbase+=2; } gbase-=2*q*R; fbase+=2; } cbase-=2*q*R*q*W; } } else { /* Rational oversampling case */ for (s=0;s<d;s++) { gbase=(double*)gf+2*(r+s*c)*p*q*R; fbase=ff+2*s*p*q*W; cbase=cf+2*s*q*q*W*R; for (nm=0;nm<q*W;nm++) { for (mm=0;mm<q*R;mm++) { cbase[0]=0.0; cbase[1]=0.0; for (km=0;km<p;km++) { cbase[0]+=gbase[0]*fbase[0]+gbase[1]*fbase[1]; cbase[1]+=gbase[0]*fbase[1]-gbase[1]*fbase[0]; gbase+=2; fbase+=2; } fbase-=2*p; cbase+=2; } gbase-=2*q*R*p; fbase+=2*p; } cbase-=2*q*R*q*W; fbase-=2*p*q*W; } } /* ------- compute inverse coefficient factorization ------- */ cfp=cf; ld4c=M*N; ld5c=M*N*R; /* Cover both integer and rational sampling case */ for (w=0;w<W;w++) { /* Complete inverse fac of coefficients */ for (l=0;l<q;l++) { for (rw=0;rw<R;rw++) { for (u=0;u<q;u++) { for (s=0;s<d;s++) { sbuf[2*s] = cfp[s*ld3b]; sbuf[2*s+1] = cfp[s*ld3b+1]; } cfp+=2; /* Do inverse fft of length d */ fftw_execute(p_after); for (s=0;s<d;s++) { rem= r+l*c+positiverem(u+s*q-l*h_a,N)*M+rw*ld4c+w*ld5c; cout[rem][0]=sbuf[2*s]; cout[rem][1]=sbuf[2*s+1]; } } } } } /* ----------- Main loop ends here ------------------------ */ } if (dotime) { st6=ltfat_time(); printf("DGT_FAC_7: Main loop done %f\n",st6-st1); } /* FFT to modulate the coefficients. */ fftw_execute(p_veryend); if (dotime) { st7=ltfat_time(); printf("DGT_FAC_7: Final FFT %f\n",st7-st6); printf("DGT_FAC_7: Total time %f\n",st7-st0); } /* ----------- Clean up ----------------- */ fftw_destroy_plan(p_before); fftw_destroy_plan(p_after); fftw_destroy_plan(p_veryend); ltfat_free(sbuf); ltfat_free(ff); ltfat_free(cf); }