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 (){ 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; }
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); }
PyObject *cvcopyToList_d(vsip_cvview_d *v){ PyObject *cval; vsip_length N = vsip_cvgetlength_d(v); PyObject *retval = PyList_New(N); vsip_index i; for(i=0; i<N; i++){ vsip_cscalar_d x = vsip_cvget_d(v,i); double re = (double)x.r; double im = (double)x.i; cval = PyComplex_FromDoubles(re,im); PyList_SetItem(retval,i,cval); } return retval; }
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); }
void VU_cvprintm_d(char s[], vsip_cvview_d *X) { char format[50]; vsip_length L = vsip_cvgetlength_d(X); vsip_index vi; vsip_cscalar_d x; strcpy(format,"(%"); strcat(format,s); strcat(format,"lf %+"); strcat(format,s); strcat(format,"lfi) %s\n"); printf("[\n"); for(vi=0; vi<L; vi++){ x=vsip_cvget_d(X,vi); printf(format,vsip_real_d(x), vsip_imag_d(x),";"); } printf("];\n"); return; }
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); } }