rewrite moving average
@@ -63,6 +63,7 @@ complex float median_complex_float(int N, const complex float ar[N])
return (1 == N % 2) ? tmp[(N - 1) / 2] : ((tmp[(N - 1) / 2 + 0] + tmp[(N - 1) / 2 + 1]) / 2.);
}
+
static float vec_dist(int D, const float x[D], const float y[D])
{
float sum = 0.;
@@ -115,15 +116,6 @@ static complex float median_geometric_complex_float(int N, const complex float a
return x;
}
-static complex float moving_average(int N, const complex float ar[N])
-{
- complex float sum = 0;
- long dims[1] = { N };
- md_zavg(1, dims, 1, &sum, ar);
- return sum;
-}
-
-
void md_medianz2(int D, int M, const long dim[D], const long ostr[D], complex float* optr, const long istr[D], const complex float* iptr)
{
assert(M < D);
@@ -211,29 +203,9 @@ void md_geometric_medianz(int D, int M, const long dim[D], complex float* optr,
void md_moving_avgz2(int D, int M, const long dim[D], const long ostr[D], complex float* optr, const long istr[D], const complex float* iptr)
{
assert(M < D);
- const long* nstr[2] = { ostr, istr };
- void* nptr[2] = { optr, (void*)iptr };
-
- long length = dim[M];
- long stride = istr[M];
-
- long dim2[D];
- for (int i = 0; i < D; i++)
- dim2[i] = dim[i];
+ assert(0 == ostr[M]);
- dim2[M] = 1;
-
- NESTED(void, nary_moving_avgz, (void* ptr[]))
- {
- complex float tmp[length];
-
- for (long i = 0; i < length; i++)
- tmp[i] = *((complex float*)(ptr[1] + i * stride));
-
- *(complex float*)ptr[0] = moving_average(length, tmp);
- };
-
- md_nary(2, D, dim2, nstr, nptr, nary_moving_avgz);
+ md_zavg2(D, dim, (1u << M), ostr, optr, istr, iptr);
}
void md_moving_avgz(int D, int M, const long dim[D], complex float* optr, const complex float* iptr)
@@ -241,16 +213,15 @@ void md_moving_avgz(int D, int M, const long dim[D], complex float* optr, const
assert(M < D);
long dim2[D];
- for (int i = 0; i < D; i++)
- dim2[i] = dim[i];
+ md_copy_dims(D, dim2, dim);
dim2[M] = 1;
long istr[D];
long ostr[D];
- md_calc_strides(D, istr, dim, 8);
- md_calc_strides(D, ostr, dim2, 8);
+ md_calc_strides(D, istr, dim, CFL_SIZE);
+ md_calc_strides(D, ostr, dim2, CFL_SIZE);
md_moving_avgz2(D, M, dim, ostr, optr, istr, iptr);
}
