int main() { int i; /* define some data space */ vsip_cvview_d* dataComplex; vsip_cvview_d* dataComplexQuotient; vsip_init((void *)0); dataComplex = vsip_cvcreate_d(L, VSIP_MEM_NONE); dataComplexQuotient = vsip_cvcreate_d(L, VSIP_MEM_NONE); /* put some complex data in dataComplex */ for(i = 0; i < L; i++) vsip_cvput_d(dataComplex,i, vsip_cmplx_d((double)(i * i),(double)(i+1))); /*divide dataComplex by some denom and print the input and output */ vsip_cvrsdiv_d(dataComplex,denom,dataComplexQuotient); for(i=0; i<L; i++) printf("(%7.4f + %7.4fi) / %7.4f) = (%7.4f + %7.4fi)\n", vsip_real_d(vsip_cvget_d(dataComplex,i)), vsip_imag_d(vsip_cvget_d(dataComplex,i)), denom, vsip_real_d(vsip_cvget_d(dataComplexQuotient,i)), vsip_imag_d(vsip_cvget_d(dataComplexQuotient,i))); vsip_cblockdestroy_d(vsip_cvdestroy_d(dataComplex)); vsip_cblockdestroy_d(vsip_cvdestroy_d(dataComplexQuotient)); vsip_finalize((void *)0); return 0; }
int main(int argc, char *argv[]){vsip_init((void*)0); { if(argc < 4){ printf("usage\nfirEx length decimation filterFile <indataFile >outputFile\n"); exit(0); } { vsip_length N = (vsip_length)atoi(argv[1]); int D = atoi(argv[2]); vsip_scalar_vi n = 0,k = 0; vsip_scalar_d hvr,hvi; FILE *fh; vsip_cfir_d *fir; vsip_cvview_d *x = vsip_cvcreate_d(N,0), *h,*y; fh = fopen(argv[3],"r"); while(fscanf(fh,"%lf %lf",&hvr, &hvi) == 2) n++; rewind(fh); y = vsip_cvcreate_d(N/D + ((N % D) ? 1:0),0); h = vsip_cvcreate_d(n,0); n=0; while(fscanf(fh,"%lf %lf",&hvr,&hvi) == 2){ vsip_cvput_d(h,n,vsip_cmplx_d(hvr,hvi)); n++; } fclose(fh); /* fir = vsip_cfir_create_d(h,VSIP_SYM_EVEN_LEN_ODD,N,D,STATE,0,0); */ /* fir = vsip_cfir_create_d(h,VSIP_SYM_EVEN_LEN_EVEN,N,D,STATE,0,0); */ fir = vsip_cfir_create_d(h,VSIP_NONSYM,N,D,STATE,0,0); n = VU_cscanstdin_d(x); while(n == N){ k = vsip_cfirflt_d(fir,x,y); VU_cprintstdout_d(y,0,k); n = VU_cscanstdin_d(x); } if(n != 0){ k = vsip_cfirflt_d(fir,x,y); VU_cprintstdout_d(y,0,k); } {/* test getattr */ vsip_cfir_attr attr; vsip_cfir_getattr_d(fir,&attr); printf("kernel %lu\n input %lu\n output %lu\ndecimation %d\n", attr.kernel_len,attr.in_len,attr.out_len, attr.decimation); } vsip_cvalldestroy_d(y); vsip_cvalldestroy_d(x); vsip_cvalldestroy_d(h); vsip_cfir_destroy_d(fir); }vsip_finalize((void*)0);return 1; } }
int main() { int i; vsip_cvview_d* dataEuler; vsip_vview_d* data; vsip_init((void *)0); dataEuler = vsip_cvcreate_d(L, VSIP_MEM_NONE); data = vsip_vcreate_d(L, VSIP_MEM_NONE); /* Make up some data */ /* Compute a ramp from zero to 2pi */ vsip_vramp_d(0.0, (2.0 * PI / (double) (L - 1)), data); /* Compute Euler */ vsip_veuler_d(data,dataEuler); /* Now print out data and dataEuler */ for(i=0; i < L; i++) { printf(" %7.4f => (%7.4f, %7.4f)\n",vsip_vget_d(data,i), vsip_real_d(vsip_cvget_d(dataEuler,i)), vsip_imag_d(vsip_cvget_d(dataEuler,i))); } /* Destroy the vector views and any associated blocks */ vsip_blockdestroy_d(vsip_vdestroy_d(data)); vsip_cblockdestroy_d(vsip_cvdestroy_d(dataEuler)); vsip_finalize((void *)0); return 0; }
int main(){vsip_init((void*)0); { void VU_vfprintyg_d(char*,vsip_vview_d*,char*); void VU_vfreqswapIP_d(vsip_vview_d*); vsip_vview_d* Cw = vsip_vcreate_cheby_d(Nlength,ripple,0); vsip_fft_d *fft = vsip_ccfftip_create_d(Nlength,1.0,VSIP_FFT_FWD,0,0); vsip_cvview_d* FCW = vsip_cvcreate_d(Nlength,0); /*printf("CW = "); VU_vprintm_d("%6.8f ;\n",Cw); */ VU_vfprintyg_d("%6.8f\n",Cw,"Cheby_Window"); vsip_cvfill_d(vsip_cmplx_d(0,0),FCW); { vsip_vview_d *rv = vsip_vrealview_d(FCW); vsip_vcopy_d_d(Cw,rv); vsip_ccfftip_d(fft,FCW); vsip_vcmagsq_d(FCW,rv); { vsip_index ind; vsip_scalar_d max = vsip_vmaxval_d(rv,&ind); vsip_scalar_d min = max/(10e12); vsip_vclip_d(rv,min,max,min,max,rv); } vsip_vlog10_d(rv,rv); vsip_svmul_d(10,rv,rv); VU_vfreqswapIP_d(rv); VU_vfprintyg_d("%6.8f\n",rv,"Cheby_Window_Frequency_Response"); vsip_vdestroy_d(rv); } vsip_fft_destroy_d(fft); vsip_valldestroy_d(Cw); vsip_cvalldestroy_d(FCW); } vsip_finalize((void*)0); return 0; }
int main(){vsip_init((void*)0); { /* vsip_cmview_d *B = vsip_cmcreate_d(P,N,VSIP_ROW,0);*/ vsip_scalar_d Re[20], Im[20]; vsip_cblock_d *Bblock = vsip_cblockbind_d(Re,Im,20,0); vsip_cmview_d *B = vsip_cmbind_d(Bblock,0,4,5,1,4); vsip_cvview_d *a = vsip_cvcreate_d(P,0), *r = vsip_cvcreate_d(N,0); int i, j; for(i=0;i<P;i++) vsip_cvput_d(a,i,vsip_cmplx_d(i,1 + sqrt(i))); for(i=0;i<P;i++) for(j=0;j<N;j++) vsip_cmput_d(B,i,j,vsip_cmplx_d(1 , i * j)); vsip_cvmprod_d(a,B,r); printf("\n vector input \n v=["); for(i=0;i<P;i++) printf("(%5.2f %+5.2fi) ", vsip_real_d(vsip_cvget_d(a,i)), vsip_imag_d(vsip_cvget_d(a,i))); printf("]\n"); printf("\n B input \n B =[\n"); {for(i=0;i<P;i++) {for(j=0;j<N;j++){ printf(" (%5.2f %+5.2fi) ", vsip_real_d(vsip_cmget_d(B,i,j)), vsip_imag_d(vsip_cmget_d(B,i,j))); } printf(";\n"); } printf("]\n"); } printf("\n vector output \n"); for(i=0;i<N;i++) printf("(%5.2f, %5.2f) ", vsip_real_d(vsip_cvget_d(r,i)), vsip_imag_d(vsip_cvget_d(r,i))); printf("\n"); vsip_cvalldestroy_d(a); vsip_cmalldestroy_d(B); vsip_cvalldestroy_d(r); }vsip_finalize((void*)0);return 0; }
int main() { int i; /* define some vectors */ vsip_vview_d* dataReOne; vsip_vview_d* dataReTwo; vsip_vview_d* dataReQuotient; vsip_cvview_d* dataComplex; vsip_cvview_d* dataComplexQuotient; vsip_init((void *)0); dataReOne = vsip_vcreate_d(L, VSIP_MEM_NONE); dataReTwo = vsip_vcreate_d(L, VSIP_MEM_NONE); dataReQuotient = vsip_vcreate_d(L, VSIP_MEM_NONE); dataComplex = vsip_cvcreate_d(L, VSIP_MEM_NONE); dataComplexQuotient = vsip_cvcreate_d(L, VSIP_MEM_NONE); /* make up some data */ vsip_vramp_d(1,1,dataReOne); vsip_vfill_d(2,dataReTwo); vsip_vcmplx_d(dataReTwo,dataReOne,dataComplex); /*divide one by two and print the input and output */ vsip_vdiv_d(dataReOne,dataReTwo,dataReQuotient); for(i=0; i<L; i++) printf("%7.4f / %7.4f = %7.4f\n", vsip_vget_d(dataReOne,i), vsip_vget_d(dataReTwo,i), vsip_vget_d(dataReQuotient,i)); printf("\n"); /*divide one by complex and print the input and output */ vsip_rcvdiv_d(dataReOne,dataComplex,dataComplexQuotient); for(i=0; i<L; i++) printf("%7.4f / (%7.4f + %7.4fi) = (%7.4f + %7.4fi)\n", vsip_vget_d(dataReOne,i), vsip_real_d(vsip_cvget_d(dataComplex,i)), vsip_imag_d(vsip_cvget_d(dataComplex,i)), vsip_real_d(vsip_cvget_d(dataComplexQuotient,i)), vsip_imag_d(vsip_cvget_d(dataComplexQuotient,i))); /* destroy created objects */ vsip_blockdestroy_d(vsip_vdestroy_d(dataReOne)); vsip_blockdestroy_d(vsip_vdestroy_d(dataReTwo)); vsip_blockdestroy_d(vsip_vdestroy_d(dataReQuotient)); vsip_cblockdestroy_d(vsip_cvdestroy_d(dataComplex)); vsip_cblockdestroy_d(vsip_cvdestroy_d(dataComplexQuotient)); vsip_finalize((void *)0); return 0; }
int main() { int i; vsip_randstate *state; vsip_cmview_d *xy; vsip_cvview_d *xy_row; vsip_length stride; vsip_cvview_d *sum; vsip_fftm_d *ccfftmip; vsip_length seed =0, num_procs=1, id=1; vsip_init((void *)0); /* Initialize Random Number Generator */ state = vsip_randcreate(seed, num_procs, id, VSIP_PRNG); /* Row major, 64 (ROWS) of 16 point data vectors */ xy = vsip_cmcreate_d(ROWS, 16, VSIP_ROW, VSIP_MEM_NONE); /* Bind xy_row view initially to row 0 of xy */ xy_row = vsip_cmrowview_d(xy, 0); /* Stride between column elements of xy */ stride = vsip_cmgetcolstride_d(xy); sum = vsip_cvcreate_d(N, VSIP_MEM_NONE); /* Create an in-place Cmplx->Cmplx Multiple N-pt FFT */ ccfftmip = vsip_ccfftmip_create_d(ROWS, N, 1.0, VSIP_FFT_FWD, VSIP_ROW, 1, VSIP_ALG_TIME); /* Initialize xy by rows with complex Gaussian noise N(0,1) */ for (i=0; i<ROWS; i++) { vsip_cvputoffset_d(xy_row, i*stride); /* view of row i of xy */ vsip_cvrand_d(state,xy_row); /* Initialize row i of xy */ } /* Compute an in-place Cmplx->Cmplx Multiple N-pt FFT using the ccfftmip object*/ vsip_ccfftmip_d(ccfftmip, xy); /* Coherently sum the rows together (in the Freq domain) */ vsip_cvputoffset_d(xy_row, 0); vsip_cvcopy_d_d(xy_row, sum); /* sum = row 0 of xy */ for (i=1; i<ROWS; i++) { vsip_cvputoffset_d(xy_row, i*stride); /* view of row i of xy */ vsip_cvadd_d(xy_row, sum, sum); /* sum += row i of xy */ } /* Print it */ printf("\nComplex Output Vector (Real, Imag)\n"); for(i=0; i<N; i++) printf("%d:\t" SCMPLX "\n", i, ACMPLX(vsip_cvget_d(sum,i))); printf("\n"); /* Destroy all the objects */ vsip_fftm_destroy_d(ccfftmip); vsip_cvdestroy(xy_row); vsip_cvdestroy(sum); vsip_cmalldestroy_d(xy); vsip_randdestroy(state); vsip_finalize((void *)0); return(0); }
vsip_corr1d_d *vsip_corr1d_create_d( vsip_length M, vsip_length N, vsip_support_region support, unsigned int ntimes, vsip_alg_hint hint) { vsip_corr1d_d *cor = (vsip_corr1d_d*) malloc(sizeof(vsip_corr1d_d)); if(cor == NULL) return (vsip_corr1d_d*) NULL; cor->support = support; cor->hint = hint; cor->ntimes = ntimes; cor->m = M; cor->n = N; cor->mn = M + N - 1; if(support == VSIP_SUPPORT_MIN){ cor->lag_len = N-M+1; } else if( support == VSIP_SUPPORT_SAME){ cor->lag_len = N; } else { cor->lag_len = N + M -1; } { vsip_length p = cor->mn; cor->N = 2; while(cor->N <= p){ cor->N *=2; } } cor->x = vsip_cvcreate_d(cor->N,VSIP_MEM_NONE); cor->h = vsip_cvcreate_d(cor->N,VSIP_MEM_NONE); cor->fft = vsip_ccfftip_create_d(cor->N,1,VSIP_FFT_FWD,0,VSIP_ALG_NOISE); if((cor->x == NULL) || (cor->h == NULL) || (cor->fft == NULL)){ vsip_corr1d_destroy_d(cor); return (vsip_corr1d_d*)NULL; } return cor; }
int main (){vsip_init((void*)0); { int i; vsip_cvview_d* vector = vsip_cvcreate_d(L,0); vsip_vview_d* realIn = vsip_vrealview_d(vector); vsip_vview_d* imagIn = vsip_vimagview_d(vector); vsip_fft_d* fftplan = vsip_ccfftip_create_d(L,1,-1,0,0); vsip_fft_d* fftplanI = vsip_ccfftip_create_d(L,(double)1/L,1,0,0); char printDataOne[L][20], printDataTwo[L][30]; /* put some data in realIn*/ vsip_vramp_d(0, 2 * VU_PI * F, realIn); vsip_vcos_d(realIn,realIn); /* print realIn */ for(i=0; i<L; i++){ sprintf(printDataOne[i],"%2d input -> %7.4f",i, vsip_vget_d(realIn,i)); } /*make sure imagIn is full of zeros*/ vsip_vfill_d(0,imagIn); /*find the fft*/ vsip_ccfftip_d(fftplan,vector); for(i=0; i<L; i++){ sprintf(printDataTwo[i]," fft -> (%7.3f, %7.3f)", vsip_real_d(vsip_cvget_d(vector,i)), vsip_imag_d(vsip_cvget_d(vector,i))); } /*invert the fft*/ vsip_ccfftip_d(fftplanI,vector); /*print it */ for(i=0; i<L; i++){ printf("%s %s ifft -> (%7.3f, %7.3f)\n", printDataOne[i], printDataTwo[i], vsip_real_d(vsip_cvget_d(vector,i)), vsip_imag_d(vsip_cvget_d(vector,i))); } { vsip_vdestroy_d((void*)imagIn); vsip_vdestroy_d((void*)realIn); vsip_cblockdestroy_d(vsip_cvdestroy_d((void*)vector)); vsip_fft_destroy_d((void*)fftplan); vsip_fft_destroy_d((void*)fftplanI); } } vsip_finalize((void*)0);return 0; }
int main() { int i; vsip_cscalar_d z; vsip_scalar_d data[N]; /* a public data space for I/O */ vsip_fft_d *rcfftNop; vsip_block_d *block; vsip_vview_d *xin; vsip_cvview_d *yout; vsip_init((void *)0); rcfftNop = /* Create an out-of-place Real->Cmplx N-pt FFT */ vsip_rcfftop_create_d(N, 1.0, 1, VSIP_ALG_TIME); /* Create a block object and bind it to the array data */ block = vsip_blockbind_d(data, N, VSIP_MEM_NONE); xin = vsip_vbind_d(block, 0, 1, N); /* Create another block and complex vector view for the symmetric output */ yout = vsip_cvcreate_d((N/2)+1, VSIP_MEM_NONE); /* Admit block to VSIPL for processing and initialize with a linear ramp */ vsip_blockadmit_d(block, VSIP_FALSE); vsip_vramp_d(0.0, 1.0, xin); /* Compute an out-of-place Real->Cmplx N-pt FFT using the rcfftNop object */ vsip_rcfftop_d(rcfftNop, xin, yout); /* print it */ printf("Real Input Vector\n"); for(i=0; i<N; i++) { printf("%g\n", vsip_vget_d(xin,i)); } printf("\nComplex Output Vector\n"); for(i=0; i<(N/2)+1; i++) { z = vsip_cvget_d(yout,i); printf(SCMPLX "\n", ACMPLX(z)); } /* Destroy the rcfftNop, blocks, and view objects */ vsip_fft_destroy_d(rcfftNop); vsip_valldestroy_d(xin); vsip_cvalldestroy_d(yout); vsip_finalize((void *)0); return(0); }
int main (){ vsip_init((void*)0); { int i; vsip_cblock_d* blockOut = vsip_cblockcreate_d(2 * L, 0); vsip_cvview_d* vectorOut = vsip_cvbind_d(blockOut,0,2,L); vsip_cvview_d* vectorIn = vsip_cvcreate_d(L,0); vsip_vview_d* realIn = vsip_vrealview_d(vectorIn); vsip_vview_d* imagIn = vsip_vimagview_d(vectorIn); vsip_fft_d* fftplan = vsip_ccfftop_create_d(L,1,-1,0,0); vsip_fft_d* fftplanI = vsip_ccfftop_create_d(L,(double)1/L,1,0,0); char inputdata[L][20]; /* put some data in realIn*/ vsip_vramp_d(0, 2 * PI * F, realIn); vsip_vcos_d(realIn,realIn); /* print realIn */ for(i=0; i<L; i++) sprintf(inputdata[i],"%2d input-> %7.3f",i, vsip_vget_d(realIn,i)); /*make sure imagIn is full of zeros*/ vsip_vfill_d(0,imagIn); /*find the fft*/ vsip_ccfftop_d(fftplan,vectorIn,vectorOut); /*invert the fft*/ vsip_ccfftop_d(fftplanI,vectorOut,vectorIn); /*print it */ for(i=0; i<L; i++) printf("%s fft -> (%7.3f, %7.3f) ifft -> (%7.3f, %7.3f)\n", inputdata[i], vsip_real_d(vsip_cvget_d(vectorOut,i)), vsip_imag_d(vsip_cvget_d(vectorOut,i)), vsip_real_d(vsip_cvget_d(vectorIn,i)), vsip_imag_d(vsip_cvget_d(vectorIn,i))); { vsip_vdestroy_d(imagIn); vsip_vdestroy_d(realIn); vsip_cblockdestroy_d(vsip_cvdestroy_d(vectorIn)); vsip_cblockdestroy_d(vsip_cvdestroy_d(vectorOut)); vsip_fft_destroy_d(fftplan); vsip_fft_destroy_d(fftplanI); } } vsip_finalize((void*)0);return 0; }
void test_ccorr_d(vsip_support_region support, vsip_bias bias, vsip_length ref_size, vsip_length input_size) { vsip_length const n_loop = 3; vsip_length const output_size = ref_corr_output_size(support, ref_size, input_size); vsip_ccorr1d_d *corr = vsip_ccorr1d_create_d(ref_size, input_size, support, 0, VSIP_ALG_SPACE); vsip_ccorr1d_attr attr; vsip_ccorr1d_getattr_d(corr, &attr); test_assert(attr.support == support); test_assert(attr.ref_len == ref_size); test_assert(attr.data_len == input_size); test_assert(attr.lag_len == output_size); vsip_randstate *rand = vsip_randcreate(0, 1, 1, VSIP_PRNG); vsip_cvview_d *ref = vsip_cvcreate_d(ref_size, VSIP_MEM_NONE); vsip_cvview_d *in = vsip_cvcreate_d(input_size, VSIP_MEM_NONE); vsip_cvview_d *out = vsip_cvcreate_d(output_size, VSIP_MEM_NONE); vsip_cvfill_d(vsip_cmplx_d(100,0), out); vsip_cvview_d *chk = vsip_cvcreate_d(output_size, VSIP_MEM_NONE); vsip_cvfill_d(vsip_cmplx_d(101,0), chk); vsip_index loop; for (loop=0; loop<n_loop; ++loop) { if (loop == 0) { vsip_cvfill_d(vsip_cmplx_d(1,0), ref); vsip_cvramp_d(vsip_cmplx_d(0,0), vsip_cmplx_d(1,0), in); } else if (loop == 1) { vsip_cvrandu_d(rand, ref); vsip_cvramp_d(vsip_cmplx_d(0,0), vsip_cmplx_d(1,0), in); } else { vsip_cvrandu_d(rand, ref); vsip_cvrandu_d(rand, in); } vsip_ccorrelate1d_d(corr, bias, ref, in, out); ref_ccorr_d(bias, support, ref, in, chk); double error = cverror_db_d(out, chk); #if VERBOSE if (error > -100) { vsip_index i; for (i=0; i<output_size; ++i) { vsip_cscalar_d out_value = vsip_cvget_d(out, i); vsip_cscalar_d chk_value = vsip_cvget_d(chk, i); printf("%d : out = (%f, %f), chk = (%f, %f)\n", i, out_value.r, out_value.i, chk_value.r, chk_value.i); } printf("error = %f\n", error); } #endif test_assert(error < -100); } }
void ref_ccorr_d(vsip_bias bias, vsip_support_region sup, vsip_cvview_d const *ref, vsip_cvview_d const *in, vsip_cvview_d const *out) { vsip_length M = vsip_cvgetlength_d(ref); vsip_length N = vsip_cvgetlength_d(in); vsip_length P = vsip_cvgetlength_d(out); vsip_length expected_P = ref_corr_output_size(sup, M, N); vsip_stride shift = ref_expected_shift(sup, M); assert(expected_P == P); vsip_cvview_d *sub = vsip_cvcreate_d(M, VSIP_MEM_NONE); // compute correlation vsip_index i; for (i=0; i<P; ++i) { vsip_cvfill_d(vsip_cmplx_d(0,0), sub); vsip_stride pos = (vsip_stride)i + shift; double scale; if (pos < 0) { vsip_cvview_d *subsub = vsip_cvsubview_d(sub, -pos, M + pos); vsip_cvview_d *insub = vsip_cvsubview_d(in, 0, M + pos); vsip_cvcopy_d_d(insub, subsub); vsip_cvdestroy_d(subsub); vsip_cvdestroy_d(insub); scale = M + pos; } else if (pos + M > N) { vsip_cvview_d *subsub = vsip_cvsubview_d(sub, 0, N - pos); vsip_cvview_d *insub = vsip_cvsubview_d(in, pos, N - pos); vsip_cvcopy_d_d(insub, subsub); vsip_cvdestroy_d(subsub); vsip_cvdestroy_d(insub); scale = N - pos; } else { vsip_cvview_d *insub = vsip_cvsubview_d(in, pos, M); vsip_cvcopy_d_d(insub, sub); vsip_cvdestroy_d(insub); scale = M; } #if VSIP_IMPL_CORR_CORRECT_SAME_SUPPORT_SCALING #else if (sup == VSIP_SUPPORT_SAME) { if (i < (M/2)) scale = i + (M+1)/2; // i + ceil(M/2) else if (i < N - (M/2)) scale = M; // M else scale = N - 1 + (M+1)/2 - i; // N-1+ceil(M/2)-i } #endif vsip_cscalar_d val = vsip_cvjdot_d(ref, sub); if (bias == VSIP_UNBIASED) { val.r /= scale; val.i /= scale; } vsip_cvput_d(out, i, val); } }
int main(){vsip_init((void*)0); { vsip_cmview_d *Adummy = vsip_cmcreate_d(5*NN,5*NN,VSIP_COL,0); vsip_cmview_d *A = vsip_cmsubview_d(Adummy,3,2,NN,NN); /* vsip_cmview_d *A= vsip_cmcreate_d(NN,NN,VSIP_COL,0); */ vsip_cvview_d *x0 = vsip_cvcreate_d(NN,0); vsip_vview_d *x0_r = vsip_vrealview_d(x0); vsip_vview_d *x0_i = vsip_vimagview_d(x0); vsip_cmview_d *X = vsip_cmcreate_d(NN,3,VSIP_ROW,0); vsip_cmview_d *XT = vsip_cmcreate_d(NN,3,VSIP_COL,0); vsip_cmputrowstride_d(A,2*vsip_cmgetrowstride_d(A)); vsip_cmputcolstride_d(A,3*vsip_cmgetcolstride_d(A)); /* matrix data */ vsip_cmput_d(A,0,0,vsip_cmplx_d(0.5,0.1)); vsip_cmput_d(A,0,1,vsip_cmplx_d(7,0.1)); vsip_cmput_d(A,0,2,vsip_cmplx_d(10,0.1)); vsip_cmput_d(A,0,3,vsip_cmplx_d(12,0.1)); vsip_cmput_d(A,0,4,vsip_cmplx_d(-3,0.1)); vsip_cmput_d(A,0,5,vsip_cmplx_d(0,0.1)); vsip_cmput_d(A,0,6,vsip_cmplx_d(.05,0.1)); vsip_cmput_d(A,1,0,vsip_cmplx_d(2,0.1)); vsip_cmput_d(A,1,1,vsip_cmplx_d(13,0.1)); vsip_cmput_d(A,1,2,vsip_cmplx_d(18,0.1)); vsip_cmput_d(A,1,3,vsip_cmplx_d(6,0.1)); vsip_cmput_d(A,1,4,vsip_cmplx_d(0,0.1)); vsip_cmput_d(A,1,5,vsip_cmplx_d(130,0.1)); vsip_cmput_d(A,1,6,vsip_cmplx_d(8,0.1)); vsip_cmput_d(A,2,0,vsip_cmplx_d(3,0.1)); vsip_cmput_d(A,2,1,vsip_cmplx_d(-9,0.1)); vsip_cmput_d(A,2,2,vsip_cmplx_d(2,0.1)); vsip_cmput_d(A,2,3,vsip_cmplx_d(3,0.2)); vsip_cmput_d(A,2,4,vsip_cmplx_d(2,0.2)); vsip_cmput_d(A,2,5,vsip_cmplx_d(-9,0.2)); vsip_cmput_d(A,2,6,vsip_cmplx_d(6,0.2)); vsip_cmput_d(A,3,0,vsip_cmplx_d(4,0.2)); vsip_cmput_d(A,3,1,vsip_cmplx_d(2,0.2)); vsip_cmput_d(A,3,2,vsip_cmplx_d(2,0.2)); vsip_cmput_d(A,3,3,vsip_cmplx_d(4,0.2)); vsip_cmput_d(A,3,4,vsip_cmplx_d(1,0.2)); vsip_cmput_d(A,3,5,vsip_cmplx_d(2,0.2)); vsip_cmput_d(A,3,6,vsip_cmplx_d(3,0.2)); vsip_cmput_d(A,4,0,vsip_cmplx_d(.2,0.3)); vsip_cmput_d(A,4,1,vsip_cmplx_d(2,0.3)); vsip_cmput_d(A,4,2,vsip_cmplx_d(9,0.3)); vsip_cmput_d(A,4,3,vsip_cmplx_d(4,0.3)); vsip_cmput_d(A,4,4,vsip_cmplx_d(1,0.3)); vsip_cmput_d(A,4,5,vsip_cmplx_d(2,0.3)); vsip_cmput_d(A,4,6,vsip_cmplx_d(3,0.3)); vsip_cmput_d(A,5,0,vsip_cmplx_d(.1,0.4)); vsip_cmput_d(A,5,1,vsip_cmplx_d(2,0.4)); vsip_cmput_d(A,5,2,vsip_cmplx_d(.3,0.4)); vsip_cmput_d(A,5,3,vsip_cmplx_d(4,0.4)); vsip_cmput_d(A,5,4,vsip_cmplx_d(1,0.4)); vsip_cmput_d(A,5,5,vsip_cmplx_d(2,0.4)); vsip_cmput_d(A,5,6,vsip_cmplx_d(3,0.4)); vsip_cmput_d(A,6,0,vsip_cmplx_d(.01,0.4)); vsip_cmput_d(A,6,1,vsip_cmplx_d(.2,0.4)); vsip_cmput_d(A,6,2,vsip_cmplx_d(3,0.4)); vsip_cmput_d(A,6,3,vsip_cmplx_d(4,0.4)); vsip_cmput_d(A,6,4,vsip_cmplx_d(1,0.4)); vsip_cmput_d(A,6,5,vsip_cmplx_d(2,0.4)); vsip_cmput_d(A,6,6,vsip_cmplx_d(3,0.4)); { /* were solving for NTRANS Ax = B */ /* use a known X, calculate B using Ax */ int k; vsip_cvview_d *x; vsip_cmview_d *AT = vsip_cmcreate_d(NN,NN,VSIP_ROW,VSIP_MEM_NONE); vsip_length L = vsip_cmgetrowlength_d(X); vsip_cmherm_d(A,AT); printf("A = "); VU_cmprintm_d("7.4",A); printf("AT = "); VU_cmprintm_d("7.4",AT); vsip_vramp_d(1,1,x0_r); vsip_vramp_d(1,-1,x0_i); for(k=0; k<L; k++){ x = vsip_cmcolview_d(X,k); vsip_cmvprod_d(A,x0,x); vsip_rscvmul_d(2.0,x0,x0); vsip_cvdestroy_d(x); } vsip_vramp_d(1,1,x0_r); vsip_vramp_d(1,-1,x0_i); for(k=0; k<L; k++){ x = vsip_cmcolview_d(XT,k); vsip_cmvprod_d(AT,x0,x); VU_cvprintm_d("7.4",x0); vsip_rscvmul_d(2.0,x0,x0); vsip_cvdestroy_d(x); } vsip_cmalldestroy_d(AT); printf("B = "); VU_cmprintm_d("7.4",X); printf("BT = "); VU_cmprintm_d("7.4",XT); { /* then solve to see if we get X back */ vsip_clu_d* luAop = vsip_clud_create_d(NN); if(luAop == NULL) exit(1); vsip_clud_d(luAop,A); { vsip_clu_attr_d attr; vsip_clud_getattr_d(luAop,&attr); printf("lud size %lu\n",attr.n); } vsip_clusol_d(luAop,VSIP_MAT_NTRANS,X); vsip_clusol_d(luAop,VSIP_MAT_HERM,XT); vsip_clud_destroy_d(luAop); } } printf("A\\X = "); VU_cmprintm_d("9.6",X); printf("A'\\X = "); VU_cmprintm_d("9.6",XT); { vsip_vdestroy_d(x0_r);vsip_vdestroy_d(x0_i); vsip_cvalldestroy_d(x0); vsip_cmalldestroy_d(X); vsip_cmalldestroy_d(A); } }vsip_finalize((void*)0);return 1; }
vsip_cfir_d *vsip_cfir_create_d( const vsip_cvview_d *kernel, vsip_symmetry symm, vsip_length N, vsip_length D, vsip_obj_state state, unsigned int ntimes, vsip_alg_hint hint) { vsip_length klength = 0; vsip_cfir_d *fir = (vsip_cfir_d*)malloc(sizeof(vsip_cfir_d)); if(fir == NULL){ return (vsip_cfir_d*) NULL; } else { switch(symm){ case 0: klength = kernel->length; break; case 1: klength = 2 * kernel->length - 1; break; case 2: klength = 2 * kernel->length; break; } fir->h = vsip_cvcreate_d(klength,VSIP_MEM_NONE); fir->s = vsip_cvcreate_d(klength-1,VSIP_MEM_NONE); } if((fir->h == NULL) | (fir->s == NULL)){ vsip_cfir_destroy_d(fir); return (vsip_cfir_d*) NULL; } else { fir->N = N; fir->M = klength; fir->D = D; fir->p = 0; fir->ntimes = ntimes; fir->symm = symm; fir->hint = hint; switch(symm){ case 0:{ fir->h->offset = fir->h->length - 1; fir->h->stride = -1; VI_cvcopy_d_d(kernel,fir->h); } break; case 1: { fir->h->length = kernel->length; vsip_cvconj_d(kernel,fir->h); fir->h->offset = klength - 1; fir->h->stride = -1; VI_cvcopy_d_d(kernel,fir->h); fir->h->length = klength; } break; case 2: { fir->h->length = kernel->length; vsip_cvconj_d(kernel,fir->h); fir->h->offset = klength - 1; fir->h->stride = -1; VI_cvcopy_d_d(kernel,fir->h); fir->h->length = klength; } break; } fir->state = state; fir->h->offset = 0; fir->h->stride = 1; VI_cvfill_d(vsip_cmplx_d((vsip_scalar_d)0,(vsip_scalar_d)0),fir->s); return fir; } }