Commit 8610cc13 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

generalize data types

parent d9642e63
......@@ -503,14 +503,14 @@ template<typename T> class Baselines
}
};
class GridderConfig
template<typename T> class GridderConfig
{
private:
size_t nx_dirty, ny_dirty;
double ucorr, vcorr;
T ucorr, vcorr;
size_t w, nsafe, nu, nv;
size_t peano_level;
vector<double> cfu, cfv;
vector<T> cfu, cfv;
public:
GridderConfig(size_t nxdirty, size_t nydirty, double epsilon,
......@@ -542,17 +542,17 @@ class GridderConfig
size_t Nu() const { return nu; }
size_t Nv() const { return nv; }
size_t W() const { return w; }
size_t coord2peano(const UVW<double> &coord) const
size_t coord2peano(const UVW<T> &coord) const
{
double u=fmodulo(coord.u*ucorr, 1.)*nu,
v=fmodulo(coord.v*vcorr, 1.)*nv;
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);
}
pyarr_c<double> grid2dirty(const pyarr_c<double> &grid) const
pyarr_c<T> grid2dirty(const pyarr_c<T> &grid) const
{
auto tmp = makearray<double>({nu, nv});
auto tmp = makearray<T>({nu, nv});
auto ptmp = tmp.mutable_data();
pocketfft::r2r_hartley({nu, nv},
{grid.strides(0), grid.strides(1)},
......@@ -562,16 +562,16 @@ class GridderConfig
for(size_t i=1; i<(nu+1)/2; ++i)
for(size_t j=1; j<(nv+1)/2; ++j)
{
double a = ptmp[i*nv+j];
double b = ptmp[(nu-i)*nv+j];
double c = ptmp[i*nv+nv-j];
double d = ptmp[(nu-i)*nv+nv-j];
ptmp[i*nv+j] = 0.5*(a+b+c-d);
ptmp[(nu-i)*nv+j] = 0.5*(a+b+d-c);
ptmp[i*nv+nv-j] = 0.5*(a+c+d-b);
ptmp[(nu-i)*nv+nv-j] = 0.5*(b+c+d-a);
T a = ptmp[i*nv+j];
T b = ptmp[(nu-i)*nv+j];
T c = ptmp[i*nv+nv-j];
T d = ptmp[(nu-i)*nv+nv-j];
ptmp[i*nv+j] = T(0.5)*(a+b+c-d);
ptmp[(nu-i)*nv+j] = T(0.5)*(a+b+d-c);
ptmp[i*nv+nv-j] = T(0.5)*(a+c+d-b);
ptmp[(nu-i)*nv+nv-j] = T(0.5)*(b+c+d-a);
}
auto res = makearray<double>({nx_dirty, ny_dirty});
auto res = makearray<T>({nx_dirty, ny_dirty});
auto pout = res.mutable_data();
for (size_t i=0; i<nx_dirty; ++i)
for (size_t j=0; j<ny_dirty; ++j)
......@@ -584,10 +584,10 @@ class GridderConfig
}
return res;
}
pyarr_c<double> dirty2grid(const pyarr_c<double> &dirty) const
pyarr_c<T> dirty2grid(const pyarr_c<T> &dirty) const
{
auto pdirty = dirty.data();
auto tmp = makearray<double>({nu, nv});
auto tmp = makearray<T>({nu, nv});
auto ptmp = tmp.mutable_data();
for (size_t i=0; i<nu*nv; ++i)
ptmp[i] = 0.;
......@@ -607,14 +607,14 @@ class GridderConfig
for(size_t i=1; i<(nu+1)/2; ++i)
for(size_t j=1; j<(nv+1)/2; ++j)
{
double a = ptmp[i*nv+j];
double b = ptmp[(nu-i)*nv+j];
double c = ptmp[i*nv+nv-j];
double d = ptmp[(nu-i)*nv+nv-j];
ptmp[i*nv+j] = 0.5*(a+b+c-d);
ptmp[(nu-i)*nv+j] = 0.5*(a+b+d-c);
ptmp[i*nv+nv-j] = 0.5*(a+c+d-b);
ptmp[(nu-i)*nv+nv-j] = 0.5*(b+c+d-a);
T a = ptmp[i*nv+j];
T b = ptmp[(nu-i)*nv+j];
T c = ptmp[i*nv+nv-j];
T d = ptmp[(nu-i)*nv+nv-j];
ptmp[i*nv+j] = T(0.5)*(a+b+c-d);
ptmp[(nu-i)*nv+j] = T(0.5)*(a+b+d-c);
ptmp[i*nv+nv-j] = T(0.5)*(a+c+d-b);
ptmp[(nu-i)*nv+nv-j] = T(0.5)*(b+c+d-a);
}
return tmp;
}
......@@ -758,7 +758,7 @@ class ReadHelper: public Helper
}
};
pyarr_c<double> vis2grid(const Baselines<double> &baselines, const GridderConfig &gconf,
pyarr_c<double> vis2grid(const Baselines<double> &baselines, const GridderConfig<double> &gconf,
const pyarr_c<uint32_t> &idx_, const pyarr_c<complex<double>> &vis_)
{
myassert(idx_.ndim()==1, "idx array must be 1D");
......@@ -801,7 +801,7 @@ pyarr_c<double> vis2grid(const Baselines<double> &baselines, const GridderConfig
return complex2hartley(res);
}
pyarr_c<complex<double>> grid2vis(const Baselines<double> &baselines,
const GridderConfig &gconf, const pyarr_c<uint32_t> &idx_,
const GridderConfig<double> &gconf, const pyarr_c<uint32_t> &idx_,
const pyarr_c<double> &grid0_)
{
size_t nu=gconf.Nu(), nv=gconf.Nv();
......@@ -848,7 +848,7 @@ pyarr_c<complex<double>> grid2vis(const Baselines<double> &baselines,
}
pyarr_c<uint32_t> getIndices(const Baselines<double> &baselines,
const GridderConfig &gconf, int chbegin, int chend, double wmin, double wmax)
const GridderConfig<double> &gconf, int chbegin, int chend, double wmin, double wmax)
{
auto idx = baselines.getIndices(chbegin, chend, wmin, wmax);
vector<size_t> peano(idx.size());
......@@ -937,13 +937,13 @@ PYBIND11_MODULE(nifty_gridder, m)
.def ("vis2ms",&Baselines<double>::vis2ms, BL_vis2ms_DS, "vis"_a, "idx"_a)
.def ("add_vis_to_ms",&Baselines<double>::add_vis_to_ms, BL_add_vis_to_ms_DS,
"vis"_a, "idx"_a, "ms"_a.noconvert());
py::class_<GridderConfig> (m, "GridderConfig")
py::class_<GridderConfig<double>> (m, "GridderConfig")
.def(py::init<size_t, size_t, double, double, double>(),"nxdirty"_a,
"nydirty"_a, "epsilon"_a, "urange"_a, "vrange"_a)
.def("Nu", &GridderConfig::Nu)
.def("Nv", &GridderConfig::Nv)
.def("grid2dirty", &GridderConfig::grid2dirty, "grid"_a)
.def("dirty2grid", &GridderConfig::dirty2grid, "dirty"_a);
.def("Nu", &GridderConfig<double>::Nu)
.def("Nv", &GridderConfig<double>::Nv)
.def("grid2dirty", &GridderConfig<double>::grid2dirty, "grid"_a)
.def("dirty2grid", &GridderConfig<double>::dirty2grid, "dirty"_a);
m.def("getIndices", getIndices, "baselines"_a, "gconf"_a, "chbegin"_a=-1,
"chend"_a=-1, "wmin"_a=-1e30, "wmax"_a=1e30);
m.def("vis2grid",&vis2grid, "baselines"_a, "gconf"_a, "idx"_a, "vis"_a);
......
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