Commit 453945cd authored by Martin Reinecke's avatar Martin Reinecke
Browse files

extend interface; tweaks

parent b83841dd
......@@ -199,7 +199,7 @@ template<typename It, typename T2, typename Comp>
T2 num=end-begin;
idx.resize(num);
for (T2 i=0; i<num; ++i) idx[i] = i;
sort (idx.begin(),idx.end(),IdxComp__<It,Comp>(begin,comp));
stable_sort (idx.begin(),idx.end(),IdxComp__<It,Comp>(begin,comp));
}
/*! Performs an indirect sort on the supplied iterator range and returns in
......@@ -534,6 +534,8 @@ template<typename T> class Baselines
}
};
constexpr int logsquare=4;
template<typename T> class GridderConfig
{
private:
......@@ -550,7 +552,7 @@ template<typename T> class GridderConfig
ucorr(1./urange), vcorr(1./vrange),
w(get_w(epsilon)), nsafe((w+1)/2),
nu(max(2*nsafe,2*nx_dirty)), nv(max(2*nsafe,2*ny_dirty)),
peano_level(bits_needed(max(nu, nv))),
peano_level(max(1,bits_needed(max(nu, nv))-logsquare)),
cfu(nx_dirty), cfv(ny_dirty)
{
myassert((nx_dirty&1)==0, "nx_dirty must be even");
......@@ -579,9 +581,15 @@ template<typename T> class GridderConfig
{
double u=fmodulo(coord.u*ucorr, T(1))*nu,
v=fmodulo(coord.v*vcorr, T(1))*nv;
auto iu = min(nu-1, size_t(u));
auto iv = min(nv-1, size_t(v));
return morton2peano2D_32(coord2morton2D_32(iu,iv),peano_level);
int iu0 = int(u-w*0.5 + 1 + nu) - nu;
if (iu0+w>nu+nsafe) iu0 = nu+nsafe-w;
iu0+=nsafe;
int iv0 = int(v-w*0.5 + 1 + nv) - nv;
if (iv0+w>nv+nsafe) iv0 = nv+nsafe-w;
iv0+=nsafe;
iu0>>=logsquare;
iv0>>=logsquare;
return morton2peano2D_32(coord2morton2D_32(iu0,iv0),peano_level);
}
pyarr_c<T> grid2dirty(const pyarr_c<T> &grid) const
{
......@@ -667,14 +675,14 @@ template<typename T> class Helper
void update_position()
{
bu0=max(-nsafe, min(nu+nsafe-su, iu0+nsafe-su/2));
bv0=max(-nsafe, min(nv+nsafe-sv, iv0+nsafe-sv/2));
bu0=((((iu0+nsafe)>>logsquare)<<logsquare))-nsafe;
bv0=((((iv0+nsafe)>>logsquare)<<logsquare))-nsafe;
}
protected:
Helper(int nu_, int nv_, int w_)
: nu(nu_), nv(nv_), w(w_), beta(2.3*w), nsafe((w+1)/2),
su(min(max(2*nsafe,80), nu)), sv(min(max(2*nsafe,80), nv)),
su(2*nsafe+(1<<logsquare)), sv(2*nsafe+(1<<logsquare)),
kernel(2*w),
bu0(-1000000), bv0(-1000000)
{
......@@ -831,7 +839,7 @@ template<typename T> pyarr_c<T> vis2grid(const Baselines<T> &baselines,
const T * RESTRICT kv = hlp.kernel.data()+hlp.w;
// Loop over sampling points
#pragma omp for schedule(dynamic,10000)
#pragma omp for schedule(guided,100)
for (size_t ipart=0; ipart<nvis; ++ipart)
{
UVW<T> coord = baselines.effectiveCoord(idx[ipart]);
......@@ -877,7 +885,7 @@ template<typename T> pyarr_c<complex<T>> grid2vis(const Baselines<T> &baselines,
const T * RESTRICT ku = hlp.kernel.data();
const T * RESTRICT kv = hlp.kernel.data()+hlp.w;
#pragma omp for schedule(dynamic,10000)
#pragma omp for schedule(guided,100)
for (size_t ipart=0; ipart<nvis; ++ipart)
{
UVW<T> coord = baselines.effectiveCoord(idx[ipart]);
......@@ -1101,6 +1109,8 @@ PYBIND11_MODULE(nifty_gridder, m)
py::class_<Baselines<double>> (m, "Baselines", Baselines_DS)
.def(py::init<const pyarr_c<double> &, const pyarr_c<double> &,
const pyarr_c<bool> &>(), "coord"_a, "scaling"_a, "flags"_a)
.def ("Nrows",&Baselines<double>::Nrows)
.def ("Nchannels",&Baselines<double>::Nchannels)
.def ("ms2vis",&Baselines<double>::ms2vis<complex<double>>, BL_ms2vis_DS, "ms"_a, "idx"_a)
.def ("ms2vis_f32",&Baselines<double>::ms2vis<float>, "ms"_a, "idx"_a)
.def ("vis2ms",&Baselines<double>::vis2ms<complex<double>>, BL_vis2ms_DS, "vis"_a, "idx"_a)
......@@ -1121,6 +1131,8 @@ PYBIND11_MODULE(nifty_gridder, m)
py::class_<Baselines<float>> (m, "Baselines_f", Baselines_DS)
.def(py::init<const pyarr_c<float> &, const pyarr_c<float> &,
const pyarr_c<bool> &>(), "coord"_a, "scaling"_a, "flags"_a)
.def ("Nrows",&Baselines<float>::Nrows)
.def ("Nchannels",&Baselines<float>::Nchannels)
.def ("ms2vis",&Baselines<float>::ms2vis<complex<float>>, BL_ms2vis_DS, "ms"_a, "idx"_a)
.def ("vis2ms",&Baselines<float>::vis2ms<complex<float>>, BL_vis2ms_DS, "vis"_a, "idx"_a)
.def ("add_vis_to_ms",&Baselines<float>::add_vis_to_ms<complex<float>>, BL_add_vis_to_ms_DS,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment