diff --git a/wrap/Module.cpp b/wrap/Module.cpp index 960935649..8f0b1668a 100644 --- a/wrap/Module.cpp +++ b/wrap/Module.cpp @@ -372,8 +372,12 @@ void Module::emit_cython_pyx(FileWriter& pyxFile) const { string pxdHeader = name + "_wrapper"; pyxFile.oss << "cimport numpy as np\n" "cimport " << pxdHeader << " as " << name << "\n" - "from "<< pxdHeader << " cimport shared_ptr\n" - "from eigency.core cimport *\n" + "from "<< pxdHeader << " cimport shared_ptr\n"; + // import all typedefs, e.g. from gtsam cimport Key, so we don't need to say gtsam.Key + for(const Qualified& q: Qualified::BasicTypedefs) { + pyxFile.oss << "from " << pxdHeader << " cimport " << q.cythonClass() << "\n"; + } + pyxFile.oss << "from eigency.core cimport *\n" "from libcpp cimport bool\n\n" "from libcpp.pair cimport pair\n" "from libcpp.string cimport string\n" diff --git a/wrap/Qualified.cpp b/wrap/Qualified.cpp new file mode 100644 index 000000000..947e51d54 --- /dev/null +++ b/wrap/Qualified.cpp @@ -0,0 +1,5 @@ +#include + +namespace wrap { + std::vector Qualified::BasicTypedefs; +} diff --git a/wrap/Qualified.h b/wrap/Qualified.h index dae45f6ce..62d15639e 100644 --- a/wrap/Qualified.h +++ b/wrap/Qualified.h @@ -1,6 +1,6 @@ /* ---------------------------------------------------------------------------- - * GTSAM Copyright 2010, Georgia Tech Research Corporation, + * GTSAM Copyright 2010, Georgia Tech Research Corporation, * Atlanta, Georgia 30332-0415 * All Rights Reserved * Authors: Frank Dellaert, et al. (see THANKS for the full author list) @@ -22,7 +22,7 @@ #include #include #include - + namespace wrap { /** @@ -35,6 +35,7 @@ public: std::vector namespaces_; ///< Stack of namespaces std::string name_; ///< type name + static std::vector BasicTypedefs; friend struct TypeGrammar; friend class TemplateSubstitution; @@ -128,8 +129,15 @@ public: return name() == "Vector" || name() == "Matrix"; } + bool isBasicTypedef() const { + return std::find(Qualified::BasicTypedefs.begin(), + Qualified::BasicTypedefs.end(), + *this) != Qualified::BasicTypedefs.end(); + } + bool isNonBasicType() const { - return !isString() && !isScalar() && !isEigen() && !isVoid(); + return !isString() && !isScalar() && !isEigen() && !isVoid() && + !isBasicTypedef(); } public: @@ -219,7 +227,6 @@ public: os << q.qualifiedName("::"); return os; } - }; /* ************************************************************************* */ diff --git a/wrap/TypedefPair.h b/wrap/TypedefPair.h index 4f36464a0..25fc1da9e 100644 --- a/wrap/TypedefPair.h +++ b/wrap/TypedefPair.h @@ -8,9 +8,15 @@ struct TypedefPair { std::string includeFile; TypedefPair() {} - TypedefPair(const Qualified& oldType, const Qualified& newType, + TypedefPair(const Qualified& _oldType, const Qualified& _newType, const std::string& includeFile) - : oldType(oldType), newType(newType), includeFile(includeFile) {} + : oldType(_oldType), newType(_newType), includeFile(includeFile) { + if (!oldType.isNonBasicType() && + std::find(Qualified::BasicTypedefs.begin(), + Qualified::BasicTypedefs.end(), + newType) == Qualified::BasicTypedefs.end()) + Qualified::BasicTypedefs.push_back(newType); + } void emit_cython_pxd(FileWriter& file) const { file.oss << "cdef extern from \"" << includeFile << "\" namespace \"" @@ -19,4 +25,4 @@ struct TypedefPair { << newType.cythonClass() << "\n"; } }; -} \ No newline at end of file +}