Commit 025e08dd authored by Martin Reinecke's avatar Martin Reinecke

improve namespace handling; build a single shared object

parent afad44ed
#include "mr_util/infra/system.cc"
#include "mr_util/infra/string_utils.cc"
#include "mr_util/infra/threading.cc"
#include "mr_util/math/pointing.cc"
#include "mr_util/math/geom_utils.cc"
#include "mr_util/sharp/sharp.cc"
#include "mr_util/sharp/sharp_almhelpers.cc"
#include "mr_util/sharp/sharp_core.cc"
#include "mr_util/sharp/sharp_ylmgen.cc"
#include "mr_util/sharp/sharp_geomhelpers.cc"
#include "mr_util/healpix/healpix_tables.cc"
#include "mr_util/healpix/healpix_base.cc"
#include <pybind11/pybind11.h>
#include "pysharp/pysharp.cc"
#include "pypocketfft/pypocketfft.cc"
#include "pyinterpol_ng/pyinterpol_ng.cc"
#include "nifty_gridder/nifty_gridder.cc"
#include "pyHealpix/pyHealpix.cc"
using namespace mr;
PYBIND11_MODULE(cxxbase1, m)
{
add_pypocketfft(m);
add_pysharp(m);
add_pyinterpol_ng(m);
add_nifty_gridder(m);
add_pyHealpix(m);
}
...@@ -24,14 +24,16 @@ ...@@ -24,14 +24,16 @@
#include "mr_util/bindings/pybind_utils.h" #include "mr_util/bindings/pybind_utils.h"
#include "gridder_cxx.h" #include "gridder_cxx.h"
namespace mr {
namespace detail_nifty_gridder {
using namespace std; using namespace std;
using namespace gridder; using namespace gridder;
using namespace mr; using namespace mr;
namespace py = pybind11; namespace py = pybind11;
namespace {
auto None = py::none(); auto None = py::none();
template<typename T> py::array ms2dirty_general2(const py::array &uvw_, template<typename T> py::array ms2dirty_general2(const py::array &uvw_,
...@@ -192,11 +194,10 @@ py::array Pydirty2ms(const py::array &uvw, ...@@ -192,11 +194,10 @@ py::array Pydirty2ms(const py::array &uvw,
verbosity); verbosity);
} }
} // unnamed namespace void add_nifty_gridder(py::module &msup)
PYBIND11_MODULE(nifty_gridder, m)
{ {
using namespace pybind11::literals; using namespace pybind11::literals;
auto m = msup.def_submodule("nifty_gridder");
m.def("ms2dirty", &Pyms2dirty, ms2dirty_DS, "uvw"_a, "freq"_a, "ms"_a, m.def("ms2dirty", &Pyms2dirty, ms2dirty_DS, "uvw"_a, "freq"_a, "ms"_a,
"wgt"_a=None, "npix_x"_a, "npix_y"_a, "pixsize_x"_a, "pixsize_y"_a, "wgt"_a=None, "npix_x"_a, "npix_y"_a, "pixsize_x"_a, "pixsize_y"_a,
...@@ -211,3 +212,9 @@ PYBIND11_MODULE(nifty_gridder, m) ...@@ -211,3 +212,9 @@ PYBIND11_MODULE(nifty_gridder, m)
"wgt"_a=None, "pixsize_x"_a, "pixsize_y"_a, "nu"_a, "nv"_a, "epsilon"_a, "wgt"_a=None, "pixsize_x"_a, "pixsize_y"_a, "nu"_a, "nv"_a, "epsilon"_a,
"do_wstacking"_a=false, "nthreads"_a=1, "verbosity"_a=0); "do_wstacking"_a=false, "nthreads"_a=1, "verbosity"_a=0);
} }
}
using detail_nifty_gridder::add_nifty_gridder;
}
...@@ -39,13 +39,15 @@ ...@@ -39,13 +39,15 @@
#include "mr_util/math/geom_utils.h" #include "mr_util/math/geom_utils.h"
#include "mr_util/bindings/pybind_utils.h" #include "mr_util/bindings/pybind_utils.h"
namespace mr {
namespace detail_pyHealpix {
using namespace std; using namespace std;
using namespace mr; using namespace mr;
namespace py = pybind11; namespace py = pybind11;
namespace {
using shape_t = fmav_info::shape_t; using shape_t = fmav_info::shape_t;
template<size_t nd1, size_t nd2> shape_t repl_dim(const shape_t &s, template<size_t nd1, size_t nd2> shape_t repl_dim(const shape_t &s,
...@@ -343,12 +345,10 @@ that their last dimension is removed. ...@@ -343,12 +345,10 @@ that their last dimension is removed.
The employed algorithm is highly accurate, even for angles close to 0 or pi. The employed algorithm is highly accurate, even for angles close to 0 or pi.
)"""; )""";
} // unnamed namespace void add_pyHealpix(py::module &msup)
PYBIND11_MODULE(pyHealpix, m)
{ {
using namespace pybind11::literals; using namespace pybind11::literals;
auto m = msup.def_submodule("pyHealpix");
m.doc() = pyHealpix_DS; m.doc() = pyHealpix_DS;
py::class_<Pyhpbase> (m, "Healpix_Base") py::class_<Pyhpbase> (m, "Healpix_Base")
...@@ -382,3 +382,9 @@ PYBIND11_MODULE(pyHealpix, m) ...@@ -382,3 +382,9 @@ PYBIND11_MODULE(pyHealpix, m)
m.def("vec2ang",&vec2ang, vec2ang_DS, "vec"_a); m.def("vec2ang",&vec2ang, vec2ang_DS, "vec"_a);
m.def("v_angle",&local_v_angle, v_angle_DS, "v1"_a, "v2"_a); m.def("v_angle",&local_v_angle, v_angle_DS, "v1"_a, "v2"_a);
} }
}
using detail_pyHealpix::add_pyHealpix;
}
...@@ -7,13 +7,15 @@ ...@@ -7,13 +7,15 @@
#include <pybind11/numpy.h> #include <pybind11/numpy.h>
#include "interpol_ng.h" #include "interpol_ng.h"
namespace mr {
namespace detail_pyinterpol_ng {
using namespace std; using namespace std;
using namespace mr; using namespace mr;
namespace py = pybind11; namespace py = pybind11;
namespace {
template<typename T> class PyInterpolator: public Interpolator<T> template<typename T> class PyInterpolator: public Interpolator<T>
{ {
protected: protected:
...@@ -232,11 +234,10 @@ Notes ...@@ -232,11 +234,10 @@ Notes
- must be the last call to the object - must be the last call to the object
)"""; )""";
} // unnamed namespace void add_pyinterpol_ng(py::module &msup)
PYBIND11_MODULE(pyinterpol_ng, m)
{ {
using namespace pybind11::literals; using namespace pybind11::literals;
auto m = msup.def_submodule("pyinterpol_ng");
m.doc() = pyinterpol_ng_DS; m.doc() = pyinterpol_ng_DS;
...@@ -268,3 +269,9 @@ PYBIND11_MODULE(pyinterpol_ng, m) ...@@ -268,3 +269,9 @@ PYBIND11_MODULE(pyinterpol_ng, m)
#endif #endif
m.def("epsilon_guess", &epsilon_guess, "support"_a, "ofactor"_a); m.def("epsilon_guess", &epsilon_guess, "support"_a, "ofactor"_a);
} }
}
using detail_pyinterpol_ng::add_pyinterpol_ng;
}
...@@ -19,6 +19,10 @@ ...@@ -19,6 +19,10 @@
#include "mr_util/math/fft.h" #include "mr_util/math/fft.h"
#include "mr_util/bindings/pybind_utils.h" #include "mr_util/bindings/pybind_utils.h"
namespace mr {
namespace detail_pypocketfft {
namespace { namespace {
using shape_t = mr::fmav_info::shape_t; using shape_t = mr::fmav_info::shape_t;
...@@ -645,10 +649,10 @@ out : int ...@@ -645,10 +649,10 @@ out : int
} // unnamed namespace } // unnamed namespace
PYBIND11_MODULE(pypocketfft, m) void add_pypocketfft(py::module &msup)
{ {
using namespace pybind11::literals; using namespace pybind11::literals;
auto m = msup.def_submodule("pypocketfft");
m.doc() = pypocketfft_DS; m.doc() = pypocketfft_DS;
m.def("c2c", c2c, c2c_DS, "a"_a, "axes"_a=None, "forward"_a=true, m.def("c2c", c2c, c2c_DS, "a"_a, "axes"_a=None, "forward"_a=true,
"inorm"_a=0, "out"_a=None, "nthreads"_a=1); "inorm"_a=0, "out"_a=None, "nthreads"_a=1);
...@@ -671,3 +675,9 @@ PYBIND11_MODULE(pypocketfft, m) ...@@ -671,3 +675,9 @@ PYBIND11_MODULE(pypocketfft, m)
{{"good_size", good_size, METH_VARARGS, good_size_DS}, {0, 0, 0, 0}}; {{"good_size", good_size, METH_VARARGS, good_size_DS}, {0, 0, 0, 0}};
PyModule_AddFunctions(m.ptr(), good_size_meth); PyModule_AddFunctions(m.ptr(), good_size_meth);
} }
}
using detail_pypocketfft::add_pypocketfft;
}
...@@ -42,13 +42,15 @@ ...@@ -42,13 +42,15 @@
#include "mr_util/math/constants.h" #include "mr_util/math/constants.h"
#include "mr_util/bindings/pybind_utils.h" #include "mr_util/bindings/pybind_utils.h"
namespace mr {
namespace detail_pysharp {
using namespace std; using namespace std;
using namespace mr; using namespace mr;
namespace py = pybind11; namespace py = pybind11;
namespace {
using a_d = py::array_t<double>; using a_d = py::array_t<double>;
using a_d_c = py::array_t<double, py::array::c_style | py::array::forcecast>; using a_d_c = py::array_t<double, py::array::c_style | py::array::forcecast>;
using a_c_c = py::array_t<complex<double>, using a_c_c = py::array_t<complex<double>,
...@@ -266,12 +268,10 @@ py::array py_upsample_to_cc(const py::array &in, size_t nrings_out, bool has_np, ...@@ -266,12 +268,10 @@ py::array py_upsample_to_cc(const py::array &in, size_t nrings_out, bool has_np,
return move(out); return move(out);
} }
} // unnamed namespace void add_pysharp(py::module &msup)
PYBIND11_MODULE(pysharp, m)
{ {
using namespace pybind11::literals; using namespace pybind11::literals;
auto m = msup.def_submodule("pysharp");
m.doc() = pysharp_DS; m.doc() = pysharp_DS;
py::class_<py_sharpjob<double>> (m, "sharpjob_d") py::class_<py_sharpjob<double>> (m, "sharpjob_d")
...@@ -303,3 +303,10 @@ PYBIND11_MODULE(pysharp, m) ...@@ -303,3 +303,10 @@ PYBIND11_MODULE(pysharp, m)
m.def("upsample_to_cc",&py_upsample_to_cc, "in"_a, "nrings_out"_a, m.def("upsample_to_cc",&py_upsample_to_cc, "in"_a, "nrings_out"_a,
"has_np"_a, "has_sp"_a, "out"_a=py::none()); "has_np"_a, "has_sp"_a, "out"_a=py::none());
} }
}
using detail_pysharp::add_pysharp;
}
...@@ -29,154 +29,20 @@ elif sys.platform == 'win32': ...@@ -29,154 +29,20 @@ elif sys.platform == 'win32':
extra_compile_args = ['/Ox', '/EHsc', '/std:c++17'] extra_compile_args = ['/Ox', '/EHsc', '/std:c++17']
else: else:
extra_compile_args += ['-Wfatal-errors', '-Wfloat-conversion', '-W', '-Wall', '-Wstrict-aliasing=2', '-Wwrite-strings', '-Wredundant-decls', '-Woverloaded-virtual', '-Wcast-qual', '-Wcast-align', '-Wpointer-arith'] extra_compile_args += ['-Wfatal-errors', '-Wfloat-conversion', '-W', '-Wall', '-Wstrict-aliasing=2', '-Wwrite-strings', '-Wredundant-decls', '-Woverloaded-virtual', '-Wcast-qual', '-Wcast-align', '-Wpointer-arith']
python_module_link_args += ['-march=native', '-Wl,-rpath,$ORIGIN' ,'-s'] python_module_link_args += ['-march=native', '-Wl,-rpath,$ORIGIN', '-s']
# if you don't want debugging info, add "-s" to python_module_link_args # if you don't want debugging info, add "-s" to python_module_link_args
def get_extension_modules(): def get_extension_modules():
return [Extension(pkgname+'.pypocketfft', return [Extension(pkgname,
language='c++', language='c++',
sources=['pypocketfft/pypocketfft.cc', sources=['cxxbase.cc'],
'src/mr_util/infra/threading.cc'], depends=[],
depends=['src/mr_util/infra/useful_macros.h',
'src/mr_util/math/fft.h',
'src/mr_util/math/fft1d.h',
'src/mr_util/infra/mav.h',
'src/mr_util/infra/threading.h',
'src/mr_util/infra/aligned_array.h',
'src/mr_util/infra/simd.h',
'src/mr_util/math/cmplx.h',
'src/mr_util/math/unity_roots.h',
'src/mr_util/infra/error_handling.h',
'src/mr_util/bindings/pybind_utils.h',
'setup.py'],
include_dirs=include_dirs, include_dirs=include_dirs,
define_macros=define_macros, define_macros=define_macros,
extra_compile_args=extra_compile_args, extra_compile_args=extra_compile_args,
extra_link_args=python_module_link_args), extra_link_args=python_module_link_args),
Extension(pkgname+'.pysharp', ]
language='c++',
sources=['pysharp/pysharp.cc',
'src/mr_util/infra/threading.cc',
'src/mr_util/infra/string_utils.cc',
'src/mr_util/sharp/sharp.cc',
'src/mr_util/sharp/sharp_core.cc',
'src/mr_util/sharp/sharp_geomhelpers.cc',
'src/mr_util/sharp/sharp_almhelpers.cc',
'src/mr_util/sharp/sharp_ylmgen.cc'],
depends=['src/mr_util/fft1d.h',
'src/mr_util/fft.h',
'src/mr_util/infra/threading.h',
'src/mr_util/infra/mav.h',
'src/mr_util/math_utils.h',
'src/mr_util/infra/aligned_array.h',
'src/mr_util/math/gl_integrator.h',
'src/mr_util/infra/simd.h',
'src/mr_util/math/cmplx.h',
'src/mr_util/infra/string_utils.h',
'src/mr_util/infra/timers.h',
'src/mr_util/math/constants.h',
'src/mr_util/math/unity_roots.h',
'src/mr_util/infra/error_handling.h',
'src/mr_util/infra/useful_macros.h',
'src/mr_util/bindings/pybind_utils.h',
'src/mr_util/sharp/sharp.h',
'src/mr_util/sharp/sharp_internal.h',
'src/mr_util/sharp/sharp_geomhelpers.h',
'src/mr_util/sharp/sharp_almhelpers.h'
'setup.py'],
include_dirs=include_dirs,
define_macros=define_macros,
extra_compile_args=extra_compile_args,
extra_link_args=python_module_link_args),
Extension(pkgname+'.pyHealpix',
language='c++',
sources=['pyHealpix/pyHealpix.cc',
'src/mr_util/math/geom_utils.cc',
'src/mr_util/math/pointing.cc',
'src/mr_util/infra/string_utils.cc',
'src/mr_util/math/space_filling.cc',
'src/mr_util/healpix/healpix_base.cc',
'src/mr_util/healpix/healpix_tables.cc'],
depends=['src/mr_util/infra/mav.h',
'src/mr_util/math/math_utils.h',
'src/mr_util/math/space_filling.h',
'src/mr_util/math/rangeset.h',
'src/mr_util/infra/string_utils.h',
'src/mr_util/math/geom_utils.h',
'src/mr_util/math/pointing.h',
'src/mr_util/math/vec3.h',
'src/mr_util/math/constants.h',
'src/mr_util/infra/error_handling.h',
'src/mr_util/healpix/healpix_base.h',
'src/mr_util/healpix/healpix_tables.h',
'src/mr_util/bindings/pybind_utils.h',
'setup.py'],
include_dirs=include_dirs,
define_macros=define_macros,
extra_compile_args=extra_compile_args,
extra_link_args=python_module_link_args),
Extension(pkgname+'.nifty_gridder',
sources=['nifty_gridder/nifty_gridder.cc',
'src/mr_util/infra/threading.cc'],
depends=['src/mr_util/infra/useful_macros.h',
'src/mr_util/math/constants.h',
'src/mr_util/math/gl_integrator.h',
'src/mr_util/infra/error_handling.h',
'src/mr_util/math/fft.h',
'src/mr_util/math/fft1d.h',
'src/mr_util/infra/threading.h',
'src/mr_util/infra/aligned_array.h',
'src/mr_util/infra/simd.h',
'src/mr_util/infra/mav.h',
'src/mr_util/math/cmplx.h',
'src/mr_util/math/unity_roots.h',
'src/mr_util/math/es_kernel.h',
'src/mr_util/bindings/pybind_utils.h',
'nifty_gridder/gridder_cxx.h',
'setup.py'],
include_dirs=include_dirs + ['./nifty_gridder'],
extra_compile_args=extra_compile_args,
extra_link_args=python_module_link_args),
Extension(pkgname+'.pyinterpol_ng',
language='c++',
sources=['pyinterpol_ng/pyinterpol_ng.cc',
'src/mr_util/infra/threading.cc',
'src/mr_util/sharp/sharp.cc',
'src/mr_util/sharp/sharp_core.cc',
'src/mr_util/sharp/sharp_geomhelpers.cc',
'src/mr_util/sharp/sharp_almhelpers.cc',
'src/mr_util/sharp/sharp_ylmgen.cc'],
depends=[
'src/mr_util/math/fft1d.h',
'src/mr_util/math/fft.h',
'src/mr_util/infra/threading.h',
'src/mr_util/infra/mav.h',
'src/mr_util/math/math_utils.h',
'src/mr_util/infra/aligned_array.h',
'src/mr_util/math/gl_integrator.h',
'src/mr_util/infra/simd.h',
'src/mr_util/math/cmplx.h',
'src/mr_util/infra/string_utils.h',
'src/mr_util/infra/timers.h',
'src/mr_util/math/constants.h',
'src/mr_util/math/unity_roots.h',
'src/mr_util/math/es_kernel.h',
'src/mr_util/infra/error_handling.h',
'src/mr_util/infra/useful_macros.h',
'src/mr_util/bindings/pybind_utils.h',
'src/mr_util/sharp/sharp.h',
'src/mr_util/sharp/sharp_internal.h',
'src/mr_util/sharp/sharp_geomhelpers.h',
'src/mr_util/sharp/sharp_almhelpers.h',
'setup.py',
'pyinterpol_ng/interpol_ng.h',
'pyinterpol_ng/alm.h'],
include_dirs=include_dirs + ['./pyinterpol_ng'],
define_macros=define_macros,
extra_compile_args=extra_compile_args,
extra_link_args=python_module_link_args),
]
setup(name=pkgname, setup(name=pkgname,
......
...@@ -35,12 +35,12 @@ ...@@ -35,12 +35,12 @@
#include "mr_util/infra/mav.h" #include "mr_util/infra/mav.h"
#include "mr_util/math/space_filling.h" #include "mr_util/math/space_filling.h"
using namespace std;
namespace mr { namespace mr {
namespace detail_healpix { namespace detail_healpix {
using namespace std;
namespace { namespace {
template<typename T> inline T spread(int v); template<typename T> inline T spread(int v);
......
...@@ -166,7 +166,7 @@ template<typename I> class T_Healpix_Base: public Healpix_Tables ...@@ -166,7 +166,7 @@ template<typename I> class T_Healpix_Base: public Healpix_Tables
double phi = safe_atan2(vec.y,vec.x); double phi = safe_atan2(vec.y,vec.x);
double nz = vec.z*xl; double nz = vec.z*xl;
if (std::abs(nz)>0.99) if (std::abs(nz)>0.99)
return loc2pix (nz,phi,sqrt(vec.x*vec.x+vec.y*vec.y)*xl,true); return loc2pix (nz,phi,std::sqrt(vec.x*vec.x+vec.y*vec.y)*xl,true);
else else
return loc2pix (nz,phi,0,false); return loc2pix (nz,phi,0,false);
} }
......
...@@ -33,12 +33,12 @@ ...@@ -33,12 +33,12 @@
#include "mr_util/infra/string_utils.h" #include "mr_util/infra/string_utils.h"
#include "mr_util/infra/error_handling.h" #include "mr_util/infra/error_handling.h"
using namespace std;
namespace mr { namespace mr {
namespace detail_healpix { namespace detail_healpix {
using namespace std;
const nside_dummy SET_NSIDE=nside_dummy(); const nside_dummy SET_NSIDE=nside_dummy();
Ordering_Scheme string2HealpixScheme (const string &inp) Ordering_Scheme string2HealpixScheme (const string &inp)
......
...@@ -418,6 +418,16 @@ using detail_simd::sqrt; ...@@ -418,6 +418,16 @@ using detail_simd::sqrt;
using detail_simd::any_of; using detail_simd::any_of;
using detail_simd::none_of; using detail_simd::none_of;
using detail_simd::all_of; using detail_simd::all_of;
// since we are explicitly introducing a few names that are also available in
// std::, we need to import them from std::as well, otherwise name resolution
// can fail in certain circumstances.
using std::abs;
using std::sqrt;
using std::max;
} }
#endif #endif
...@@ -40,10 +40,12 @@ ...@@ -40,10 +40,12 @@
#include "mr_util/infra/string_utils.h" #include "mr_util/infra/string_utils.h"
#include "mr_util/infra/error_handling.h" #include "mr_util/infra/error_handling.h"
using namespace std;
namespace mr { namespace mr {
namespace detail_string_utils {
using namespace std;
string trim (const string &orig) string trim (const string &orig)
{ {
string::size_type p1=orig.find_first_not_of(" \t"); string::size_type p1=orig.find_first_not_of(" \t");
...@@ -330,4 +332,4 @@ void parse_words_from_file (const string &filename, vector<string> &words) ...@@ -330,4 +332,4 @@ void parse_words_from_file (const string &filename, vector<string> &words)
} }
} }
} }}
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
namespace mr { namespace mr {
namespace detail_string_utils {
/*! \defgroup stringutilsgroup String handling helper functions */ /*! \defgroup stringutilsgroup String handling helper functions */
/*! \{ */ /*! \{ */
...@@ -113,4 +115,19 @@ void parse_words_from_file (const std::string &filename, ...@@ -113,4 +115,19 @@ void parse_words_from_file (const std::string &filename,
} }
using detail_string_utils::trim;
using detail_string_utils::intToString;
using detail_string_utils::dataToString;
using detail_string_utils::stringToData;
using detail_string_utils::parse_file;
using detail_string_utils::parse_cmdline_classic;
using detail_string_utils::parse_cmdline_equalsign;
using detail_string_utils::equal_nocase;
using detail_string_utils::tolower;
using detail_string_utils::split;
using detail_string_utils::tokenize;
using detail_string_utils::parse_words_from_file;
}
#endif #endif
...@@ -28,11 +28,11 @@ ...@@ -28,11 +28,11 @@
#include "mr_util/infra/system.h" #include "mr_util/infra/system.h"
#include "mr_util/infra/string_utils.h" #include "mr_util/infra/string_utils.h"
using namespace std;
namespace mr { namespace mr {