void (vsip_cmprodj_d)( const vsip_cmview_d* A, const vsip_cmview_d* B, const vsip_cmview_d* R) { { vsip_length M = A->col_length, N = B->row_length; vsip_stride cRst = R->block->cstride; vsip_cscalar_d tmp; vsip_length i,j; vsip_cvview_d aa,bb,rr,*a,*b,*r; a = &aa; b = &bb; r = &rr; /* row view */ a->block = A->block; a->offset = A->offset; a->stride = A->row_stride; a->length = A->row_length; /* col view */ b->block = B->block; b->offset = B->offset; b->stride = B->col_stride; b->length = B->col_length; /* row view */ r->block = R->block; r->offset = R->offset; r->stride = R->row_stride; r->length = R->row_length; a->markings = vsip_valid_structure_object; b->markings = vsip_valid_structure_object; r->markings = vsip_valid_structure_object; for(i = 0; i < M; i++){ vsip_scalar_d *r_pr =(vsip_scalar_d*) (r->block->R->array + cRst * r->offset); vsip_scalar_d *r_pi =(vsip_scalar_d*) (r->block->I->array + cRst * r->offset); vsip_stride str = cRst * r->stride; b->offset = B->offset; for(j =0; j < N; j++){ tmp = vsip_cvjdot_d(a,b); *r_pr = tmp.r; *r_pi =tmp.i; r_pr += str; r_pi += str; b->offset += B->row_stride; } a->offset += A->col_stride; r->offset += R->col_stride; } } }
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); } }