diff --git a/CMakeLists.txt b/CMakeLists.txt index 263e47321..a99f36027 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -348,7 +348,7 @@ endif() # Python wrap if (GTSAM_BUILD_PYTHON) include(GtsamPythonWrap) - wrap_and_install_python(gtsampy.h "${GTSAM_ADDITIONAL_LIBRARIES}" "") + # wrap_and_install_python(gtsampy.h "${GTSAM_ADDITIONAL_LIBRARIES}" "") endif() # Build gtsam_unstable diff --git a/python/gtsam/__init__.py b/python/gtsam/__init__.py index f1b07905b..2f9356acc 100644 --- a/python/gtsam/__init__.py +++ b/python/gtsam/__init__.py @@ -1 +1 @@ -from libgtsam_python import * +import noiseModel diff --git a/python/gtsam/noiseModel/.gitignore b/python/gtsam/noiseModel/.gitignore new file mode 100644 index 000000000..e054d5cfe --- /dev/null +++ b/python/gtsam/noiseModel/.gitignore @@ -0,0 +1 @@ +/libnoiseModel_python.so diff --git a/python/gtsam/noiseModel/__init__.py b/python/gtsam/noiseModel/__init__.py new file mode 100644 index 000000000..492937407 --- /dev/null +++ b/python/gtsam/noiseModel/__init__.py @@ -0,0 +1 @@ +from libnoiseModel_python import * \ No newline at end of file diff --git a/python/handwritten/noiseModel_python.cpp b/python/handwritten/noiseModel_python.cpp new file mode 100644 index 000000000..e23a5b630 --- /dev/null +++ b/python/handwritten/noiseModel_python.cpp @@ -0,0 +1,111 @@ +#include + +#include + +#include + +using namespace boost::python; +using namespace gtsam; +using namespace gtsam::noiseModel; + +// Wrap around pure virtual class Base +// See: http://www.boost.org/doc/libs/1_59_0/libs/python/doc/tutorial/doc/html/python/exposing.html#python.class_virtual_functions +struct BaseWrap : Base, wrapper +{ + void print (const std::string & name="") const { + this->get_override("print")(); + } + bool equals (const Base & expected, double tol=1e-9) const { + return this->get_override("equals")(); + } + Vector whiten (const Vector & v) const { + return this->get_override("whiten")(); + } + Matrix Whiten (const Matrix & v) const { + return this->get_override("Whiten")(); + } + Vector unwhiten (const Vector & v) const { + return this->get_override("unwhiten")(); + } + double distance (const Vector & v) const { + return this->get_override("distance")(); + } + void WhitenSystem (std::vector< Matrix > &A, Vector &b) const { + this->get_override("WhitenSystem")(); + } + void WhitenSystem (Matrix &A, Vector &b) const { + this->get_override("WhitenSystem")(); + } + void WhitenSystem (Matrix &A1, Matrix &A2, Vector &b) const { + this->get_override("WhitenSystem")(); + } + void WhitenSystem (Matrix &A1, Matrix &A2, Matrix &A3, Vector &b) const { + this->get_override("WhitenSystem")(); + } + +}; + +BOOST_PYTHON_MODULE(libnoiseModel_python) +{ + +// NOTE: Don't know if it's really necessary to register the matrices convertion here. +import_array(); +NumpyEigenConverter::register_converter(); +NumpyEigenConverter::register_converter(); +NumpyEigenConverter::register_converter(); +NumpyEigenConverter::register_converter(); +NumpyEigenConverter::register_converter(); +NumpyEigenConverter::register_converter(); +NumpyEigenConverter::register_converter(); +NumpyEigenConverter::register_converter(); +NumpyEigenConverter::register_converter(); +NumpyEigenConverter::register_converter(); +NumpyEigenConverter::register_converter(); + +NumpyEigenConverter::register_converter(); +NumpyEigenConverter::register_converter(); +NumpyEigenConverter::register_converter(); +NumpyEigenConverter::register_converter(); +NumpyEigenConverter::register_converter(); +NumpyEigenConverter::register_converter(); +NumpyEigenConverter::register_converter(); +NumpyEigenConverter::register_converter(); +NumpyEigenConverter::register_converter(); + +class_("Base") + .def("print", pure_virtual(&Base::print)) +; + +class_, bases >("Gaussian", no_init) + .def("SqrtInformation",&Gaussian::SqrtInformation) + .staticmethod("SqrtInformation") + .def("Information",&Gaussian::Information) + .staticmethod("Information") + .def("Covariance",&Gaussian::Covariance) + .staticmethod("Covariance") +; + +class_ >("Diagonal", no_init) + .def("Sigmas",&Diagonal::Sigmas) + .staticmethod("Sigmas") + .def("Variances",&Diagonal::Variances) + .staticmethod("Variances") + .def("Precisions",&Diagonal::Precisions) + .staticmethod("Precisions") +; + +class_ >("Isotropic", no_init) + .def("Sigma",&Isotropic::Sigma) + .staticmethod("Sigma") + .def("Variance",&Isotropic::Variance) + .staticmethod("Variance") + .def("Precision",&Isotropic::Precision) + .staticmethod("Precision") +; + +class_ >("Unit", no_init) + .def("Create",&Unit::Create) + .staticmethod("Create") +; + +} \ No newline at end of file