void VU_vfreqswapIP_d(vsip_vview_d* b) { vsip_length N = vsip_vgetlength_d(b); if(N%2){/* odd */ vsip_vview_d *a1 = vsip_vsubview_d(b, (vsip_index)(N/2)+1, (vsip_length)(N/2)); vsip_vview_d *a2 = vsip_vsubview_d(b, (vsip_index)0, (vsip_length)(N/2)+1); vsip_vview_d *a3 = vsip_vcreate_d((vsip_length)(N/2)+1, VSIP_MEM_NONE); vsip_vcopy_d_d(a2,a3); vsip_vputlength_d(a2,(vsip_length)(N/2)); vsip_vcopy_d_d(a1,a2); vsip_vputlength_d(a2,(vsip_length)(N/2) + 1); vsip_vputoffset_d(a2,(vsip_offset)(N/2)); vsip_vcopy_d_d(a3,a2); vsip_vdestroy_d(a1); vsip_vdestroy_d(a2); vsip_valldestroy_d(a3); }else{ /* even */ vsip_vview_d *a1 = vsip_vsubview_d(b, (vsip_index)(N/2), (vsip_length)(N/2)); vsip_vputlength_d(b,(vsip_length)(N/2)); vsip_vswap_d(b,a1); vsip_vdestroy_d(a1); vsip_vputlength_d(b,N); } return; }
void ref_corr_d(vsip_bias bias, vsip_support_region sup, vsip_vview_d const *ref, vsip_vview_d const *in, vsip_vview_d const *out) { vsip_length M = vsip_vgetlength_d(ref); vsip_length N = vsip_vgetlength_d(in); vsip_length P = vsip_vgetlength_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_vview_d *sub = vsip_vcreate_d(M, VSIP_MEM_NONE); // compute correlation vsip_index i; for (i=0; i<P; ++i) { vsip_vfill_d(0, sub); vsip_stride pos = (vsip_stride)i + shift; double scale; if (pos < 0) { vsip_vview_d *subsub = vsip_vsubview_d(sub, -pos, M + pos); vsip_vview_d *insub = vsip_vsubview_d(in, 0, M + pos); vsip_vcopy_d_d(insub, subsub); vsip_vdestroy_d(subsub); vsip_vdestroy_d(insub); scale = M + pos; } else if (pos + M > N) { vsip_vview_d *subsub = vsip_vsubview_d(sub, 0, N - pos); vsip_vview_d *insub = vsip_vsubview_d(in, pos, N - pos); vsip_vcopy_d_d(insub, subsub); vsip_vdestroy_d(subsub); vsip_vdestroy_d(insub); scale = N - pos; } else { vsip_vview_d *insub = vsip_vsubview_d(in, pos, M); vsip_vcopy_d_d(insub, sub); vsip_vdestroy_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 double val = vsip_vdot_d(ref, sub); if (bias == VSIP_UNBIASED) val /= scale; vsip_vput_d(out, i, val); } }