Merging 'master' into 'wrap'

release/4.3a0
Varun Agrawal 2021-12-17 15:55:42 -05:00
commit 0344b725d7
12 changed files with 58 additions and 57 deletions

View File

@ -66,7 +66,7 @@ class WrapperTemplate:
mxDestroyArray(registry);
mxArray *newAlreadyCreated = mxCreateNumericMatrix(0, 0, mxINT8_CLASS, mxREAL);
if(mexPutVariable("global", "gtsam_geometry_rttiRegistry_created", newAlreadyCreated) != 0) {{
if(mexPutVariable("global", "gtsam_{module_name}_rttiRegistry_created", newAlreadyCreated) != 0) {{
mexErrMsgTxt("gtsam wrap: Error indexing RTTI types, inheritance will not work correctly");
}}
mxDestroyArray(newAlreadyCreated);

View File

@ -5,16 +5,16 @@ that Matlab's MEX compiler can use.
# pylint: disable=too-many-lines, no-self-use, too-many-arguments, too-many-branches, too-many-statements
import copy
import os
import os.path as osp
import textwrap
from functools import partial, reduce
from typing import Dict, Iterable, List, Union
import copy
import gtwrap.interface_parser as parser
from gtwrap.interface_parser.function import ArgumentList
import gtwrap.template_instantiator as instantiator
from gtwrap.interface_parser.function import ArgumentList
from gtwrap.matlab_wrapper.mixins import CheckMixin, FormatMixin
from gtwrap.matlab_wrapper.templates import WrapperTemplate
@ -1269,9 +1269,9 @@ class MatlabWrapper(CheckMixin, FormatMixin):
Collector_{class_name}::iterator item;
item = collector_{class_name}.find(self);
if(item != collector_{class_name}.end()) {{
delete self;
collector_{class_name}.erase(item);
}}
delete self;
''').format(class_name_sep=class_name_separated,
class_name=class_name),
prefix=' ')

View File

@ -92,9 +92,20 @@ class PybindWrapper:
prefix,
suffix,
method_suffix=""):
"""
Wrap the `method` for the class specified by `cpp_class`.
Args:
method: The method to wrap.
cpp_class: The C++ name of the class to which the method belongs.
prefix: Prefix to add to the wrapped method when writing to the cpp file.
suffix: Suffix to add to the wrapped method when writing to the cpp file.
method_suffix: A string to append to the wrapped method name.
"""
py_method = method.name + method_suffix
cpp_method = method.to_cpp()
# Special handling for the serialize/serializable method
if cpp_method in ["serialize", "serializable"]:
if not cpp_class in self._serializing_classes:
self._serializing_classes.append(cpp_class)
@ -104,16 +115,12 @@ class PybindWrapper:
'.def("deserialize", []({class_inst} self, string serialized)' \
'{{ gtsam::deserialize(serialized, *self); }}, py::arg("serialized"))' \
.format(class_inst=cpp_class + '*')
return serialize_method + deserialize_method
if cpp_method == "pickle":
if not cpp_class in self._serializing_classes:
raise ValueError(
"Cannot pickle a class which is not serializable")
# Since this class supports serialization, we also add the pickle method.
pickle_method = self.method_indent + \
".def(py::pickle({indent} [](const {cpp_class} &a){{ /* __getstate__: Returns a string that encodes the state of the object */ return py::make_tuple(gtsam::serialize(a)); }},{indent} [](py::tuple t){{ /* __setstate__ */ {cpp_class} obj; gtsam::deserialize(t[0].cast<std::string>(), obj); return obj; }}))"
return pickle_method.format(cpp_class=cpp_class,
indent=self.method_indent)
return serialize_method + deserialize_method + \
pickle_method.format(cpp_class=cpp_class, indent=self.method_indent)
# Add underscore to disambiguate if the method name matches a python keyword
if py_method in self.python_keywords:

View File

@ -145,7 +145,7 @@ void _class_RTTIRegister() {
mxDestroyArray(registry);
mxArray *newAlreadyCreated = mxCreateNumericMatrix(0, 0, mxINT8_CLASS, mxREAL);
if(mexPutVariable("global", "gtsam_geometry_rttiRegistry_created", newAlreadyCreated) != 0) {
if(mexPutVariable("global", "gtsam_class_rttiRegistry_created", newAlreadyCreated) != 0) {
mexErrMsgTxt("gtsam wrap: Error indexing RTTI types, inheritance will not work correctly");
}
mxDestroyArray(newAlreadyCreated);
@ -180,9 +180,9 @@ void FunRange_deconstructor_2(int nargout, mxArray *out[], int nargin, const mxA
Collector_FunRange::iterator item;
item = collector_FunRange.find(self);
if(item != collector_FunRange.end()) {
delete self;
collector_FunRange.erase(item);
}
delete self;
}
void FunRange_range_3(int nargout, mxArray *out[], int nargin, const mxArray *in[])
@ -216,9 +216,9 @@ void FunDouble_deconstructor_6(int nargout, mxArray *out[], int nargin, const mx
Collector_FunDouble::iterator item;
item = collector_FunDouble.find(self);
if(item != collector_FunDouble.end()) {
delete self;
collector_FunDouble.erase(item);
}
delete self;
}
void FunDouble_multiTemplatedMethod_7(int nargout, mxArray *out[], int nargin, const mxArray *in[])
@ -301,9 +301,9 @@ void Test_deconstructor_15(int nargout, mxArray *out[], int nargin, const mxArra
Collector_Test::iterator item;
item = collector_Test.find(self);
if(item != collector_Test.end()) {
delete self;
collector_Test.erase(item);
}
delete self;
}
void Test_arg_EigenConstRef_16(int nargout, mxArray *out[], int nargin, const mxArray *in[])
@ -544,9 +544,9 @@ void PrimitiveRefDouble_deconstructor_43(int nargout, mxArray *out[], int nargin
Collector_PrimitiveRefDouble::iterator item;
item = collector_PrimitiveRefDouble.find(self);
if(item != collector_PrimitiveRefDouble.end()) {
delete self;
collector_PrimitiveRefDouble.erase(item);
}
delete self;
}
void PrimitiveRefDouble_Brutal_44(int nargout, mxArray *out[], int nargin, const mxArray *in[])
@ -584,9 +584,9 @@ void MyVector3_deconstructor_47(int nargout, mxArray *out[], int nargin, const m
Collector_MyVector3::iterator item;
item = collector_MyVector3.find(self);
if(item != collector_MyVector3.end()) {
delete self;
collector_MyVector3.erase(item);
}
delete self;
}
void MyVector12_collectorInsertAndMakeBase_48(int nargout, mxArray *out[], int nargin, const mxArray *in[])
@ -617,9 +617,9 @@ void MyVector12_deconstructor_50(int nargout, mxArray *out[], int nargin, const
Collector_MyVector12::iterator item;
item = collector_MyVector12.find(self);
if(item != collector_MyVector12.end()) {
delete self;
collector_MyVector12.erase(item);
}
delete self;
}
void MultipleTemplatesIntDouble_collectorInsertAndMakeBase_51(int nargout, mxArray *out[], int nargin, const mxArray *in[])
@ -639,9 +639,9 @@ void MultipleTemplatesIntDouble_deconstructor_52(int nargout, mxArray *out[], in
Collector_MultipleTemplatesIntDouble::iterator item;
item = collector_MultipleTemplatesIntDouble.find(self);
if(item != collector_MultipleTemplatesIntDouble.end()) {
delete self;
collector_MultipleTemplatesIntDouble.erase(item);
}
delete self;
}
void MultipleTemplatesIntFloat_collectorInsertAndMakeBase_53(int nargout, mxArray *out[], int nargin, const mxArray *in[])
@ -661,9 +661,9 @@ void MultipleTemplatesIntFloat_deconstructor_54(int nargout, mxArray *out[], int
Collector_MultipleTemplatesIntFloat::iterator item;
item = collector_MultipleTemplatesIntFloat.find(self);
if(item != collector_MultipleTemplatesIntFloat.end()) {
delete self;
collector_MultipleTemplatesIntFloat.erase(item);
}
delete self;
}
void ForwardKinematics_collectorInsertAndMakeBase_55(int nargout, mxArray *out[], int nargin, const mxArray *in[])
@ -714,9 +714,9 @@ void ForwardKinematics_deconstructor_58(int nargout, mxArray *out[], int nargin,
Collector_ForwardKinematics::iterator item;
item = collector_ForwardKinematics.find(self);
if(item != collector_ForwardKinematics.end()) {
delete self;
collector_ForwardKinematics.erase(item);
}
delete self;
}
void TemplatedConstructor_collectorInsertAndMakeBase_59(int nargout, mxArray *out[], int nargin, const mxArray *in[])
@ -783,9 +783,9 @@ void TemplatedConstructor_deconstructor_64(int nargout, mxArray *out[], int narg
Collector_TemplatedConstructor::iterator item;
item = collector_TemplatedConstructor.find(self);
if(item != collector_TemplatedConstructor.end()) {
delete self;
collector_TemplatedConstructor.erase(item);
}
delete self;
}
void MyFactorPosePoint2_collectorInsertAndMakeBase_65(int nargout, mxArray *out[], int nargin, const mxArray *in[])
@ -820,9 +820,9 @@ void MyFactorPosePoint2_deconstructor_67(int nargout, mxArray *out[], int nargin
Collector_MyFactorPosePoint2::iterator item;
item = collector_MyFactorPosePoint2.find(self);
if(item != collector_MyFactorPosePoint2.end()) {
delete self;
collector_MyFactorPosePoint2.erase(item);
}
delete self;
}
void MyFactorPosePoint2_print_68(int nargout, mxArray *out[], int nargin, const mxArray *in[])

View File

@ -51,7 +51,7 @@ void _functions_RTTIRegister() {
mxDestroyArray(registry);
mxArray *newAlreadyCreated = mxCreateNumericMatrix(0, 0, mxINT8_CLASS, mxREAL);
if(mexPutVariable("global", "gtsam_geometry_rttiRegistry_created", newAlreadyCreated) != 0) {
if(mexPutVariable("global", "gtsam_functions_rttiRegistry_created", newAlreadyCreated) != 0) {
mexErrMsgTxt("gtsam wrap: Error indexing RTTI types, inheritance will not work correctly");
}
mxDestroyArray(newAlreadyCreated);

View File

@ -118,9 +118,9 @@ void gtsamPoint2_deconstructor_3(int nargout, mxArray *out[], int nargin, const
Collector_gtsamPoint2::iterator item;
item = collector_gtsamPoint2.find(self);
if(item != collector_gtsamPoint2.end()) {
delete self;
collector_gtsamPoint2.erase(item);
}
delete self;
}
void gtsamPoint2_argChar_4(int nargout, mxArray *out[], int nargin, const mxArray *in[])
@ -262,9 +262,9 @@ void gtsamPoint3_deconstructor_20(int nargout, mxArray *out[], int nargin, const
Collector_gtsamPoint3::iterator item;
item = collector_gtsamPoint3.find(self);
if(item != collector_gtsamPoint3.end()) {
delete self;
collector_gtsamPoint3.erase(item);
}
delete self;
}
void gtsamPoint3_norm_21(int nargout, mxArray *out[], int nargin, const mxArray *in[])

View File

@ -88,7 +88,7 @@ void _inheritance_RTTIRegister() {
mxDestroyArray(registry);
mxArray *newAlreadyCreated = mxCreateNumericMatrix(0, 0, mxINT8_CLASS, mxREAL);
if(mexPutVariable("global", "gtsam_geometry_rttiRegistry_created", newAlreadyCreated) != 0) {
if(mexPutVariable("global", "gtsam_inheritance_rttiRegistry_created", newAlreadyCreated) != 0) {
mexErrMsgTxt("gtsam wrap: Error indexing RTTI types, inheritance will not work correctly");
}
mxDestroyArray(newAlreadyCreated);
@ -121,9 +121,9 @@ void MyBase_deconstructor_2(int nargout, mxArray *out[], int nargin, const mxArr
Collector_MyBase::iterator item;
item = collector_MyBase.find(self);
if(item != collector_MyBase.end()) {
delete self;
collector_MyBase.erase(item);
}
delete self;
}
void MyTemplatePoint2_collectorInsertAndMakeBase_3(int nargout, mxArray *out[], int nargin, const mxArray *in[])
@ -171,9 +171,9 @@ void MyTemplatePoint2_deconstructor_6(int nargout, mxArray *out[], int nargin, c
Collector_MyTemplatePoint2::iterator item;
item = collector_MyTemplatePoint2.find(self);
if(item != collector_MyTemplatePoint2.end()) {
delete self;
collector_MyTemplatePoint2.erase(item);
}
delete self;
}
void MyTemplatePoint2_accept_T_7(int nargout, mxArray *out[], int nargin, const mxArray *in[])
@ -339,9 +339,9 @@ void MyTemplateMatrix_deconstructor_22(int nargout, mxArray *out[], int nargin,
Collector_MyTemplateMatrix::iterator item;
item = collector_MyTemplateMatrix.find(self);
if(item != collector_MyTemplateMatrix.end()) {
delete self;
collector_MyTemplateMatrix.erase(item);
}
delete self;
}
void MyTemplateMatrix_accept_T_23(int nargout, mxArray *out[], int nargin, const mxArray *in[])
@ -492,9 +492,9 @@ void ForwardKinematicsFactor_deconstructor_37(int nargout, mxArray *out[], int n
Collector_ForwardKinematicsFactor::iterator item;
item = collector_ForwardKinematicsFactor.find(self);
if(item != collector_ForwardKinematicsFactor.end()) {
delete self;
collector_ForwardKinematicsFactor.erase(item);
}
delete self;
}

View File

@ -75,7 +75,7 @@ void _multiple_files_RTTIRegister() {
mxDestroyArray(registry);
mxArray *newAlreadyCreated = mxCreateNumericMatrix(0, 0, mxINT8_CLASS, mxREAL);
if(mexPutVariable("global", "gtsam_geometry_rttiRegistry_created", newAlreadyCreated) != 0) {
if(mexPutVariable("global", "gtsam_multiple_files_rttiRegistry_created", newAlreadyCreated) != 0) {
mexErrMsgTxt("gtsam wrap: Error indexing RTTI types, inheritance will not work correctly");
}
mxDestroyArray(newAlreadyCreated);
@ -110,9 +110,9 @@ void gtsamClass1_deconstructor_2(int nargout, mxArray *out[], int nargin, const
Collector_gtsamClass1::iterator item;
item = collector_gtsamClass1.find(self);
if(item != collector_gtsamClass1.end()) {
delete self;
collector_gtsamClass1.erase(item);
}
delete self;
}
void gtsamClass2_collectorInsertAndMakeBase_3(int nargout, mxArray *out[], int nargin, const mxArray *in[])
@ -143,9 +143,9 @@ void gtsamClass2_deconstructor_5(int nargout, mxArray *out[], int nargin, const
Collector_gtsamClass2::iterator item;
item = collector_gtsamClass2.find(self);
if(item != collector_gtsamClass2.end()) {
delete self;
collector_gtsamClass2.erase(item);
}
delete self;
}
void gtsamClassA_collectorInsertAndMakeBase_6(int nargout, mxArray *out[], int nargin, const mxArray *in[])
@ -176,9 +176,9 @@ void gtsamClassA_deconstructor_8(int nargout, mxArray *out[], int nargin, const
Collector_gtsamClassA::iterator item;
item = collector_gtsamClassA.find(self);
if(item != collector_gtsamClassA.end()) {
delete self;
collector_gtsamClassA.erase(item);
}
delete self;
}

View File

@ -112,7 +112,7 @@ void _namespaces_RTTIRegister() {
mxDestroyArray(registry);
mxArray *newAlreadyCreated = mxCreateNumericMatrix(0, 0, mxINT8_CLASS, mxREAL);
if(mexPutVariable("global", "gtsam_geometry_rttiRegistry_created", newAlreadyCreated) != 0) {
if(mexPutVariable("global", "gtsam_namespaces_rttiRegistry_created", newAlreadyCreated) != 0) {
mexErrMsgTxt("gtsam wrap: Error indexing RTTI types, inheritance will not work correctly");
}
mxDestroyArray(newAlreadyCreated);
@ -147,9 +147,9 @@ void ns1ClassA_deconstructor_2(int nargout, mxArray *out[], int nargin, const mx
Collector_ns1ClassA::iterator item;
item = collector_ns1ClassA.find(self);
if(item != collector_ns1ClassA.end()) {
delete self;
collector_ns1ClassA.erase(item);
}
delete self;
}
void ns1ClassB_collectorInsertAndMakeBase_3(int nargout, mxArray *out[], int nargin, const mxArray *in[])
@ -180,9 +180,9 @@ void ns1ClassB_deconstructor_5(int nargout, mxArray *out[], int nargin, const mx
Collector_ns1ClassB::iterator item;
item = collector_ns1ClassB.find(self);
if(item != collector_ns1ClassB.end()) {
delete self;
collector_ns1ClassB.erase(item);
}
delete self;
}
void aGlobalFunction_6(int nargout, mxArray *out[], int nargin, const mxArray *in[])
@ -218,9 +218,9 @@ void ns2ClassA_deconstructor_9(int nargout, mxArray *out[], int nargin, const mx
Collector_ns2ClassA::iterator item;
item = collector_ns2ClassA.find(self);
if(item != collector_ns2ClassA.end()) {
delete self;
collector_ns2ClassA.erase(item);
}
delete self;
}
void ns2ClassA_memberFunction_10(int nargout, mxArray *out[], int nargin, const mxArray *in[])
@ -280,9 +280,9 @@ void ns2ns3ClassB_deconstructor_16(int nargout, mxArray *out[], int nargin, cons
Collector_ns2ns3ClassB::iterator item;
item = collector_ns2ns3ClassB.find(self);
if(item != collector_ns2ns3ClassB.end()) {
delete self;
collector_ns2ns3ClassB.erase(item);
}
delete self;
}
void ns2ClassC_collectorInsertAndMakeBase_17(int nargout, mxArray *out[], int nargin, const mxArray *in[])
@ -313,9 +313,9 @@ void ns2ClassC_deconstructor_19(int nargout, mxArray *out[], int nargin, const m
Collector_ns2ClassC::iterator item;
item = collector_ns2ClassC.find(self);
if(item != collector_ns2ClassC.end()) {
delete self;
collector_ns2ClassC.erase(item);
}
delete self;
}
void aGlobalFunction_20(int nargout, mxArray *out[], int nargin, const mxArray *in[])
@ -364,9 +364,9 @@ void ClassD_deconstructor_25(int nargout, mxArray *out[], int nargin, const mxAr
Collector_ClassD::iterator item;
item = collector_ClassD.find(self);
if(item != collector_ClassD.end()) {
delete self;
collector_ClassD.erase(item);
}
delete self;
}
void gtsamValues_collectorInsertAndMakeBase_26(int nargout, mxArray *out[], int nargin, const mxArray *in[])
@ -409,9 +409,9 @@ void gtsamValues_deconstructor_29(int nargout, mxArray *out[], int nargin, const
Collector_gtsamValues::iterator item;
item = collector_gtsamValues.find(self);
if(item != collector_gtsamValues.end()) {
delete self;
collector_gtsamValues.erase(item);
}
delete self;
}
void gtsamValues_insert_30(int nargout, mxArray *out[], int nargin, const mxArray *in[])

View File

@ -84,7 +84,7 @@ void _special_cases_RTTIRegister() {
mxDestroyArray(registry);
mxArray *newAlreadyCreated = mxCreateNumericMatrix(0, 0, mxINT8_CLASS, mxREAL);
if(mexPutVariable("global", "gtsam_geometry_rttiRegistry_created", newAlreadyCreated) != 0) {
if(mexPutVariable("global", "gtsam_special_cases_rttiRegistry_created", newAlreadyCreated) != 0) {
mexErrMsgTxt("gtsam wrap: Error indexing RTTI types, inheritance will not work correctly");
}
mxDestroyArray(newAlreadyCreated);
@ -108,9 +108,9 @@ void gtsamNonlinearFactorGraph_deconstructor_1(int nargout, mxArray *out[], int
Collector_gtsamNonlinearFactorGraph::iterator item;
item = collector_gtsamNonlinearFactorGraph.find(self);
if(item != collector_gtsamNonlinearFactorGraph.end()) {
delete self;
collector_gtsamNonlinearFactorGraph.erase(item);
}
delete self;
}
void gtsamNonlinearFactorGraph_addPrior_2(int nargout, mxArray *out[], int nargin, const mxArray *in[])
@ -140,9 +140,9 @@ void gtsamSfmTrack_deconstructor_4(int nargout, mxArray *out[], int nargin, cons
Collector_gtsamSfmTrack::iterator item;
item = collector_gtsamSfmTrack.find(self);
if(item != collector_gtsamSfmTrack.end()) {
delete self;
collector_gtsamSfmTrack.erase(item);
}
delete self;
}
void gtsamPinholeCameraCal3Bundler_collectorInsertAndMakeBase_5(int nargout, mxArray *out[], int nargin, const mxArray *in[])
@ -162,9 +162,9 @@ void gtsamPinholeCameraCal3Bundler_deconstructor_6(int nargout, mxArray *out[],
Collector_gtsamPinholeCameraCal3Bundler::iterator item;
item = collector_gtsamPinholeCameraCal3Bundler.find(self);
if(item != collector_gtsamPinholeCameraCal3Bundler.end()) {
delete self;
collector_gtsamPinholeCameraCal3Bundler.erase(item);
}
delete self;
}
void gtsamGeneralSFMFactorCal3Bundler_collectorInsertAndMakeBase_7(int nargout, mxArray *out[], int nargin, const mxArray *in[])
@ -184,9 +184,9 @@ void gtsamGeneralSFMFactorCal3Bundler_deconstructor_8(int nargout, mxArray *out[
Collector_gtsamGeneralSFMFactorCal3Bundler::iterator item;
item = collector_gtsamGeneralSFMFactorCal3Bundler.find(self);
if(item != collector_gtsamGeneralSFMFactorCal3Bundler.end()) {
delete self;
collector_gtsamGeneralSFMFactorCal3Bundler.erase(item);
}
delete self;
}

View File

@ -67,7 +67,7 @@ void _template_RTTIRegister() {
mxDestroyArray(registry);
mxArray *newAlreadyCreated = mxCreateNumericMatrix(0, 0, mxINT8_CLASS, mxREAL);
if(mexPutVariable("global", "gtsam_geometry_rttiRegistry_created", newAlreadyCreated) != 0) {
if(mexPutVariable("global", "gtsam_template_rttiRegistry_created", newAlreadyCreated) != 0) {
mexErrMsgTxt("gtsam wrap: Error indexing RTTI types, inheritance will not work correctly");
}
mxDestroyArray(newAlreadyCreated);
@ -138,9 +138,9 @@ void TemplatedConstructor_deconstructor_5(int nargout, mxArray *out[], int nargi
Collector_TemplatedConstructor::iterator item;
item = collector_TemplatedConstructor.find(self);
if(item != collector_TemplatedConstructor.end()) {
delete self;
collector_TemplatedConstructor.erase(item);
}
delete self;
}
void ScopedTemplateResult_collectorInsertAndMakeBase_6(int nargout, mxArray *out[], int nargin, const mxArray *in[])
@ -172,9 +172,9 @@ void ScopedTemplateResult_deconstructor_8(int nargout, mxArray *out[], int nargi
Collector_ScopedTemplateResult::iterator item;
item = collector_ScopedTemplateResult.find(self);
if(item != collector_ScopedTemplateResult.end()) {
delete self;
collector_ScopedTemplateResult.erase(item);
}
delete self;
}

View File

@ -24,9 +24,6 @@ class Point2 {
VectorNotEigen vectorConfusion();
void serializable() const; // Sets flag and creates export, but does not make serialization functions
// enable pickling in python
void pickle() const;
};
#include <gtsam/geometry/Point3.h>
@ -40,9 +37,6 @@ class Point3 {
// enabling serialization functionality
void serialize() const; // Just triggers a flag internally and removes actual function
// enable pickling in python
void pickle() const;
};
}