From 707b13dff5cacce953c9319b0ff3a1d47aa10e5b Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Mon, 13 Dec 2021 08:53:49 -0500 Subject: [PATCH 1/2] Squashed 'wrap/' changes from 248971868..086be59be 086be59be Merge pull request #135 from borglab/feature/matlab_default_args d3a0a8a15 don't allow out-of-order default argument specifications in matlab 702986de3 take out unit test with illegal default argument specification (according to c++ rules) 6166dfa4d update functions.i unit test expected and fix cyclic copy 4a4003273 class wrapper working b7e4d3522 Update class_wrapper matlab unit test b9409f10c placeholder folder for unit test "actual" folder 5e2aa1511 fix unit test for `DefaultFuncInt` only (others not fixed yet) git-subtree-dir: wrap git-subtree-split: 086be59bed87cc8a9c3f28b4cb99566b59bc3fda --- gtwrap/matlab_wrapper/wrapper.py | 83 ++++++++---- tests/actual/.gitignore | 2 + tests/expected/matlab/DefaultFuncInt.m | 4 + tests/expected/matlab/DefaultFuncObj.m | 4 +- tests/expected/matlab/DefaultFuncString.m | 6 +- tests/expected/matlab/DefaultFuncVector.m | 6 +- tests/expected/matlab/DefaultFuncZero.m | 10 +- tests/expected/matlab/ForwardKinematics.m | 4 +- tests/expected/matlab/MyFactorPosePoint2.m | 20 ++- tests/expected/matlab/TemplatedFunctionRot3.m | 2 +- tests/expected/matlab/class_wrapper.cpp | 77 ++++++++--- tests/expected/matlab/functions_wrapper.cpp | 126 ++++++++++++++++-- tests/expected/matlab/setPose.m | 4 +- tests/expected/python/functions_pybind.cpp | 2 +- tests/fixtures/functions.i | 2 +- 15 files changed, 282 insertions(+), 70 deletions(-) create mode 100644 tests/actual/.gitignore diff --git a/gtwrap/matlab_wrapper/wrapper.py b/gtwrap/matlab_wrapper/wrapper.py index b87db23f3d..3935f25a3f 100755 --- a/gtwrap/matlab_wrapper/wrapper.py +++ b/gtwrap/matlab_wrapper/wrapper.py @@ -10,8 +10,10 @@ 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.matlab_wrapper.mixins import CheckMixin, FormatMixin from gtwrap.matlab_wrapper.templates import WrapperTemplate @@ -137,6 +139,37 @@ def _insert_spaces(self, x, y): """ return x + '\n' + ('' if y == '' else ' ') + y + @staticmethod + def _expand_default_arguments(method, save_backup=True): + """Recursively expand all possibilities for optional default arguments. + We create "overload" functions with fewer arguments, but since we have to "remember" what + the default arguments are for later, we make a backup. + """ + def args_copy(args): + return ArgumentList([copy.copy(arg) for arg in args.list()]) + def method_copy(method): + method2 = copy.copy(method) + method2.args = args_copy(method.args) + method2.args.backup = method.args.backup + return method2 + if save_backup: + method.args.backup = args_copy(method.args) + method = method_copy(method) + for arg in reversed(method.args.list()): + if arg.default is not None: + arg.default = None + methodWithArg = method_copy(method) + method.args.list().remove(arg) + return [ + methodWithArg, + *MatlabWrapper._expand_default_arguments(method, save_backup=False) + ] + break + assert all(arg.default is None for arg in method.args.list()), \ + 'In parsing method {:}: Arguments with default values cannot appear before ones ' \ + 'without default values.'.format(method.name) + return [method] + def _group_methods(self, methods): """Group overloaded methods together""" method_map = {} @@ -147,9 +180,9 @@ def _group_methods(self, methods): if method_index is None: method_map[method.name] = len(method_out) - method_out.append([method]) + method_out.append(MatlabWrapper._expand_default_arguments(method)) else: - method_out[method_index].append(method) + method_out[method_index] += MatlabWrapper._expand_default_arguments(method) return method_out @@ -301,13 +334,9 @@ def _wrapper_unwrap_arguments(self, args, arg_id=0, constructor=False): ((a), Test& t = *unwrap_shared_ptr< Test >(in[1], "ptr_Test");), ((a), std::shared_ptr p1 = unwrap_shared_ptr< Test >(in[1], "ptr_Test");) """ - params = '' body_args = '' for arg in args.list(): - if params != '': - params += ',' - if self.is_ref(arg.ctype): # and not constructor: ctype_camel = self._format_type_name(arg.ctype.typename, separator='') @@ -336,8 +365,6 @@ def _wrapper_unwrap_arguments(self, args, arg_id=0, constructor=False): name=arg.name, id=arg_id)), prefix=' ') - if call_type == "": - params += "*" else: body_args += textwrap.indent(textwrap.dedent('''\ @@ -347,10 +374,29 @@ def _wrapper_unwrap_arguments(self, args, arg_id=0, constructor=False): id=arg_id)), prefix=' ') - params += arg.name - arg_id += 1 + params = '' + explicit_arg_names = [arg.name for arg in args.list()] + # when returning the params list, we need to re-include the default args. + for arg in args.backup.list(): + if params != '': + params += ',' + + if (arg.default is not None) and (arg.name not in explicit_arg_names): + params += arg.default + continue + + if (not self.is_ref(arg.ctype)) and (self.is_shared_ptr(arg.ctype)) and (self.is_ptr( + arg.ctype)) and (arg.ctype.typename.name not in self.ignore_namespace): + if arg.ctype.is_shared_ptr: + call_type = arg.ctype.is_shared_ptr + else: + call_type = arg.ctype.is_ptr + if call_type == "": + params += "*" + params += arg.name + return params, body_args @staticmethod @@ -555,6 +601,8 @@ def wrap_class_constructors(self, namespace_name, inst_class, parent_name, if not isinstance(ctors, Iterable): ctors = [ctors] + ctors = sum((MatlabWrapper._expand_default_arguments(ctor) for ctor in ctors), []) + methods_wrap = textwrap.indent(textwrap.dedent("""\ methods function obj = {class_name}(varargin) @@ -674,20 +722,7 @@ def wrap_class_display(self): def _group_class_methods(self, methods): """Group overloaded methods together""" - method_map = {} - method_out = [] - - for method in methods: - method_index = method_map.get(method.name) - - if method_index is None: - method_map[method.name] = len(method_out) - method_out.append([method]) - else: - # print("[_group_methods] Merging {} with {}".format(method_index, method.name)) - method_out[method_index].append(method) - - return method_out + return self._group_methods(methods) @classmethod def _format_varargout(cls, return_type, return_type_formatted): diff --git a/tests/actual/.gitignore b/tests/actual/.gitignore new file mode 100644 index 0000000000..7e0359a99d --- /dev/null +++ b/tests/actual/.gitignore @@ -0,0 +1,2 @@ +./* +!.gitignore diff --git a/tests/expected/matlab/DefaultFuncInt.m b/tests/expected/matlab/DefaultFuncInt.m index 284aaa9f02..6c9c4116bc 100644 --- a/tests/expected/matlab/DefaultFuncInt.m +++ b/tests/expected/matlab/DefaultFuncInt.m @@ -1,6 +1,10 @@ function varargout = DefaultFuncInt(varargin) if length(varargin) == 2 && isa(varargin{1},'numeric') && isa(varargin{2},'numeric') functions_wrapper(8, varargin{:}); + elseif length(varargin) == 1 && isa(varargin{1},'numeric') + functions_wrapper(9, varargin{:}); + elseif length(varargin) == 0 + functions_wrapper(10, varargin{:}); else error('Arguments do not match any overload of function DefaultFuncInt'); end diff --git a/tests/expected/matlab/DefaultFuncObj.m b/tests/expected/matlab/DefaultFuncObj.m index d2006dcad7..15d9ba0fa3 100644 --- a/tests/expected/matlab/DefaultFuncObj.m +++ b/tests/expected/matlab/DefaultFuncObj.m @@ -1,6 +1,8 @@ function varargout = DefaultFuncObj(varargin) if length(varargin) == 1 && isa(varargin{1},'gtsam.KeyFormatter') - functions_wrapper(10, varargin{:}); + functions_wrapper(14, varargin{:}); + elseif length(varargin) == 0 + functions_wrapper(15, varargin{:}); else error('Arguments do not match any overload of function DefaultFuncObj'); end diff --git a/tests/expected/matlab/DefaultFuncString.m b/tests/expected/matlab/DefaultFuncString.m index 86572ffbfc..d26201c152 100644 --- a/tests/expected/matlab/DefaultFuncString.m +++ b/tests/expected/matlab/DefaultFuncString.m @@ -1,6 +1,10 @@ function varargout = DefaultFuncString(varargin) if length(varargin) == 2 && isa(varargin{1},'char') && isa(varargin{2},'char') - functions_wrapper(9, varargin{:}); + functions_wrapper(11, varargin{:}); + elseif length(varargin) == 1 && isa(varargin{1},'char') + functions_wrapper(12, varargin{:}); + elseif length(varargin) == 0 + functions_wrapper(13, varargin{:}); else error('Arguments do not match any overload of function DefaultFuncString'); end diff --git a/tests/expected/matlab/DefaultFuncVector.m b/tests/expected/matlab/DefaultFuncVector.m index 9e4db181df..344533fad0 100644 --- a/tests/expected/matlab/DefaultFuncVector.m +++ b/tests/expected/matlab/DefaultFuncVector.m @@ -1,6 +1,10 @@ function varargout = DefaultFuncVector(varargin) if length(varargin) == 2 && isa(varargin{1},'std.vectornumeric') && isa(varargin{2},'std.vectorchar') - functions_wrapper(12, varargin{:}); + functions_wrapper(20, varargin{:}); + elseif length(varargin) == 1 && isa(varargin{1},'std.vectornumeric') + functions_wrapper(21, varargin{:}); + elseif length(varargin) == 0 + functions_wrapper(22, varargin{:}); else error('Arguments do not match any overload of function DefaultFuncVector'); end diff --git a/tests/expected/matlab/DefaultFuncZero.m b/tests/expected/matlab/DefaultFuncZero.m index 7d37dcfa7d..0ebba2e5c7 100644 --- a/tests/expected/matlab/DefaultFuncZero.m +++ b/tests/expected/matlab/DefaultFuncZero.m @@ -1,6 +1,12 @@ function varargout = DefaultFuncZero(varargin) - if length(varargin) == 5 && isa(varargin{1},'numeric') && isa(varargin{2},'numeric') && isa(varargin{3},'double') && isa(varargin{4},'logical') && isa(varargin{5},'logical') - functions_wrapper(11, varargin{:}); + if length(varargin) == 5 && isa(varargin{1},'numeric') && isa(varargin{2},'numeric') && isa(varargin{3},'double') && isa(varargin{4},'numeric') && isa(varargin{5},'logical') + functions_wrapper(16, varargin{:}); + elseif length(varargin) == 4 && isa(varargin{1},'numeric') && isa(varargin{2},'numeric') && isa(varargin{3},'double') && isa(varargin{4},'numeric') + functions_wrapper(17, varargin{:}); + elseif length(varargin) == 3 && isa(varargin{1},'numeric') && isa(varargin{2},'numeric') && isa(varargin{3},'double') + functions_wrapper(18, varargin{:}); + elseif length(varargin) == 2 && isa(varargin{1},'numeric') && isa(varargin{2},'numeric') + functions_wrapper(19, varargin{:}); else error('Arguments do not match any overload of function DefaultFuncZero'); end diff --git a/tests/expected/matlab/ForwardKinematics.m b/tests/expected/matlab/ForwardKinematics.m index e420dcc464..f91733440c 100644 --- a/tests/expected/matlab/ForwardKinematics.m +++ b/tests/expected/matlab/ForwardKinematics.m @@ -15,6 +15,8 @@ class_wrapper(55, my_ptr); elseif nargin == 5 && isa(varargin{1},'gtdynamics.Robot') && isa(varargin{2},'char') && isa(varargin{3},'char') && isa(varargin{4},'gtsam.Values') && isa(varargin{5},'gtsam.Pose3') my_ptr = class_wrapper(56, varargin{1}, varargin{2}, varargin{3}, varargin{4}, varargin{5}); + elseif nargin == 4 && isa(varargin{1},'gtdynamics.Robot') && isa(varargin{2},'char') && isa(varargin{3},'char') && isa(varargin{4},'gtsam.Values') + my_ptr = class_wrapper(57, varargin{1}, varargin{2}, varargin{3}, varargin{4}); else error('Arguments do not match any overload of ForwardKinematics constructor'); end @@ -22,7 +24,7 @@ end function delete(obj) - class_wrapper(57, obj.ptr_ForwardKinematics); + class_wrapper(58, obj.ptr_ForwardKinematics); end function display(obj), obj.print(''); end diff --git a/tests/expected/matlab/MyFactorPosePoint2.m b/tests/expected/matlab/MyFactorPosePoint2.m index 56843ed0a9..f31367698b 100644 --- a/tests/expected/matlab/MyFactorPosePoint2.m +++ b/tests/expected/matlab/MyFactorPosePoint2.m @@ -15,9 +15,9 @@ function obj = MyFactorPosePoint2(varargin) if nargin == 2 && isa(varargin{1}, 'uint64') && varargin{1} == uint64(5139824614673773682) my_ptr = varargin{2}; - class_wrapper(64, my_ptr); + class_wrapper(65, my_ptr); elseif nargin == 4 && isa(varargin{1},'numeric') && isa(varargin{2},'numeric') && isa(varargin{3},'double') && isa(varargin{4},'gtsam.noiseModel.Base') - my_ptr = class_wrapper(65, varargin{1}, varargin{2}, varargin{3}, varargin{4}); + my_ptr = class_wrapper(66, varargin{1}, varargin{2}, varargin{3}, varargin{4}); else error('Arguments do not match any overload of MyFactorPosePoint2 constructor'); end @@ -25,7 +25,7 @@ end function delete(obj) - class_wrapper(66, obj.ptr_MyFactorPosePoint2); + class_wrapper(67, obj.ptr_MyFactorPosePoint2); end function display(obj), obj.print(''); end @@ -36,7 +36,19 @@ function delete(obj) % PRINT usage: print(string s, KeyFormatter keyFormatter) : returns void % Doxygen can be found at https://gtsam.org/doxygen/ if length(varargin) == 2 && isa(varargin{1},'char') && isa(varargin{2},'gtsam.KeyFormatter') - class_wrapper(67, this, varargin{:}); + class_wrapper(68, this, varargin{:}); + return + end + % PRINT usage: print(string s) : returns void + % Doxygen can be found at https://gtsam.org/doxygen/ + if length(varargin) == 1 && isa(varargin{1},'char') + class_wrapper(69, this, varargin{:}); + return + end + % PRINT usage: print() : returns void + % Doxygen can be found at https://gtsam.org/doxygen/ + if length(varargin) == 0 + class_wrapper(70, this, varargin{:}); return end error('Arguments do not match any overload of function MyFactorPosePoint2.print'); diff --git a/tests/expected/matlab/TemplatedFunctionRot3.m b/tests/expected/matlab/TemplatedFunctionRot3.m index 4216201b49..eb5cb4abea 100644 --- a/tests/expected/matlab/TemplatedFunctionRot3.m +++ b/tests/expected/matlab/TemplatedFunctionRot3.m @@ -1,6 +1,6 @@ function varargout = TemplatedFunctionRot3(varargin) if length(varargin) == 1 && isa(varargin{1},'gtsam.Rot3') - functions_wrapper(14, varargin{:}); + functions_wrapper(25, varargin{:}); else error('Arguments do not match any overload of function TemplatedFunctionRot3'); end diff --git a/tests/expected/matlab/class_wrapper.cpp b/tests/expected/matlab/class_wrapper.cpp index bdb0d1de60..e7e4ebf3bd 100644 --- a/tests/expected/matlab/class_wrapper.cpp +++ b/tests/expected/matlab/class_wrapper.cpp @@ -691,7 +691,22 @@ void ForwardKinematics_constructor_56(int nargout, mxArray *out[], int nargin, c *reinterpret_cast (mxGetData(out[0])) = self; } -void ForwardKinematics_deconstructor_57(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +void ForwardKinematics_constructor_57(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +{ + mexAtExit(&_deleteAllObjects); + typedef boost::shared_ptr Shared; + + gtdynamics::Robot& robot = *unwrap_shared_ptr< gtdynamics::Robot >(in[0], "ptr_gtdynamicsRobot"); + string& start_link_name = *unwrap_shared_ptr< string >(in[1], "ptr_string"); + string& end_link_name = *unwrap_shared_ptr< string >(in[2], "ptr_string"); + gtsam::Values& joint_angles = *unwrap_shared_ptr< gtsam::Values >(in[3], "ptr_gtsamValues"); + Shared *self = new Shared(new ForwardKinematics(robot,start_link_name,end_link_name,joint_angles,gtsam::Pose3())); + collector_ForwardKinematics.insert(self); + out[0] = mxCreateNumericMatrix(1, 1, mxUINT32OR64_CLASS, mxREAL); + *reinterpret_cast (mxGetData(out[0])) = self; +} + +void ForwardKinematics_deconstructor_58(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { typedef boost::shared_ptr Shared; checkArguments("delete_ForwardKinematics",nargout,nargin,1); @@ -704,7 +719,7 @@ void ForwardKinematics_deconstructor_57(int nargout, mxArray *out[], int nargin, } } -void TemplatedConstructor_collectorInsertAndMakeBase_58(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +void TemplatedConstructor_collectorInsertAndMakeBase_59(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { mexAtExit(&_deleteAllObjects); typedef boost::shared_ptr Shared; @@ -713,7 +728,7 @@ void TemplatedConstructor_collectorInsertAndMakeBase_58(int nargout, mxArray *ou collector_TemplatedConstructor.insert(self); } -void TemplatedConstructor_constructor_59(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +void TemplatedConstructor_constructor_60(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { mexAtExit(&_deleteAllObjects); typedef boost::shared_ptr Shared; @@ -724,7 +739,7 @@ void TemplatedConstructor_constructor_59(int nargout, mxArray *out[], int nargin *reinterpret_cast (mxGetData(out[0])) = self; } -void TemplatedConstructor_constructor_60(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +void TemplatedConstructor_constructor_61(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { mexAtExit(&_deleteAllObjects); typedef boost::shared_ptr Shared; @@ -736,7 +751,7 @@ void TemplatedConstructor_constructor_60(int nargout, mxArray *out[], int nargin *reinterpret_cast (mxGetData(out[0])) = self; } -void TemplatedConstructor_constructor_61(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +void TemplatedConstructor_constructor_62(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { mexAtExit(&_deleteAllObjects); typedef boost::shared_ptr Shared; @@ -748,7 +763,7 @@ void TemplatedConstructor_constructor_61(int nargout, mxArray *out[], int nargin *reinterpret_cast (mxGetData(out[0])) = self; } -void TemplatedConstructor_constructor_62(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +void TemplatedConstructor_constructor_63(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { mexAtExit(&_deleteAllObjects); typedef boost::shared_ptr Shared; @@ -760,7 +775,7 @@ void TemplatedConstructor_constructor_62(int nargout, mxArray *out[], int nargin *reinterpret_cast (mxGetData(out[0])) = self; } -void TemplatedConstructor_deconstructor_63(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +void TemplatedConstructor_deconstructor_64(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { typedef boost::shared_ptr Shared; checkArguments("delete_TemplatedConstructor",nargout,nargin,1); @@ -773,7 +788,7 @@ void TemplatedConstructor_deconstructor_63(int nargout, mxArray *out[], int narg } } -void MyFactorPosePoint2_collectorInsertAndMakeBase_64(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +void MyFactorPosePoint2_collectorInsertAndMakeBase_65(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { mexAtExit(&_deleteAllObjects); typedef boost::shared_ptr> Shared; @@ -782,7 +797,7 @@ void MyFactorPosePoint2_collectorInsertAndMakeBase_64(int nargout, mxArray *out[ collector_MyFactorPosePoint2.insert(self); } -void MyFactorPosePoint2_constructor_65(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +void MyFactorPosePoint2_constructor_66(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { mexAtExit(&_deleteAllObjects); typedef boost::shared_ptr> Shared; @@ -797,7 +812,7 @@ void MyFactorPosePoint2_constructor_65(int nargout, mxArray *out[], int nargin, *reinterpret_cast (mxGetData(out[0])) = self; } -void MyFactorPosePoint2_deconstructor_66(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +void MyFactorPosePoint2_deconstructor_67(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { typedef boost::shared_ptr> Shared; checkArguments("delete_MyFactorPosePoint2",nargout,nargin,1); @@ -810,7 +825,7 @@ void MyFactorPosePoint2_deconstructor_66(int nargout, mxArray *out[], int nargin } } -void MyFactorPosePoint2_print_67(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +void MyFactorPosePoint2_print_68(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { checkArguments("print",nargout,nargin-1,2); auto obj = unwrap_shared_ptr>(in[0], "ptr_MyFactorPosePoint2"); @@ -819,6 +834,21 @@ void MyFactorPosePoint2_print_67(int nargout, mxArray *out[], int nargin, const obj->print(s,keyFormatter); } +void MyFactorPosePoint2_print_69(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +{ + checkArguments("print",nargout,nargin-1,1); + auto obj = unwrap_shared_ptr>(in[0], "ptr_MyFactorPosePoint2"); + string& s = *unwrap_shared_ptr< string >(in[1], "ptr_string"); + obj->print(s,gtsam::DefaultKeyFormatter); +} + +void MyFactorPosePoint2_print_70(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +{ + checkArguments("print",nargout,nargin-1,0); + auto obj = unwrap_shared_ptr>(in[0], "ptr_MyFactorPosePoint2"); + obj->print("factor: ",gtsam::DefaultKeyFormatter); +} + void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { @@ -1003,13 +1033,13 @@ void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[]) ForwardKinematics_constructor_56(nargout, out, nargin-1, in+1); break; case 57: - ForwardKinematics_deconstructor_57(nargout, out, nargin-1, in+1); + ForwardKinematics_constructor_57(nargout, out, nargin-1, in+1); break; case 58: - TemplatedConstructor_collectorInsertAndMakeBase_58(nargout, out, nargin-1, in+1); + ForwardKinematics_deconstructor_58(nargout, out, nargin-1, in+1); break; case 59: - TemplatedConstructor_constructor_59(nargout, out, nargin-1, in+1); + TemplatedConstructor_collectorInsertAndMakeBase_59(nargout, out, nargin-1, in+1); break; case 60: TemplatedConstructor_constructor_60(nargout, out, nargin-1, in+1); @@ -1021,19 +1051,28 @@ void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[]) TemplatedConstructor_constructor_62(nargout, out, nargin-1, in+1); break; case 63: - TemplatedConstructor_deconstructor_63(nargout, out, nargin-1, in+1); + TemplatedConstructor_constructor_63(nargout, out, nargin-1, in+1); break; case 64: - MyFactorPosePoint2_collectorInsertAndMakeBase_64(nargout, out, nargin-1, in+1); + TemplatedConstructor_deconstructor_64(nargout, out, nargin-1, in+1); break; case 65: - MyFactorPosePoint2_constructor_65(nargout, out, nargin-1, in+1); + MyFactorPosePoint2_collectorInsertAndMakeBase_65(nargout, out, nargin-1, in+1); break; case 66: - MyFactorPosePoint2_deconstructor_66(nargout, out, nargin-1, in+1); + MyFactorPosePoint2_constructor_66(nargout, out, nargin-1, in+1); break; case 67: - MyFactorPosePoint2_print_67(nargout, out, nargin-1, in+1); + MyFactorPosePoint2_deconstructor_67(nargout, out, nargin-1, in+1); + break; + case 68: + MyFactorPosePoint2_print_68(nargout, out, nargin-1, in+1); + break; + case 69: + MyFactorPosePoint2_print_69(nargout, out, nargin-1, in+1); + break; + case 70: + MyFactorPosePoint2_print_70(nargout, out, nargin-1, in+1); break; } } catch(const std::exception& e) { diff --git a/tests/expected/matlab/functions_wrapper.cpp b/tests/expected/matlab/functions_wrapper.cpp index d0f0f8ca67..313197d8cc 100644 --- a/tests/expected/matlab/functions_wrapper.cpp +++ b/tests/expected/matlab/functions_wrapper.cpp @@ -130,43 +130,110 @@ void DefaultFuncInt_8(int nargout, mxArray *out[], int nargin, const mxArray *in int b = unwrap< int >(in[1]); DefaultFuncInt(a,b); } -void DefaultFuncString_9(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +void DefaultFuncInt_9(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +{ + checkArguments("DefaultFuncInt",nargout,nargin,1); + int a = unwrap< int >(in[0]); + DefaultFuncInt(a,0); +} +void DefaultFuncInt_10(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +{ + checkArguments("DefaultFuncInt",nargout,nargin,0); + DefaultFuncInt(123,0); +} +void DefaultFuncString_11(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { checkArguments("DefaultFuncString",nargout,nargin,2); string& s = *unwrap_shared_ptr< string >(in[0], "ptr_string"); string& name = *unwrap_shared_ptr< string >(in[1], "ptr_string"); DefaultFuncString(s,name); } -void DefaultFuncObj_10(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +void DefaultFuncString_12(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +{ + checkArguments("DefaultFuncString",nargout,nargin,1); + string& s = *unwrap_shared_ptr< string >(in[0], "ptr_string"); + DefaultFuncString(s,""); +} +void DefaultFuncString_13(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +{ + checkArguments("DefaultFuncString",nargout,nargin,0); + DefaultFuncString("hello",""); +} +void DefaultFuncObj_14(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { checkArguments("DefaultFuncObj",nargout,nargin,1); gtsam::KeyFormatter& keyFormatter = *unwrap_shared_ptr< gtsam::KeyFormatter >(in[0], "ptr_gtsamKeyFormatter"); DefaultFuncObj(keyFormatter); } -void DefaultFuncZero_11(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +void DefaultFuncObj_15(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +{ + checkArguments("DefaultFuncObj",nargout,nargin,0); + DefaultFuncObj(gtsam::DefaultKeyFormatter); +} +void DefaultFuncZero_16(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { checkArguments("DefaultFuncZero",nargout,nargin,5); int a = unwrap< int >(in[0]); int b = unwrap< int >(in[1]); double c = unwrap< double >(in[2]); - bool d = unwrap< bool >(in[3]); + int d = unwrap< int >(in[3]); bool e = unwrap< bool >(in[4]); DefaultFuncZero(a,b,c,d,e); } -void DefaultFuncVector_12(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +void DefaultFuncZero_17(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +{ + checkArguments("DefaultFuncZero",nargout,nargin,4); + int a = unwrap< int >(in[0]); + int b = unwrap< int >(in[1]); + double c = unwrap< double >(in[2]); + int d = unwrap< int >(in[3]); + DefaultFuncZero(a,b,c,d,false); +} +void DefaultFuncZero_18(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +{ + checkArguments("DefaultFuncZero",nargout,nargin,3); + int a = unwrap< int >(in[0]); + int b = unwrap< int >(in[1]); + double c = unwrap< double >(in[2]); + DefaultFuncZero(a,b,c,0,false); +} +void DefaultFuncZero_19(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +{ + checkArguments("DefaultFuncZero",nargout,nargin,2); + int a = unwrap< int >(in[0]); + int b = unwrap< int >(in[1]); + DefaultFuncZero(a,b,0.0,0,false); +} +void DefaultFuncVector_20(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { checkArguments("DefaultFuncVector",nargout,nargin,2); std::vector& i = *unwrap_shared_ptr< std::vector >(in[0], "ptr_stdvectorint"); std::vector& s = *unwrap_shared_ptr< std::vector >(in[1], "ptr_stdvectorstring"); DefaultFuncVector(i,s); } -void setPose_13(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +void DefaultFuncVector_21(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +{ + checkArguments("DefaultFuncVector",nargout,nargin,1); + std::vector& i = *unwrap_shared_ptr< std::vector >(in[0], "ptr_stdvectorint"); + DefaultFuncVector(i,{"borglab", "gtsam"}); +} +void DefaultFuncVector_22(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +{ + checkArguments("DefaultFuncVector",nargout,nargin,0); + DefaultFuncVector({1, 2, 3},{"borglab", "gtsam"}); +} +void setPose_23(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { checkArguments("setPose",nargout,nargin,1); gtsam::Pose3& pose = *unwrap_shared_ptr< gtsam::Pose3 >(in[0], "ptr_gtsamPose3"); setPose(pose); } -void TemplatedFunctionRot3_14(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +void setPose_24(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +{ + checkArguments("setPose",nargout,nargin,0); + setPose(gtsam::Pose3()); +} +void TemplatedFunctionRot3_25(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { checkArguments("TemplatedFunctionRot3",nargout,nargin,1); gtsam::Rot3& t = *unwrap_shared_ptr< gtsam::Rot3 >(in[0], "ptr_gtsamRot3"); @@ -212,22 +279,55 @@ void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[]) DefaultFuncInt_8(nargout, out, nargin-1, in+1); break; case 9: - DefaultFuncString_9(nargout, out, nargin-1, in+1); + DefaultFuncInt_9(nargout, out, nargin-1, in+1); break; case 10: - DefaultFuncObj_10(nargout, out, nargin-1, in+1); + DefaultFuncInt_10(nargout, out, nargin-1, in+1); break; case 11: - DefaultFuncZero_11(nargout, out, nargin-1, in+1); + DefaultFuncString_11(nargout, out, nargin-1, in+1); break; case 12: - DefaultFuncVector_12(nargout, out, nargin-1, in+1); + DefaultFuncString_12(nargout, out, nargin-1, in+1); break; case 13: - setPose_13(nargout, out, nargin-1, in+1); + DefaultFuncString_13(nargout, out, nargin-1, in+1); break; case 14: - TemplatedFunctionRot3_14(nargout, out, nargin-1, in+1); + DefaultFuncObj_14(nargout, out, nargin-1, in+1); + break; + case 15: + DefaultFuncObj_15(nargout, out, nargin-1, in+1); + break; + case 16: + DefaultFuncZero_16(nargout, out, nargin-1, in+1); + break; + case 17: + DefaultFuncZero_17(nargout, out, nargin-1, in+1); + break; + case 18: + DefaultFuncZero_18(nargout, out, nargin-1, in+1); + break; + case 19: + DefaultFuncZero_19(nargout, out, nargin-1, in+1); + break; + case 20: + DefaultFuncVector_20(nargout, out, nargin-1, in+1); + break; + case 21: + DefaultFuncVector_21(nargout, out, nargin-1, in+1); + break; + case 22: + DefaultFuncVector_22(nargout, out, nargin-1, in+1); + break; + case 23: + setPose_23(nargout, out, nargin-1, in+1); + break; + case 24: + setPose_24(nargout, out, nargin-1, in+1); + break; + case 25: + TemplatedFunctionRot3_25(nargout, out, nargin-1, in+1); break; } } catch(const std::exception& e) { diff --git a/tests/expected/matlab/setPose.m b/tests/expected/matlab/setPose.m index ed573b8729..d45cc56921 100644 --- a/tests/expected/matlab/setPose.m +++ b/tests/expected/matlab/setPose.m @@ -1,6 +1,8 @@ function varargout = setPose(varargin) if length(varargin) == 1 && isa(varargin{1},'gtsam.Pose3') - functions_wrapper(13, varargin{:}); + functions_wrapper(23, varargin{:}); + elseif length(varargin) == 0 + functions_wrapper(24, varargin{:}); else error('Arguments do not match any overload of function setPose'); end diff --git a/tests/expected/python/functions_pybind.cpp b/tests/expected/python/functions_pybind.cpp index bee95ec03f..8511b5d3cd 100644 --- a/tests/expected/python/functions_pybind.cpp +++ b/tests/expected/python/functions_pybind.cpp @@ -33,7 +33,7 @@ PYBIND11_MODULE(functions_py, m_) { m_.def("DefaultFuncInt",[](int a, int b){ ::DefaultFuncInt(a, b);}, py::arg("a") = 123, py::arg("b") = 0); m_.def("DefaultFuncString",[](const string& s, const string& name){ ::DefaultFuncString(s, name);}, py::arg("s") = "hello", py::arg("name") = ""); m_.def("DefaultFuncObj",[](const gtsam::KeyFormatter& keyFormatter){ ::DefaultFuncObj(keyFormatter);}, py::arg("keyFormatter") = gtsam::DefaultKeyFormatter); - m_.def("DefaultFuncZero",[](int a, int b, double c, bool d, bool e){ ::DefaultFuncZero(a, b, c, d, e);}, py::arg("a") = 0, py::arg("b"), py::arg("c") = 0.0, py::arg("d") = false, py::arg("e")); + m_.def("DefaultFuncZero",[](int a, int b, double c, int d, bool e){ ::DefaultFuncZero(a, b, c, d, e);}, py::arg("a"), py::arg("b"), py::arg("c") = 0.0, py::arg("d") = 0, py::arg("e") = false); m_.def("DefaultFuncVector",[](const std::vector& i, const std::vector& s){ ::DefaultFuncVector(i, s);}, py::arg("i") = {1, 2, 3}, py::arg("s") = {"borglab", "gtsam"}); m_.def("setPose",[](const gtsam::Pose3& pose){ ::setPose(pose);}, py::arg("pose") = gtsam::Pose3()); m_.def("TemplatedFunctionRot3",[](const gtsam::Rot3& t){ ::TemplatedFunction(t);}, py::arg("t")); diff --git a/tests/fixtures/functions.i b/tests/fixtures/functions.i index 0852a3e1e9..7f3c833328 100644 --- a/tests/fixtures/functions.i +++ b/tests/fixtures/functions.i @@ -31,7 +31,7 @@ typedef TemplatedFunction TemplatedFunctionRot3; void DefaultFuncInt(int a = 123, int b = 0); void DefaultFuncString(const string& s = "hello", const string& name = ""); void DefaultFuncObj(const gtsam::KeyFormatter& keyFormatter = gtsam::DefaultKeyFormatter); -void DefaultFuncZero(int a = 0, int b, double c = 0.0, bool d = false, bool e); +void DefaultFuncZero(int a, int b, double c = 0.0, int d = 0, bool e = false); void DefaultFuncVector(const std::vector &i = {1, 2, 3}, const std::vector &s = {"borglab", "gtsam"}); // Test for non-trivial default constructor From 5beaed55c91af5cb33a8c27293b365c560c4497e Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Mon, 13 Dec 2021 11:18:52 -0500 Subject: [PATCH 2/2] remove previously added parameters now that we support defaults --- matlab/gtsam_tests/testJacobianFactor.m | 4 ++-- matlab/gtsam_tests/testKalmanFilter.m | 4 ++-- matlab/gtsam_tests/testLocalizationExample.m | 4 ++-- matlab/gtsam_tests/testOdometryExample.m | 4 ++-- matlab/gtsam_tests/testPlanarSLAMExample.m | 6 +++--- matlab/gtsam_tests/testPose2SLAMExample.m | 6 +++--- matlab/gtsam_tests/testPose3SLAMExample.m | 2 +- matlab/gtsam_tests/testSFMExample.m | 6 +++--- matlab/gtsam_tests/testSerialization.m | 10 +++++----- matlab/gtsam_tests/testStereoVOExample.m | 2 +- 10 files changed, 24 insertions(+), 24 deletions(-) diff --git a/matlab/gtsam_tests/testJacobianFactor.m b/matlab/gtsam_tests/testJacobianFactor.m index 7a2d344b1e..1c214c3bcc 100644 --- a/matlab/gtsam_tests/testJacobianFactor.m +++ b/matlab/gtsam_tests/testJacobianFactor.m @@ -32,7 +32,7 @@ % the RHS b2=[-1;1.5;2;-1]; sigmas = [1;1;1;1]; -model4 = noiseModel.Diagonal.Sigmas(sigmas, true); +model4 = noiseModel.Diagonal.Sigmas(sigmas); combined = JacobianFactor(x2, Ax2, l1, Al1, x1, Ax1, b2, model4); % eliminate the first variable (x2) in the combined factor, destructive ! @@ -74,7 +74,7 @@ % the RHS b1= [0.0;0.894427]; -model2 = noiseModel.Diagonal.Sigmas([1;1], true); +model2 = noiseModel.Diagonal.Sigmas([1;1]); expectedLF = JacobianFactor(l1, Bl1, x1, Bx1, b1, model2); % check if the result matches the combined (reduced) factor diff --git a/matlab/gtsam_tests/testKalmanFilter.m b/matlab/gtsam_tests/testKalmanFilter.m index 46846b8f76..3564c6b7a7 100644 --- a/matlab/gtsam_tests/testKalmanFilter.m +++ b/matlab/gtsam_tests/testKalmanFilter.m @@ -23,13 +23,13 @@ F = eye(2,2); B = eye(2,2); u = [1.0; 0.0]; -modelQ = noiseModel.Diagonal.Sigmas([0.1;0.1], true); +modelQ = noiseModel.Diagonal.Sigmas([0.1;0.1]); Q = 0.01*eye(2,2); H = eye(2,2); z1 = [1.0, 0.0]'; z2 = [2.0, 0.0]'; z3 = [3.0, 0.0]'; -modelR = noiseModel.Diagonal.Sigmas([0.1;0.1], true); +modelR = noiseModel.Diagonal.Sigmas([0.1;0.1]); R = 0.01*eye(2,2); %% Create the set of expected output TestValues diff --git a/matlab/gtsam_tests/testLocalizationExample.m b/matlab/gtsam_tests/testLocalizationExample.m index 6c79eada5a..ed091ea716 100644 --- a/matlab/gtsam_tests/testLocalizationExample.m +++ b/matlab/gtsam_tests/testLocalizationExample.m @@ -17,7 +17,7 @@ %% Add two odometry factors odometry = Pose2(2.0, 0.0, 0.0); % create a measurement for both factors (the same in this case) -odometryNoise = noiseModel.Diagonal.Sigmas([0.2; 0.2; 0.1], true); % 20cm std on x,y, 0.1 rad on theta +odometryNoise = noiseModel.Diagonal.Sigmas([0.2; 0.2; 0.1]); % 20cm std on x,y, 0.1 rad on theta graph.add(BetweenFactorPose2(1, 2, odometry, odometryNoise)); graph.add(BetweenFactorPose2(2, 3, odometry, odometryNoise)); @@ -27,7 +27,7 @@ groundTruth.insert(1, Pose2(0.0, 0.0, 0.0)); groundTruth.insert(2, Pose2(2.0, 0.0, 0.0)); groundTruth.insert(3, Pose2(4.0, 0.0, 0.0)); -model = noiseModel.Diagonal.Sigmas([0.1; 0.1; 10], true); +model = noiseModel.Diagonal.Sigmas([0.1; 0.1; 10]); for i=1:3 graph.add(PriorFactorPose2(i, groundTruth.atPose2(i), model)); end diff --git a/matlab/gtsam_tests/testOdometryExample.m b/matlab/gtsam_tests/testOdometryExample.m index 744d1af6e3..9bd4762a7a 100644 --- a/matlab/gtsam_tests/testOdometryExample.m +++ b/matlab/gtsam_tests/testOdometryExample.m @@ -17,12 +17,12 @@ %% Add a Gaussian prior on pose x_1 priorMean = Pose2(0.0, 0.0, 0.0); % prior mean is at origin -priorNoise = noiseModel.Diagonal.Sigmas([0.3; 0.3; 0.1], true); % 30cm std on x,y, 0.1 rad on theta +priorNoise = noiseModel.Diagonal.Sigmas([0.3; 0.3; 0.1]); % 30cm std on x,y, 0.1 rad on theta graph.add(PriorFactorPose2(1, priorMean, priorNoise)); % add directly to graph %% Add two odometry factors odometry = Pose2(2.0, 0.0, 0.0); % create a measurement for both factors (the same in this case) -odometryNoise = noiseModel.Diagonal.Sigmas([0.2; 0.2; 0.1], true); % 20cm std on x,y, 0.1 rad on theta +odometryNoise = noiseModel.Diagonal.Sigmas([0.2; 0.2; 0.1]); % 20cm std on x,y, 0.1 rad on theta graph.add(BetweenFactorPose2(1, 2, odometry, odometryNoise)); graph.add(BetweenFactorPose2(2, 3, odometry, odometryNoise)); diff --git a/matlab/gtsam_tests/testPlanarSLAMExample.m b/matlab/gtsam_tests/testPlanarSLAMExample.m index 8cb2826fdb..e0b4dbfc8a 100644 --- a/matlab/gtsam_tests/testPlanarSLAMExample.m +++ b/matlab/gtsam_tests/testPlanarSLAMExample.m @@ -30,18 +30,18 @@ %% Add prior priorMean = Pose2(0.0, 0.0, 0.0); % prior at origin -priorNoise = noiseModel.Diagonal.Sigmas([0.3; 0.3; 0.1], true); +priorNoise = noiseModel.Diagonal.Sigmas([0.3; 0.3; 0.1]); graph.add(PriorFactorPose2(i1, priorMean, priorNoise)); % add directly to graph %% Add odometry odometry = Pose2(2.0, 0.0, 0.0); -odometryNoise = noiseModel.Diagonal.Sigmas([0.2; 0.2; 0.1], true); +odometryNoise = noiseModel.Diagonal.Sigmas([0.2; 0.2; 0.1]); graph.add(BetweenFactorPose2(i1, i2, odometry, odometryNoise)); graph.add(BetweenFactorPose2(i2, i3, odometry, odometryNoise)); %% Add bearing/range measurement factors degrees = pi/180; -brNoise = noiseModel.Diagonal.Sigmas([0.1; 0.2], true); +brNoise = noiseModel.Diagonal.Sigmas([0.1; 0.2]); graph.add(BearingRangeFactor2D(i1, j1, Rot2(45*degrees), sqrt(4+4), brNoise)); graph.add(BearingRangeFactor2D(i2, j1, Rot2(90*degrees), 2, brNoise)); graph.add(BearingRangeFactor2D(i3, j2, Rot2(90*degrees), 2, brNoise)); diff --git a/matlab/gtsam_tests/testPose2SLAMExample.m b/matlab/gtsam_tests/testPose2SLAMExample.m index 17374c71bf..72e5331f27 100644 --- a/matlab/gtsam_tests/testPose2SLAMExample.m +++ b/matlab/gtsam_tests/testPose2SLAMExample.m @@ -26,19 +26,19 @@ %% Add prior % gaussian for prior priorMean = Pose2(0.0, 0.0, 0.0); % prior at origin -priorNoise = noiseModel.Diagonal.Sigmas([0.3; 0.3; 0.1], true); +priorNoise = noiseModel.Diagonal.Sigmas([0.3; 0.3; 0.1]); graph.add(PriorFactorPose2(1, priorMean, priorNoise)); % add directly to graph %% Add odometry % general noisemodel for odometry -odometryNoise = noiseModel.Diagonal.Sigmas([0.2; 0.2; 0.1], true); +odometryNoise = noiseModel.Diagonal.Sigmas([0.2; 0.2; 0.1]); graph.add(BetweenFactorPose2(1, 2, Pose2(2.0, 0.0, 0.0 ), odometryNoise)); graph.add(BetweenFactorPose2(2, 3, Pose2(2.0, 0.0, pi/2), odometryNoise)); graph.add(BetweenFactorPose2(3, 4, Pose2(2.0, 0.0, pi/2), odometryNoise)); graph.add(BetweenFactorPose2(4, 5, Pose2(2.0, 0.0, pi/2), odometryNoise)); %% Add pose constraint -model = noiseModel.Diagonal.Sigmas([0.2; 0.2; 0.1], true); +model = noiseModel.Diagonal.Sigmas([0.2; 0.2; 0.1]); graph.add(BetweenFactorPose2(5, 2, Pose2(2.0, 0.0, pi/2), model)); %% Initialize to noisy points diff --git a/matlab/gtsam_tests/testPose3SLAMExample.m b/matlab/gtsam_tests/testPose3SLAMExample.m index d5e23ee779..51ba692409 100644 --- a/matlab/gtsam_tests/testPose3SLAMExample.m +++ b/matlab/gtsam_tests/testPose3SLAMExample.m @@ -21,7 +21,7 @@ fg = NonlinearFactorGraph; fg.add(NonlinearEqualityPose3(0, p0)); delta = p0.between(p1); -covariance = noiseModel.Diagonal.Sigmas([0.05; 0.05; 0.05; 5*pi/180; 5*pi/180; 5*pi/180], true); +covariance = noiseModel.Diagonal.Sigmas([0.05; 0.05; 0.05; 5*pi/180; 5*pi/180; 5*pi/180]); fg.add(BetweenFactorPose3(0,1, delta, covariance)); fg.add(BetweenFactorPose3(1,2, delta, covariance)); fg.add(BetweenFactorPose3(2,3, delta, covariance)); diff --git a/matlab/gtsam_tests/testSFMExample.m b/matlab/gtsam_tests/testSFMExample.m index 6ac41eedc9..a1f63c3a7d 100644 --- a/matlab/gtsam_tests/testSFMExample.m +++ b/matlab/gtsam_tests/testSFMExample.m @@ -25,7 +25,7 @@ graph = NonlinearFactorGraph; %% Add factors for all measurements -measurementNoise = noiseModel.Isotropic.Sigma(2,measurementNoiseSigma, true); +measurementNoise = noiseModel.Isotropic.Sigma(2,measurementNoiseSigma); for i=1:length(data.Z) for k=1:length(data.Z{i}) j = data.J{i}{k}; @@ -33,9 +33,9 @@ end end -posePriorNoise = noiseModel.Diagonal.Sigmas(poseNoiseSigmas, true); +posePriorNoise = noiseModel.Diagonal.Sigmas(poseNoiseSigmas); graph.add(PriorFactorPose3(symbol('x',1), truth.cameras{1}.pose, posePriorNoise)); -pointPriorNoise = noiseModel.Isotropic.Sigma(3,pointNoiseSigma, true); +pointPriorNoise = noiseModel.Isotropic.Sigma(3,pointNoiseSigma); graph.add(PriorFactorPoint3(symbol('p',1), truth.points{1}, pointPriorNoise)); %% Initial estimate diff --git a/matlab/gtsam_tests/testSerialization.m b/matlab/gtsam_tests/testSerialization.m index 2f1d116e8a..e55822c1c7 100644 --- a/matlab/gtsam_tests/testSerialization.m +++ b/matlab/gtsam_tests/testSerialization.m @@ -45,30 +45,30 @@ % Prior factor priorMean = Pose2(0.0, 0.0, 0.0); % prior at origin -priorNoise = noiseModel.Diagonal.Sigmas([0.3; 0.3; 0.1], true); +priorNoise = noiseModel.Diagonal.Sigmas([0.3; 0.3; 0.1]); graph.add(PriorFactorPose2(i1, priorMean, priorNoise)); % add directly to graph % Between Factors odometry = Pose2(2.0, 0.0, 0.0); -odometryNoise = noiseModel.Diagonal.Sigmas([0.2; 0.2; 0.1], true); +odometryNoise = noiseModel.Diagonal.Sigmas([0.2; 0.2; 0.1]); graph.add(BetweenFactorPose2(i1, i2, odometry, odometryNoise)); graph.add(BetweenFactorPose2(i2, i3, odometry, odometryNoise)); % Range Factors -rNoise = noiseModel.Diagonal.Sigmas([0.2], true); +rNoise = noiseModel.Diagonal.Sigmas([0.2]); graph.add(RangeFactor2D(i1, j1, sqrt(4+4), rNoise)); graph.add(RangeFactor2D(i2, j1, 2, rNoise)); graph.add(RangeFactor2D(i3, j2, 2, rNoise)); % Bearing Factors degrees = pi/180; -bNoise = noiseModel.Diagonal.Sigmas([0.1], true); +bNoise = noiseModel.Diagonal.Sigmas([0.1]); graph.add(BearingFactor2D(i1, j1, Rot2(45*degrees), bNoise)); graph.add(BearingFactor2D(i2, j1, Rot2(90*degrees), bNoise)); graph.add(BearingFactor2D(i3, j2, Rot2(90*degrees), bNoise)); % BearingRange Factors -brNoise = noiseModel.Diagonal.Sigmas([0.1; 0.2], true); +brNoise = noiseModel.Diagonal.Sigmas([0.1; 0.2]); graph.add(BearingRangeFactor2D(i1, j1, Rot2(45*degrees), sqrt(4+4), brNoise)); graph.add(BearingRangeFactor2D(i2, j1, Rot2(90*degrees), 2, brNoise)); graph.add(BearingRangeFactor2D(i3, j2, Rot2(90*degrees), 2, brNoise)); diff --git a/matlab/gtsam_tests/testStereoVOExample.m b/matlab/gtsam_tests/testStereoVOExample.m index 8edbb15535..c721244ba8 100644 --- a/matlab/gtsam_tests/testStereoVOExample.m +++ b/matlab/gtsam_tests/testStereoVOExample.m @@ -33,7 +33,7 @@ %% Create realistic calibration and measurement noise model % format: fx fy skew cx cy baseline K = Cal3_S2Stereo(1000, 1000, 0, 320, 240, 0.2); -stereo_model = noiseModel.Diagonal.Sigmas([1.0; 1.0; 1.0], true); +stereo_model = noiseModel.Diagonal.Sigmas([1.0; 1.0; 1.0]); %% Add measurements % pose 1