diff --git a/wrap/tests/expected-cython/geometry.pxd b/wrap/tests/expected-cython/geometry.pxd index a48182701..f2cd513e2 100644 --- a/wrap/tests/expected-cython/geometry.pxd +++ b/wrap/tests/expected-cython/geometry.pxd @@ -12,26 +12,28 @@ cdef extern from "boost/shared_ptr.hpp" namespace "boost": shared_ptr() shared_ptr(T*) T* get() + long use_count() const T& operator*() cdef shared_ptr[T] dynamic_pointer_cast[T,U](const shared_ptr[U]& r) cdef shared_ptr[T] make_shared[T](const T& r) + cdef extern from "gtsam/geometry/Point2.h" namespace "gtsam": cdef cppclass CPoint2 "gtsam::Point2": CPoint2() except + CPoint2(double x, double y) except + - void argChar "argChar"(char a) except + - void argUChar "argUChar"(unsigned char a) except + - int dim "dim"() except + - void eigenArguments "eigenArguments"(const VectorXd& v, const MatrixXd& m) except + - char returnChar "returnChar"() except + - CVectorNotEigen vectorConfusion "vectorConfusion"() except + - double x "x"() except + - double y "y"() except + + void argChar(char a) except + + void argUChar(unsigned char a) except + + int dim() except + + void eigenArguments(const VectorXd& v, const MatrixXd& m) except + + char returnChar() except + + CVectorNotEigen vectorConfusion() except + + double x() except + + double y() except + cdef class Point2: - cdef shared_ptr[CPoint2] shared_CPoint2_ + cdef shared_ptr[CPoint2] CPoint2_ @staticmethod cdef Point2 cyCreateFromShared(const shared_ptr[CPoint2]& other) @@ -45,41 +47,42 @@ cdef extern from "gtsam/geometry/Point3.h" namespace "gtsam": @staticmethod double staticFunction "staticFunction"() except + - double norm "norm"() except + + double norm() except + cdef class Point3: - cdef shared_ptr[CPoint3] shared_CPoint3_ + cdef shared_ptr[CPoint3] CPoint3_ @staticmethod cdef Point3 cyCreateFromShared(const shared_ptr[CPoint3]& other) + cdef extern from "folder/path/to/Test.h": cdef cppclass CTest "Test": CTest() except + CTest(double a, const MatrixXd& b) except + - void arg_EigenConstRef "arg_EigenConstRef"(const MatrixXd& value) except + - pair[CTest,shared_ptr[CTest]] create_MixedPtrs "create_MixedPtrs"() except + - pair[shared_ptr[CTest],shared_ptr[CTest]] create_ptrs "create_ptrs"() except + + void arg_EigenConstRef(const MatrixXd& value) except + + pair[CTest,shared_ptr[CTest]] create_MixedPtrs() except + + pair[shared_ptr[CTest],shared_ptr[CTest]] create_ptrs() except + void print_ "print"() except + - shared_ptr[CPoint2] return_Point2Ptr "return_Point2Ptr"(bool value) except + - CTest return_Test "return_Test"(shared_ptr[CTest]& value) except + - shared_ptr[CTest] return_TestPtr "return_TestPtr"(shared_ptr[CTest]& value) except + - bool return_bool "return_bool"(bool value) except + - double return_double "return_double"(double value) except + - bool return_field "return_field"(const CTest& t) except + - int return_int "return_int"(int value) except + - MatrixXd return_matrix1 "return_matrix1"(const MatrixXd& value) except + - MatrixXd return_matrix2 "return_matrix2"(const MatrixXd& value) except + - pair[VectorXd,MatrixXd] return_pair "return_pair"(const VectorXd& v, const MatrixXd& A) except + - pair[shared_ptr[CTest],shared_ptr[CTest]] return_ptrs "return_ptrs"(shared_ptr[CTest]& p1, shared_ptr[CTest]& p2) except + - size_t return_size_t "return_size_t"(size_t value) except + - string return_string "return_string"(string value) except + - VectorXd return_vector1 "return_vector1"(const VectorXd& value) except + - VectorXd return_vector2 "return_vector2"(const VectorXd& value) except + + shared_ptr[CPoint2] return_Point2Ptr(bool value) except + + CTest return_Test(shared_ptr[CTest]& value) except + + shared_ptr[CTest] return_TestPtr(shared_ptr[CTest]& value) except + + bool return_bool(bool value) except + + double return_double(double value) except + + bool return_field(const CTest& t) except + + int return_int(int value) except + + MatrixXd return_matrix1(const MatrixXd& value) except + + MatrixXd return_matrix2(const MatrixXd& value) except + + pair[VectorXd,MatrixXd] return_pair(const VectorXd& v, const MatrixXd& A) except + + pair[shared_ptr[CTest],shared_ptr[CTest]] return_ptrs(shared_ptr[CTest]& p1, shared_ptr[CTest]& p2) except + + size_t return_size_t(size_t value) except + + string return_string(string value) except + + VectorXd return_vector1(const VectorXd& value) except + + VectorXd return_vector2(const VectorXd& value) except + cdef class Test: - cdef shared_ptr[CTest] shared_CTest_ + cdef shared_ptr[CTest] CTest_ @staticmethod cdef Test cyCreateFromShared(const shared_ptr[CTest]& other) @@ -89,7 +92,7 @@ cdef extern from "folder/path/to/Test.h": pass cdef class MyBase: - cdef shared_ptr[CMyBase] shared_CMyBase_ + cdef shared_ptr[CMyBase] CMyBase_ @staticmethod cdef MyBase cyCreateFromShared(const shared_ptr[CMyBase]& other) @@ -98,24 +101,26 @@ cdef extern from "folder/path/to/Test.h": cdef cppclass CMyTemplate "MyTemplate"[T](CMyBase): CMyTemplate() except + - void accept_T "accept_T"(const T& value) except + - void accept_Tptr "accept_Tptr"(shared_ptr[T]& value) except + - pair[T,shared_ptr[T]] create_MixedPtrs "create_MixedPtrs"() except + - pair[shared_ptr[T],shared_ptr[T]] create_ptrs "create_ptrs"() except + - T return_T "return_T"(shared_ptr[T]& value) except + - shared_ptr[T] return_Tptr "return_Tptr"(shared_ptr[T]& value) except + - pair[shared_ptr[T],shared_ptr[T]] return_ptrs "return_ptrs"(shared_ptr[T]& p1, shared_ptr[T]& p2) except + + void accept_T(const T& value) except + + void accept_Tptr(shared_ptr[T]& value) except + + pair[T,shared_ptr[T]] create_MixedPtrs() except + + pair[shared_ptr[T],shared_ptr[T]] create_ptrs() except + + T return_T(shared_ptr[T]& value) except + + shared_ptr[T] return_Tptr(shared_ptr[T]& value) except + + pair[shared_ptr[T],shared_ptr[T]] return_ptrs(shared_ptr[T]& p1, shared_ptr[T]& p2) except + ARG templatedMethod[ARG](const ARG& t) except + + ctypedef CMyTemplate[CPoint2] CMyTemplatePoint2 cdef class MyTemplatePoint2(MyBase): - cdef shared_ptr[CMyTemplatePoint2] shared_CMyTemplatePoint2_ + cdef shared_ptr[CMyTemplatePoint2] CMyTemplatePoint2_ @staticmethod cdef MyTemplatePoint2 cyCreateFromShared(const shared_ptr[CMyTemplatePoint2]& other) + ctypedef CMyTemplate[MatrixXd] CMyTemplateMatrix cdef class MyTemplateMatrix(MyBase): - cdef shared_ptr[CMyTemplateMatrix] shared_CMyTemplateMatrix_ + cdef shared_ptr[CMyTemplateMatrix] CMyTemplateMatrix_ @staticmethod cdef MyTemplateMatrix cyCreateFromShared(const shared_ptr[CMyTemplateMatrix]& other) @@ -124,10 +129,11 @@ cdef extern from "folder/path/to/Test.h": cdef cppclass CMyFactor "MyFactor"[POSE,POINT]: CMyFactor(size_t key1, size_t key2, double measured, const shared_ptr[CnoiseModel_Base]& noiseModel) except + + ctypedef CMyFactor[CPose2, MatrixXd] CMyFactorPosePoint2 cdef class MyFactorPosePoint2: - cdef shared_ptr[CMyFactorPosePoint2] shared_CMyFactorPosePoint2_ + cdef shared_ptr[CMyFactorPosePoint2] CMyFactorPosePoint2_ @staticmethod cdef MyFactorPosePoint2 cyCreateFromShared(const shared_ptr[CMyFactorPosePoint2]& other) diff --git a/wrap/tests/expected-cython/geometry.pyx b/wrap/tests/expected-cython/geometry.pyx index 18aa521e7..0a4e24edf 100644 --- a/wrap/tests/expected-cython/geometry.pyx +++ b/wrap/tests/expected-cython/geometry.pyx @@ -4,6 +4,16 @@ cimport geometry from geometry cimport shared_ptr from geometry cimport dynamic_pointer_cast from geometry cimport make_shared +# C helper function that copies all arguments into a positional list. +cdef list process_args(list keywords, tuple args, dict kwargs): + cdef str keyword + cdef int n = len(args), m = len(keywords) + cdef list params = list(args) + assert len(args)+len(kwargs) == m, 'Expected {} arguments'.format(m) + try: + return params + [kwargs[keyword] for keyword in keywords[n:]] + except: + raise ValueError('Epected arguments ' + str(keywords)) from gtsam_eigency.core cimport * from libcpp cimport bool @@ -14,104 +24,83 @@ from cython.operator cimport dereference as deref cdef class Point2: def __init__(self, *args, **kwargs): - self.shared_CPoint2_ = shared_ptr[CPoint2]() + cdef list __params + self.CPoint2_ = shared_ptr[CPoint2]() if len(args)==0 and len(kwargs)==1 and kwargs.has_key('cyCreateFromShared'): return - elif self.Point2_0(*args, **kwargs): - pass - elif self.Point2_1(*args, **kwargs): - pass - else: - raise TypeError('Point2 construction failed!') - - def Point2_0(self, *args, **kwargs): - if len(args)+len(kwargs) !=0: - return False - self.shared_CPoint2_ = shared_ptr[CPoint2](new CPoint2()) - return True - - def Point2_1(self, *args, **kwargs): - if len(args)+len(kwargs) !=2: - return False - __params = kwargs.copy() - __names = ['x', 'y'] - for i in range(len(args)): - __params[__names[i]] = args[i] try: - x = (__params['x']) - y = (__params['y']) + __params = process_args([], args, kwargs) + self.CPoint2_ = shared_ptr[CPoint2](new CPoint2()) except: - return False - self.shared_CPoint2_ = shared_ptr[CPoint2](new CPoint2(x, y)) - return True - + pass + try: + __params = process_args(['x', 'y'], args, kwargs) + x = (__params[0]) + y = (__params[1]) + self.CPoint2_ = shared_ptr[CPoint2](new CPoint2(x, y)) + except: + pass + if (self.CPoint2_.use_count()==0): + raise TypeError('Point2 construction failed!') @staticmethod cdef Point2 cyCreateFromShared(const shared_ptr[CPoint2]& other): if other.get() == NULL: raise RuntimeError('Cannot create object from a nullptr!') - cdef Point2 ret = Point2(cyCreateFromShared=True) - ret.shared_CPoint2_ = other - return ret + cdef Point2 return_value = Point2(cyCreateFromShared=True) + return_value.CPoint2_ = other + return return_value + def argChar(self, char a): - self.shared_CPoint2_.get().argChar(a) + self.CPoint2_.get().argChar(a) def argUChar(self, unsigned char a): - self.shared_CPoint2_.get().argUChar(a) + self.CPoint2_.get().argUChar(a) def dim(self): - cdef int ret = self.shared_CPoint2_.get().dim() + cdef int ret = self.CPoint2_.get().dim() return ret def eigenArguments(self, np.ndarray v, np.ndarray m): v = v.astype(float, order='F', copy=False) m = m.astype(float, order='F', copy=False) - self.shared_CPoint2_.get().eigenArguments((Map[VectorXd](v)), (Map[MatrixXd](m))) + self.CPoint2_.get().eigenArguments((Map[VectorXd](v)), (Map[MatrixXd](m))) def returnChar(self): - cdef char ret = self.shared_CPoint2_.get().returnChar() + cdef char ret = self.CPoint2_.get().returnChar() return ret def vectorConfusion(self): - cdef shared_ptr[CVectorNotEigen] ret = make_shared[CVectorNotEigen](self.shared_CPoint2_.get().vectorConfusion()) + cdef shared_ptr[CVectorNotEigen] ret = make_shared[CVectorNotEigen](self.CPoint2_.get().vectorConfusion()) return VectorNotEigen.cyCreateFromShared(ret) def x(self): - cdef double ret = self.shared_CPoint2_.get().x() + cdef double ret = self.CPoint2_.get().x() return ret def y(self): - cdef double ret = self.shared_CPoint2_.get().y() + cdef double ret = self.CPoint2_.get().y() return ret cdef class Point3: def __init__(self, *args, **kwargs): - self.shared_CPoint3_ = shared_ptr[CPoint3]() + cdef list __params + self.CPoint3_ = shared_ptr[CPoint3]() if len(args)==0 and len(kwargs)==1 and kwargs.has_key('cyCreateFromShared'): return - elif self.Point3_0(*args, **kwargs): - pass - else: - raise TypeError('Point3 construction failed!') - - def Point3_0(self, *args, **kwargs): - if len(args)+len(kwargs) !=3: - return False - __params = kwargs.copy() - __names = ['x', 'y', 'z'] - for i in range(len(args)): - __params[__names[i]] = args[i] try: - x = (__params['x']) - y = (__params['y']) - z = (__params['z']) + __params = process_args(['x', 'y', 'z'], args, kwargs) + x = (__params[0]) + y = (__params[1]) + z = (__params[2]) + self.CPoint3_ = shared_ptr[CPoint3](new CPoint3(x, y, z)) except: - return False - self.shared_CPoint3_ = shared_ptr[CPoint3](new CPoint3(x, y, z)) - return True - + pass + if (self.CPoint3_.use_count()==0): + raise TypeError('Point3 construction failed!') @staticmethod cdef Point3 cyCreateFromShared(const shared_ptr[CPoint3]& other): if other.get() == NULL: raise RuntimeError('Cannot create object from a nullptr!') - cdef Point3 ret = Point3(cyCreateFromShared=True) - ret.shared_CPoint3_ = other - return ret + cdef Point3 return_value = Point3(cyCreateFromShared=True) + return_value.CPoint3_ = other + return return_value + @staticmethod def StaticFunctionRet(double z): return Point3.cyCreateFromShared(make_shared[CPoint3](CPoint3.StaticFunctionRet(z))) @@ -122,366 +111,337 @@ cdef class Point3: def norm(self): - cdef double ret = self.shared_CPoint3_.get().norm() + cdef double ret = self.CPoint3_.get().norm() return ret cdef class Test: def __init__(self, *args, **kwargs): - self.shared_CTest_ = shared_ptr[CTest]() + cdef list __params + self.CTest_ = shared_ptr[CTest]() if len(args)==0 and len(kwargs)==1 and kwargs.has_key('cyCreateFromShared'): return - elif self.Test_0(*args, **kwargs): - pass - elif self.Test_1(*args, **kwargs): - pass - else: - raise TypeError('Test construction failed!') - - def Test_0(self, *args, **kwargs): - if len(args)+len(kwargs) !=0: - return False - self.shared_CTest_ = shared_ptr[CTest](new CTest()) - return True - - def Test_1(self, *args, **kwargs): - if len(args)+len(kwargs) !=2: - return False - __params = kwargs.copy() - __names = ['a', 'b'] - for i in range(len(args)): - __params[__names[i]] = args[i] - if not isinstance(__params[__names[1]], np.ndarray) or not __params[__names[1]].ndim == 2: - return False try: - a = (__params['a']) - b = (__params['b']) + __params = process_args([], args, kwargs) + self.CTest_ = shared_ptr[CTest](new CTest()) except: - return False - b = b.astype(float, order='F', copy=False) - self.shared_CTest_ = shared_ptr[CTest](new CTest(a, (Map[MatrixXd](b)))) - return True - + pass + try: + __params = process_args(['a', 'b'], args, kwargs) + a = (__params[0]) + b = (__params[1]) + assert isinstance(b, np.ndarray) and b.ndim == 2 + b = b.astype(float, order='F', copy=False) + self.CTest_ = shared_ptr[CTest](new CTest(a, (Map[MatrixXd](b)))) + except: + pass + if (self.CTest_.use_count()==0): + raise TypeError('Test construction failed!') @staticmethod cdef Test cyCreateFromShared(const shared_ptr[CTest]& other): if other.get() == NULL: raise RuntimeError('Cannot create object from a nullptr!') - cdef Test ret = Test(cyCreateFromShared=True) - ret.shared_CTest_ = other - return ret + cdef Test return_value = Test(cyCreateFromShared=True) + return_value.CTest_ = other + return return_value + def arg_EigenConstRef(self, np.ndarray value): value = value.astype(float, order='F', copy=False) - self.shared_CTest_.get().arg_EigenConstRef((Map[MatrixXd](value))) + self.CTest_.get().arg_EigenConstRef((Map[MatrixXd](value))) def create_MixedPtrs(self): - cdef pair [CTest,shared_ptr[CTest]] ret = self.shared_CTest_.get().create_MixedPtrs() + cdef pair [CTest,shared_ptr[CTest]] ret = self.CTest_.get().create_MixedPtrs() return (Test.cyCreateFromShared(make_shared[CTest](ret.first)),Test.cyCreateFromShared(ret.second)) def create_ptrs(self): - cdef pair [shared_ptr[CTest],shared_ptr[CTest]] ret = self.shared_CTest_.get().create_ptrs() + cdef pair [shared_ptr[CTest],shared_ptr[CTest]] ret = self.CTest_.get().create_ptrs() return (Test.cyCreateFromShared(ret.first),Test.cyCreateFromShared(ret.second)) def __str__(self): strBuf = RedirectCout() self.print_('') return strBuf.str() def print_(self): - self.shared_CTest_.get().print_() + self.CTest_.get().print_() def return_Point2Ptr(self, bool value): - cdef shared_ptr[CPoint2] ret = self.shared_CTest_.get().return_Point2Ptr(value) + cdef shared_ptr[CPoint2] ret = self.CTest_.get().return_Point2Ptr(value) return Point2.cyCreateFromShared(ret) def return_Test(self, Test value): - cdef shared_ptr[CTest] ret = make_shared[CTest](self.shared_CTest_.get().return_Test(value.shared_CTest_)) + cdef shared_ptr[CTest] ret = make_shared[CTest](self.CTest_.get().return_Test(value.CTest_)) return Test.cyCreateFromShared(ret) def return_TestPtr(self, Test value): - cdef shared_ptr[CTest] ret = self.shared_CTest_.get().return_TestPtr(value.shared_CTest_) + cdef shared_ptr[CTest] ret = self.CTest_.get().return_TestPtr(value.CTest_) return Test.cyCreateFromShared(ret) def return_bool(self, bool value): - cdef bool ret = self.shared_CTest_.get().return_bool(value) + cdef bool ret = self.CTest_.get().return_bool(value) return ret def return_double(self, double value): - cdef double ret = self.shared_CTest_.get().return_double(value) + cdef double ret = self.CTest_.get().return_double(value) return ret def return_field(self, Test t): - cdef bool ret = self.shared_CTest_.get().return_field(deref(t.shared_CTest_)) + cdef bool ret = self.CTest_.get().return_field(deref(t.CTest_)) return ret def return_int(self, int value): - cdef int ret = self.shared_CTest_.get().return_int(value) + cdef int ret = self.CTest_.get().return_int(value) return ret def return_matrix1(self, np.ndarray value): value = value.astype(float, order='F', copy=False) - cdef MatrixXd ret = self.shared_CTest_.get().return_matrix1((Map[MatrixXd](value))) + cdef MatrixXd ret = self.CTest_.get().return_matrix1((Map[MatrixXd](value))) return ndarray_copy(ret) def return_matrix2(self, np.ndarray value): value = value.astype(float, order='F', copy=False) - cdef MatrixXd ret = self.shared_CTest_.get().return_matrix2((Map[MatrixXd](value))) + cdef MatrixXd ret = self.CTest_.get().return_matrix2((Map[MatrixXd](value))) return ndarray_copy(ret) def return_pair(self, np.ndarray v, np.ndarray A): v = v.astype(float, order='F', copy=False) A = A.astype(float, order='F', copy=False) - cdef pair [VectorXd,MatrixXd] ret = self.shared_CTest_.get().return_pair((Map[VectorXd](v)), (Map[MatrixXd](A))) + cdef pair [VectorXd,MatrixXd] ret = self.CTest_.get().return_pair((Map[VectorXd](v)), (Map[MatrixXd](A))) return (ndarray_copy(ret.first).squeeze(),ndarray_copy(ret.second)) def return_ptrs(self, Test p1, Test p2): - cdef pair [shared_ptr[CTest],shared_ptr[CTest]] ret = self.shared_CTest_.get().return_ptrs(p1.shared_CTest_, p2.shared_CTest_) + cdef pair [shared_ptr[CTest],shared_ptr[CTest]] ret = self.CTest_.get().return_ptrs(p1.CTest_, p2.CTest_) return (Test.cyCreateFromShared(ret.first),Test.cyCreateFromShared(ret.second)) def return_size_t(self, size_t value): - cdef size_t ret = self.shared_CTest_.get().return_size_t(value) + cdef size_t ret = self.CTest_.get().return_size_t(value) return ret def return_string(self, string value): - cdef string ret = self.shared_CTest_.get().return_string(value) + cdef string ret = self.CTest_.get().return_string(value) return ret def return_vector1(self, np.ndarray value): value = value.astype(float, order='F', copy=False) - cdef VectorXd ret = self.shared_CTest_.get().return_vector1((Map[VectorXd](value))) + cdef VectorXd ret = self.CTest_.get().return_vector1((Map[VectorXd](value))) return ndarray_copy(ret).squeeze() def return_vector2(self, np.ndarray value): value = value.astype(float, order='F', copy=False) - cdef VectorXd ret = self.shared_CTest_.get().return_vector2((Map[VectorXd](value))) + cdef VectorXd ret = self.CTest_.get().return_vector2((Map[VectorXd](value))) return ndarray_copy(ret).squeeze() cdef class MyBase: def __init__(self, *args, **kwargs): - self.shared_CMyBase_ = shared_ptr[CMyBase]() + cdef list __params + self.CMyBase_ = shared_ptr[CMyBase]() if len(args)==0 and len(kwargs)==1 and kwargs.has_key('cyCreateFromShared'): return - else: + if (self.CMyBase_.use_count()==0): raise TypeError('MyBase construction failed!') @staticmethod cdef MyBase cyCreateFromShared(const shared_ptr[CMyBase]& other): if other.get() == NULL: raise RuntimeError('Cannot create object from a nullptr!') - cdef MyBase ret = MyBase(cyCreateFromShared=True) - ret.shared_CMyBase_ = other - return ret + cdef MyBase return_value = MyBase(cyCreateFromShared=True) + return_value.CMyBase_ = other + return return_value + cdef class MyTemplatePoint2(MyBase): def __init__(self, *args, **kwargs): - self.shared_CMyTemplatePoint2_ = shared_ptr[CMyTemplatePoint2]() + cdef list __params + self.CMyTemplatePoint2_ = shared_ptr[CMyTemplatePoint2]() if len(args)==0 and len(kwargs)==1 and kwargs.has_key('cyCreateFromShared'): return - elif self.MyTemplatePoint2_0(*args, **kwargs): + try: + __params = process_args([], args, kwargs) + self.CMyTemplatePoint2_ = shared_ptr[CMyTemplatePoint2](new CMyTemplatePoint2()) + except: pass - else: + if (self.CMyTemplatePoint2_.use_count()==0): raise TypeError('MyTemplatePoint2 construction failed!') - self.shared_CMyBase_ = (self.shared_CMyTemplatePoint2_) - - def MyTemplatePoint2_0(self, *args, **kwargs): - if len(args)+len(kwargs) !=0: - return False - self.shared_CMyTemplatePoint2_ = shared_ptr[CMyTemplatePoint2](new CMyTemplatePoint2()) - return True - + self.CMyBase_ = (self.CMyTemplatePoint2_) @staticmethod cdef MyTemplatePoint2 cyCreateFromShared(const shared_ptr[CMyTemplatePoint2]& other): if other.get() == NULL: raise RuntimeError('Cannot create object from a nullptr!') - cdef MyTemplatePoint2 ret = MyTemplatePoint2(cyCreateFromShared=True) - ret.shared_CMyTemplatePoint2_ = other - ret.shared_CMyBase_ = (other) - return ret + cdef MyTemplatePoint2 return_value = MyTemplatePoint2(cyCreateFromShared=True) + return_value.CMyTemplatePoint2_ = other + return_value.CMyBase_ = (other) + return return_value + def accept_T(self, Point2 value): - self.shared_CMyTemplatePoint2_.get().accept_T(deref(value.shared_CPoint2_)) + self.CMyTemplatePoint2_.get().accept_T(deref(value.CPoint2_)) def accept_Tptr(self, Point2 value): - self.shared_CMyTemplatePoint2_.get().accept_Tptr(value.shared_CPoint2_) + self.CMyTemplatePoint2_.get().accept_Tptr(value.CPoint2_) def create_MixedPtrs(self): - cdef pair [CPoint2,shared_ptr[CPoint2]] ret = self.shared_CMyTemplatePoint2_.get().create_MixedPtrs() + cdef pair [CPoint2,shared_ptr[CPoint2]] ret = self.CMyTemplatePoint2_.get().create_MixedPtrs() return (Point2.cyCreateFromShared(make_shared[CPoint2](ret.first)),Point2.cyCreateFromShared(ret.second)) def create_ptrs(self): - cdef pair [shared_ptr[CPoint2],shared_ptr[CPoint2]] ret = self.shared_CMyTemplatePoint2_.get().create_ptrs() + cdef pair [shared_ptr[CPoint2],shared_ptr[CPoint2]] ret = self.CMyTemplatePoint2_.get().create_ptrs() return (Point2.cyCreateFromShared(ret.first),Point2.cyCreateFromShared(ret.second)) def return_T(self, Point2 value): - cdef shared_ptr[CPoint2] ret = make_shared[CPoint2](self.shared_CMyTemplatePoint2_.get().return_T(value.shared_CPoint2_)) + cdef shared_ptr[CPoint2] ret = make_shared[CPoint2](self.CMyTemplatePoint2_.get().return_T(value.CPoint2_)) return Point2.cyCreateFromShared(ret) def return_Tptr(self, Point2 value): - cdef shared_ptr[CPoint2] ret = self.shared_CMyTemplatePoint2_.get().return_Tptr(value.shared_CPoint2_) + cdef shared_ptr[CPoint2] ret = self.CMyTemplatePoint2_.get().return_Tptr(value.CPoint2_) return Point2.cyCreateFromShared(ret) def return_ptrs(self, Point2 p1, Point2 p2): - cdef pair [shared_ptr[CPoint2],shared_ptr[CPoint2]] ret = self.shared_CMyTemplatePoint2_.get().return_ptrs(p1.shared_CPoint2_, p2.shared_CPoint2_) + cdef pair [shared_ptr[CPoint2],shared_ptr[CPoint2]] ret = self.CMyTemplatePoint2_.get().return_ptrs(p1.CPoint2_, p2.CPoint2_) return (Point2.cyCreateFromShared(ret.first),Point2.cyCreateFromShared(ret.second)) def templatedMethodMatrix(self, np.ndarray t): t = t.astype(float, order='F', copy=False) - cdef MatrixXd ret = self.shared_CMyTemplatePoint2_.get().templatedMethod[MatrixXd]((Map[MatrixXd](t))) + cdef MatrixXd ret = self.CMyTemplatePoint2_.get().templatedMethod[MatrixXd]((Map[MatrixXd](t))) return ndarray_copy(ret) def templatedMethodPoint2(self, Point2 t): - cdef shared_ptr[CPoint2] ret = make_shared[CPoint2](self.shared_CMyTemplatePoint2_.get().templatedMethod[CPoint2](deref(t.shared_CPoint2_))) + cdef shared_ptr[CPoint2] ret = make_shared[CPoint2](self.CMyTemplatePoint2_.get().templatedMethod[CPoint2](deref(t.CPoint2_))) return Point2.cyCreateFromShared(ret) def templatedMethodPoint3(self, Point3 t): - cdef shared_ptr[CPoint3] ret = make_shared[CPoint3](self.shared_CMyTemplatePoint2_.get().templatedMethod[CPoint3](deref(t.shared_CPoint3_))) + cdef shared_ptr[CPoint3] ret = make_shared[CPoint3](self.CMyTemplatePoint2_.get().templatedMethod[CPoint3](deref(t.CPoint3_))) return Point3.cyCreateFromShared(ret) def templatedMethodVector(self, np.ndarray t): t = t.astype(float, order='F', copy=False) - cdef VectorXd ret = self.shared_CMyTemplatePoint2_.get().templatedMethod[VectorXd]((Map[VectorXd](t))) + cdef VectorXd ret = self.CMyTemplatePoint2_.get().templatedMethod[VectorXd]((Map[VectorXd](t))) return ndarray_copy(ret).squeeze() def dynamic_cast_MyTemplatePoint2_MyBase(MyBase parent): try: - return MyTemplatePoint2.cyCreateFromShared(dynamic_pointer_cast[CMyTemplatePoint2,CMyBase](parent.shared_CMyBase_)) + return MyTemplatePoint2.cyCreateFromShared(dynamic_pointer_cast[CMyTemplatePoint2,CMyBase](parent.CMyBase_)) except: raise TypeError('dynamic cast failed!') cdef class MyTemplateMatrix(MyBase): def __init__(self, *args, **kwargs): - self.shared_CMyTemplateMatrix_ = shared_ptr[CMyTemplateMatrix]() + cdef list __params + self.CMyTemplateMatrix_ = shared_ptr[CMyTemplateMatrix]() if len(args)==0 and len(kwargs)==1 and kwargs.has_key('cyCreateFromShared'): return - elif self.MyTemplateMatrix_0(*args, **kwargs): + try: + __params = process_args([], args, kwargs) + self.CMyTemplateMatrix_ = shared_ptr[CMyTemplateMatrix](new CMyTemplateMatrix()) + except: pass - else: + if (self.CMyTemplateMatrix_.use_count()==0): raise TypeError('MyTemplateMatrix construction failed!') - self.shared_CMyBase_ = (self.shared_CMyTemplateMatrix_) - - def MyTemplateMatrix_0(self, *args, **kwargs): - if len(args)+len(kwargs) !=0: - return False - self.shared_CMyTemplateMatrix_ = shared_ptr[CMyTemplateMatrix](new CMyTemplateMatrix()) - return True - + self.CMyBase_ = (self.CMyTemplateMatrix_) @staticmethod cdef MyTemplateMatrix cyCreateFromShared(const shared_ptr[CMyTemplateMatrix]& other): if other.get() == NULL: raise RuntimeError('Cannot create object from a nullptr!') - cdef MyTemplateMatrix ret = MyTemplateMatrix(cyCreateFromShared=True) - ret.shared_CMyTemplateMatrix_ = other - ret.shared_CMyBase_ = (other) - return ret + cdef MyTemplateMatrix return_value = MyTemplateMatrix(cyCreateFromShared=True) + return_value.CMyTemplateMatrix_ = other + return_value.CMyBase_ = (other) + return return_value + def accept_T(self, np.ndarray value): value = value.astype(float, order='F', copy=False) - self.shared_CMyTemplateMatrix_.get().accept_T((Map[MatrixXd](value))) + self.CMyTemplateMatrix_.get().accept_T((Map[MatrixXd](value))) def accept_Tptr(self, np.ndarray value): value = value.astype(float, order='F', copy=False) - self.shared_CMyTemplateMatrix_.get().accept_Tptr((Map[MatrixXd](value))) + self.CMyTemplateMatrix_.get().accept_Tptr((Map[MatrixXd](value))) def create_MixedPtrs(self): - cdef pair [MatrixXd,shared_ptr[MatrixXd]] ret = self.shared_CMyTemplateMatrix_.get().create_MixedPtrs() + cdef pair [MatrixXd,shared_ptr[MatrixXd]] ret = self.CMyTemplateMatrix_.get().create_MixedPtrs() return (ndarray_copy(ret.first),ndarray_copy(ret.second)) def create_ptrs(self): - cdef pair [shared_ptr[MatrixXd],shared_ptr[MatrixXd]] ret = self.shared_CMyTemplateMatrix_.get().create_ptrs() + cdef pair [shared_ptr[MatrixXd],shared_ptr[MatrixXd]] ret = self.CMyTemplateMatrix_.get().create_ptrs() return (ndarray_copy(ret.first),ndarray_copy(ret.second)) def return_T(self, np.ndarray value): value = value.astype(float, order='F', copy=False) - cdef MatrixXd ret = self.shared_CMyTemplateMatrix_.get().return_T((Map[MatrixXd](value))) + cdef MatrixXd ret = self.CMyTemplateMatrix_.get().return_T((Map[MatrixXd](value))) return ndarray_copy(ret) def return_Tptr(self, np.ndarray value): value = value.astype(float, order='F', copy=False) - cdef shared_ptr[MatrixXd] ret = self.shared_CMyTemplateMatrix_.get().return_Tptr((Map[MatrixXd](value))) + cdef shared_ptr[MatrixXd] ret = self.CMyTemplateMatrix_.get().return_Tptr((Map[MatrixXd](value))) return ndarray_copy(ret) def return_ptrs(self, np.ndarray p1, np.ndarray p2): p1 = p1.astype(float, order='F', copy=False) p2 = p2.astype(float, order='F', copy=False) - cdef pair [shared_ptr[MatrixXd],shared_ptr[MatrixXd]] ret = self.shared_CMyTemplateMatrix_.get().return_ptrs((Map[MatrixXd](p1)), (Map[MatrixXd](p2))) + cdef pair [shared_ptr[MatrixXd],shared_ptr[MatrixXd]] ret = self.CMyTemplateMatrix_.get().return_ptrs((Map[MatrixXd](p1)), (Map[MatrixXd](p2))) return (ndarray_copy(ret.first),ndarray_copy(ret.second)) def templatedMethodMatrix(self, np.ndarray t): t = t.astype(float, order='F', copy=False) - cdef MatrixXd ret = self.shared_CMyTemplateMatrix_.get().templatedMethod[MatrixXd]((Map[MatrixXd](t))) + cdef MatrixXd ret = self.CMyTemplateMatrix_.get().templatedMethod[MatrixXd]((Map[MatrixXd](t))) return ndarray_copy(ret) def templatedMethodPoint2(self, Point2 t): - cdef shared_ptr[CPoint2] ret = make_shared[CPoint2](self.shared_CMyTemplateMatrix_.get().templatedMethod[CPoint2](deref(t.shared_CPoint2_))) + cdef shared_ptr[CPoint2] ret = make_shared[CPoint2](self.CMyTemplateMatrix_.get().templatedMethod[CPoint2](deref(t.CPoint2_))) return Point2.cyCreateFromShared(ret) def templatedMethodPoint3(self, Point3 t): - cdef shared_ptr[CPoint3] ret = make_shared[CPoint3](self.shared_CMyTemplateMatrix_.get().templatedMethod[CPoint3](deref(t.shared_CPoint3_))) + cdef shared_ptr[CPoint3] ret = make_shared[CPoint3](self.CMyTemplateMatrix_.get().templatedMethod[CPoint3](deref(t.CPoint3_))) return Point3.cyCreateFromShared(ret) def templatedMethodVector(self, np.ndarray t): t = t.astype(float, order='F', copy=False) - cdef VectorXd ret = self.shared_CMyTemplateMatrix_.get().templatedMethod[VectorXd]((Map[VectorXd](t))) + cdef VectorXd ret = self.CMyTemplateMatrix_.get().templatedMethod[VectorXd]((Map[VectorXd](t))) return ndarray_copy(ret).squeeze() def dynamic_cast_MyTemplateMatrix_MyBase(MyBase parent): try: - return MyTemplateMatrix.cyCreateFromShared(dynamic_pointer_cast[CMyTemplateMatrix,CMyBase](parent.shared_CMyBase_)) + return MyTemplateMatrix.cyCreateFromShared(dynamic_pointer_cast[CMyTemplateMatrix,CMyBase](parent.CMyBase_)) except: raise TypeError('dynamic cast failed!') cdef class MyVector3: def __init__(self, *args, **kwargs): - self.shared_CMyVector3_ = shared_ptr[CMyVector3]() + cdef list __params + self.CMyVector3_ = shared_ptr[CMyVector3]() if len(args)==0 and len(kwargs)==1 and kwargs.has_key('cyCreateFromShared'): return - elif self.MyVector3_0(*args, **kwargs): + try: + __params = process_args([], args, kwargs) + self.CMyVector3_ = shared_ptr[CMyVector3](new CMyVector3()) + except: pass - else: + if (self.CMyVector3_.use_count()==0): raise TypeError('MyVector3 construction failed!') - def MyVector3_0(self, *args, **kwargs): - if len(args)+len(kwargs) !=0: - return False - self.shared_CMyVector3_ = shared_ptr[CMyVector3](new CMyVector3()) - return True - - @staticmethod cdef MyVector3 cyCreateFromShared(const shared_ptr[CMyVector3]& other): if other.get() == NULL: raise RuntimeError('Cannot create object from a nullptr!') - cdef MyVector3 ret = MyVector3(cyCreateFromShared=True) - ret.shared_CMyVector3_ = other - return ret + cdef MyVector3 return_value = MyVector3(cyCreateFromShared=True) + return_value.CMyVector3_ = other + return return_value + cdef class MyVector12: def __init__(self, *args, **kwargs): - self.shared_CMyVector12_ = shared_ptr[CMyVector12]() + cdef list __params + self.CMyVector12_ = shared_ptr[CMyVector12]() if len(args)==0 and len(kwargs)==1 and kwargs.has_key('cyCreateFromShared'): return - elif self.MyVector12_0(*args, **kwargs): + try: + __params = process_args([], args, kwargs) + self.CMyVector12_ = shared_ptr[CMyVector12](new CMyVector12()) + except: pass - else: + if (self.CMyVector12_.use_count()==0): raise TypeError('MyVector12 construction failed!') - def MyVector12_0(self, *args, **kwargs): - if len(args)+len(kwargs) !=0: - return False - self.shared_CMyVector12_ = shared_ptr[CMyVector12](new CMyVector12()) - return True - - @staticmethod cdef MyVector12 cyCreateFromShared(const shared_ptr[CMyVector12]& other): if other.get() == NULL: raise RuntimeError('Cannot create object from a nullptr!') - cdef MyVector12 ret = MyVector12(cyCreateFromShared=True) - ret.shared_CMyVector12_ = other - return ret + cdef MyVector12 return_value = MyVector12(cyCreateFromShared=True) + return_value.CMyVector12_ = other + return return_value + cdef class MyFactorPosePoint2: def __init__(self, *args, **kwargs): - self.shared_CMyFactorPosePoint2_ = shared_ptr[CMyFactorPosePoint2]() + cdef list __params + self.CMyFactorPosePoint2_ = shared_ptr[CMyFactorPosePoint2]() if len(args)==0 and len(kwargs)==1 and kwargs.has_key('cyCreateFromShared'): return - elif self.MyFactorPosePoint2_0(*args, **kwargs): - pass - else: - raise TypeError('MyFactorPosePoint2 construction failed!') - - def MyFactorPosePoint2_0(self, *args, **kwargs): - if len(args)+len(kwargs) !=4: - return False - __params = kwargs.copy() - __names = ['key1', 'key2', 'measured', 'noiseModel'] - for i in range(len(args)): - __params[__names[i]] = args[i] - if not isinstance(__params[__names[3]], noiseModel_Base): - return False try: - key1 = (__params['key1']) - key2 = (__params['key2']) - measured = (__params['measured']) - noiseModel = (__params['noiseModel']) + __params = process_args(['key1', 'key2', 'measured', 'noiseModel'], args, kwargs) + key1 = (__params[0]) + key2 = (__params[1]) + measured = (__params[2]) + noiseModel = (__params[3]) + assert isinstance(noiseModel, noiseModel_Base) + self.CMyFactorPosePoint2_ = shared_ptr[CMyFactorPosePoint2](new CMyFactorPosePoint2(key1, key2, measured, noiseModel.CnoiseModel_Base_)) except: - return False - self.shared_CMyFactorPosePoint2_ = shared_ptr[CMyFactorPosePoint2](new CMyFactorPosePoint2(key1, key2, measured, noiseModel.shared_CnoiseModel_Base_)) - return True - + pass + if (self.CMyFactorPosePoint2_.use_count()==0): + raise TypeError('MyFactorPosePoint2 construction failed!') @staticmethod cdef MyFactorPosePoint2 cyCreateFromShared(const shared_ptr[CMyFactorPosePoint2]& other): if other.get() == NULL: raise RuntimeError('Cannot create object from a nullptr!') - cdef MyFactorPosePoint2 ret = MyFactorPosePoint2(cyCreateFromShared=True) - ret.shared_CMyFactorPosePoint2_ = other - return ret + cdef MyFactorPosePoint2 return_value = MyFactorPosePoint2(cyCreateFromShared=True) + return_value.CMyFactorPosePoint2_ = other + return return_value + @@ -489,37 +449,33 @@ def aGlobalFunction(): cdef VectorXd ret = pxd_aGlobalFunction() return ndarray_copy(ret).squeeze() def overloadedGlobalFunction(*args, **kwargs): - success, results = overloadedGlobalFunction_0(*args, **kwargs) + success, results = overloadedGlobalFunction_0(args, kwargs) if success: return results - success, results = overloadedGlobalFunction_1(*args, **kwargs) + success, results = overloadedGlobalFunction_1(args, kwargs) if success: return results raise TypeError('Could not find the correct overload') -def overloadedGlobalFunction_0(*args, **kwargs): - if len(args)+len(kwargs) !=1: - return False, None - __params = kwargs.copy() - __names = ['a'] - for i in range(len(args)): - __params[__names[i]] = args[i] +def overloadedGlobalFunction_0(args, kwargs): + cdef list __params + cdef VectorXd return_value try: - a = (__params['a']) + __params = process_args(['a'], args, kwargs) + a = (__params[0]) + return_value = pxd_overloadedGlobalFunction(a) + return True, ndarray_copy(return_value).squeeze() except: return False, None - cdef VectorXd ret = pxd_overloadedGlobalFunction(a) - return True, ndarray_copy(ret).squeeze() -def overloadedGlobalFunction_1(*args, **kwargs): - if len(args)+len(kwargs) !=2: - return False, None - __params = kwargs.copy() - __names = ['a', 'b'] - for i in range(len(args)): - __params[__names[i]] = args[i] + +def overloadedGlobalFunction_1(args, kwargs): + cdef list __params + cdef VectorXd return_value try: - a = (__params['a']) - b = (__params['b']) + __params = process_args(['a', 'b'], args, kwargs) + a = (__params[0]) + b = (__params[1]) + return_value = pxd_overloadedGlobalFunction(a, b) + return True, ndarray_copy(return_value).squeeze() except: return False, None - cdef VectorXd ret = pxd_overloadedGlobalFunction(a, b) - return True, ndarray_copy(ret).squeeze() +