...
 
Commits (2)
......@@ -1091,7 +1091,27 @@ PYBIND11_MODULE(nifty_gridder, m)
.def("grid2dirty_c", &GridderConfig<double>::grid2dirty_c, "grid"_a)
.def("dirty2grid", &GridderConfig<double>::dirty2grid, dirty2grid_DS,
"dirty"_a)
.def("dirty2grid_c", &GridderConfig<double>::dirty2grid_c, "dirty"_a);
.def("dirty2grid_c", &GridderConfig<double>::dirty2grid_c, "dirty"_a)
// pickle support
.def(py::pickle(
// __getstate__
[](const GridderConfig<double> & gc) {
// Encode object state in tuple
return py::make_tuple(gc.Nxdirty(), gc.Nydirty(), gc.Epsilon(),
gc.Pixsize_x(), gc.Pixsize_y());
},
// __setstate__
[](py::tuple t) {
if(t.size() != 5)
{ throw std::runtime_error("Invalid state"); }
// Reconstruct from tuple
return GridderConfig<double>(t[0].cast<size_t>(), t[1].cast<size_t>(),
t[2].cast<double>(), t[3].cast<double>(),
t[4].cast<double>());
}));
m.def("getIndices", getIndices<double>, getIndices_DS, "baselines"_a,
"gconf"_a, "flags"_a, "chbegin"_a=-1, "chend"_a=-1,
"wmin"_a=-1e30, "wmax"_a=1e30);
......
try:
import cPickle as pickle
except ImportError:
import pickle
import nifty_gridder as ng
# Have to use cPickle and pickle protocol 2 for this to work
# unfortunately
pickle_protocol = 2
gc = ng.GridderConfig(1024, 1024, 2e-13, 2.0, 2.0)
pickled = pickle.dumps(gc, pickle_protocol)
gc2 = pickle.loads(pickled)
assert gc is not gc2
assert gc.Nxdirty() == gc2.Nxdirty()
assert gc.Nydirty() == gc2.Nydirty()
assert gc.Epsilon() == gc2.Epsilon()
assert gc.Pixsize_x() == gc2.Pixsize_x()
assert gc.Pixsize_y() == gc2.Pixsize_y()