Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use original name for templated global function #153

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gtwrap/template_instantiator/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def __init__(self, original, instantiations=(), new_name=''):
self.return_type = original.return_type
self.args = original.args
else:
self.name = instantiate_name(
original.name, instantiations) if not new_name else new_name
# Don't append template type to function name
self.name = original.name if not new_name else new_name
self.return_type = instantiate_return_type(
original.return_type,
self.original.template.typenames,
Expand Down
6 changes: 3 additions & 3 deletions tests/expected/matlab/DefaultFuncInt.m
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
function varargout = DefaultFuncInt(varargin)
if length(varargin) == 2 && isa(varargin{1},'numeric') && isa(varargin{2},'numeric')
functions_wrapper(8, varargin{:});
functions_wrapper(10, varargin{:});
elseif length(varargin) == 1 && isa(varargin{1},'numeric')
functions_wrapper(9, varargin{:});
functions_wrapper(11, varargin{:});
elseif length(varargin) == 0
functions_wrapper(10, varargin{:});
functions_wrapper(12, varargin{:});
else
error('Arguments do not match any overload of function DefaultFuncInt');
end
4 changes: 2 additions & 2 deletions tests/expected/matlab/DefaultFuncObj.m
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
function varargout = DefaultFuncObj(varargin)
if length(varargin) == 1 && isa(varargin{1},'gtsam.KeyFormatter')
functions_wrapper(14, varargin{:});
functions_wrapper(16, varargin{:});
elseif length(varargin) == 0
functions_wrapper(15, varargin{:});
functions_wrapper(17, varargin{:});
else
error('Arguments do not match any overload of function DefaultFuncObj');
end
6 changes: 3 additions & 3 deletions tests/expected/matlab/DefaultFuncString.m
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
function varargout = DefaultFuncString(varargin)
if length(varargin) == 2 && isa(varargin{1},'char') && isa(varargin{2},'char')
functions_wrapper(11, varargin{:});
functions_wrapper(13, varargin{:});
elseif length(varargin) == 1 && isa(varargin{1},'char')
functions_wrapper(12, varargin{:});
functions_wrapper(14, varargin{:});
elseif length(varargin) == 0
functions_wrapper(13, varargin{:});
functions_wrapper(15, varargin{:});
else
error('Arguments do not match any overload of function DefaultFuncString');
end
6 changes: 3 additions & 3 deletions tests/expected/matlab/DefaultFuncVector.m
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
function varargout = DefaultFuncVector(varargin)
if length(varargin) == 2 && isa(varargin{1},'std.vectornumeric') && isa(varargin{2},'std.vectorchar')
functions_wrapper(20, varargin{:});
functions_wrapper(22, varargin{:});
elseif length(varargin) == 1 && isa(varargin{1},'std.vectornumeric')
functions_wrapper(21, varargin{:});
functions_wrapper(23, varargin{:});
elseif length(varargin) == 0
functions_wrapper(22, varargin{:});
functions_wrapper(24, varargin{:});
else
error('Arguments do not match any overload of function DefaultFuncVector');
end
8 changes: 4 additions & 4 deletions tests/expected/matlab/DefaultFuncZero.m
Original file line number Diff line number Diff line change
@@ -1,12 +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},'numeric') && isa(varargin{5},'logical')
functions_wrapper(16, varargin{:});
functions_wrapper(18, 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{:});
functions_wrapper(19, varargin{:});
elseif length(varargin) == 3 && isa(varargin{1},'numeric') && isa(varargin{2},'numeric') && isa(varargin{3},'double')
functions_wrapper(18, varargin{:});
functions_wrapper(20, varargin{:});
elseif length(varargin) == 2 && isa(varargin{1},'numeric') && isa(varargin{2},'numeric')
functions_wrapper(19, varargin{:});
functions_wrapper(21, varargin{:});
else
error('Arguments do not match any overload of function DefaultFuncZero');
end
8 changes: 8 additions & 0 deletions tests/expected/matlab/MultiTemplatedFunction.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function varargout = MultiTemplatedFunction(varargin)
if length(varargin) == 2 && isa(varargin{1},'char') && isa(varargin{2},'numeric')
varargout{1} = functions_wrapper(8, varargin{:});
elseif length(varargin) == 2 && isa(varargin{1},'double') && isa(varargin{2},'numeric')
varargout{1} = functions_wrapper(9, varargin{:});
else
error('Arguments do not match any overload of function MultiTemplatedFunction');
end

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion tests/expected/matlab/TemplatedFunctionRot3.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function varargout = TemplatedFunctionRot3(varargin)
if length(varargin) == 1 && isa(varargin{1},'gtsam.Rot3')
functions_wrapper(25, varargin{:});
functions_wrapper(27, varargin{:});
else
error('Arguments do not match any overload of function TemplatedFunctionRot3');
end
100 changes: 59 additions & 41 deletions tests/expected/matlab/functions_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,68 +109,80 @@ void overloadedGlobalFunction_5(int nargout, mxArray *out[], int nargin, const m
double b = unwrap< double >(in[1]);
out[0] = wrap< Vector >(overloadedGlobalFunction(a,b));
}
void MultiTemplatedFunctionStringSize_tDouble_6(int nargout, mxArray *out[], int nargin, const mxArray *in[])
void TemplatedFunction_6(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
checkArguments("MultiTemplatedFunctionStringSize_tDouble",nargout,nargin,2);
T& x = *unwrap_shared_ptr< T >(in[0], "ptr_T");
checkArguments("TemplatedFunction",nargout,nargin,1);
gtsam::Rot3& t = *unwrap_shared_ptr< gtsam::Rot3 >(in[0], "ptr_gtsamRot3");
TemplatedFunction(t);
}
void TemplatedFunction_7(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
checkArguments("TemplatedFunction",nargout,nargin,1);
gtsam::Pose3& t = *unwrap_shared_ptr< gtsam::Pose3 >(in[0], "ptr_gtsamPose3");
TemplatedFunction(t);
}
void MultiTemplatedFunction_8(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
checkArguments("MultiTemplatedFunction",nargout,nargin,2);
string& x = *unwrap_shared_ptr< string >(in[0], "ptr_string");
size_t y = unwrap< size_t >(in[1]);
out[0] = wrap< double >(MultiTemplatedFunctionStringSize_tDouble(x,y));
out[0] = wrap< double >(MultiTemplatedFunction(x,y));
}
void MultiTemplatedFunctionDoubleSize_tDouble_7(int nargout, mxArray *out[], int nargin, const mxArray *in[])
void MultiTemplatedFunction_9(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
checkArguments("MultiTemplatedFunctionDoubleSize_tDouble",nargout,nargin,2);
T& x = *unwrap_shared_ptr< T >(in[0], "ptr_T");
checkArguments("MultiTemplatedFunction",nargout,nargin,2);
double x = unwrap< double >(in[0]);
size_t y = unwrap< size_t >(in[1]);
out[0] = wrap< double >(MultiTemplatedFunctionDoubleSize_tDouble(x,y));
out[0] = wrap< double >(MultiTemplatedFunction(x,y));
}
void DefaultFuncInt_8(int nargout, mxArray *out[], int nargin, const mxArray *in[])
void DefaultFuncInt_10(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
checkArguments("DefaultFuncInt",nargout,nargin,2);
int a = unwrap< int >(in[0]);
int b = unwrap< int >(in[1]);
DefaultFuncInt(a,b);
}
void DefaultFuncInt_9(int nargout, mxArray *out[], int nargin, const mxArray *in[])
void DefaultFuncInt_11(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[])
void DefaultFuncInt_12(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[])
void DefaultFuncString_13(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 DefaultFuncString_12(int nargout, mxArray *out[], int nargin, const mxArray *in[])
void DefaultFuncString_14(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[])
void DefaultFuncString_15(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[])
void DefaultFuncObj_16(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 DefaultFuncObj_15(int nargout, mxArray *out[], int nargin, const mxArray *in[])
void DefaultFuncObj_17(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[])
void DefaultFuncZero_18(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
checkArguments("DefaultFuncZero",nargout,nargin,5);
int a = unwrap< int >(in[0]);
Expand All @@ -180,7 +192,7 @@ void DefaultFuncZero_16(int nargout, mxArray *out[], int nargin, const mxArray *
bool e = unwrap< bool >(in[4]);
DefaultFuncZero(a,b,c,d,e);
}
void DefaultFuncZero_17(int nargout, mxArray *out[], int nargin, const mxArray *in[])
void DefaultFuncZero_19(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
checkArguments("DefaultFuncZero",nargout,nargin,4);
int a = unwrap< int >(in[0]);
Expand All @@ -189,51 +201,51 @@ void DefaultFuncZero_17(int nargout, mxArray *out[], int nargin, const mxArray *
int d = unwrap< int >(in[3]);
DefaultFuncZero(a,b,c,d,false);
}
void DefaultFuncZero_18(int nargout, mxArray *out[], int nargin, const mxArray *in[])
void DefaultFuncZero_20(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[])
void DefaultFuncZero_21(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[])
void DefaultFuncVector_22(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
checkArguments("DefaultFuncVector",nargout,nargin,2);
std::vector<int>& i = *unwrap_shared_ptr< std::vector<int> >(in[0], "ptr_stdvectorint");
std::vector<string>& s = *unwrap_shared_ptr< std::vector<string> >(in[1], "ptr_stdvectorstring");
DefaultFuncVector(i,s);
}
void DefaultFuncVector_21(int nargout, mxArray *out[], int nargin, const mxArray *in[])
void DefaultFuncVector_23(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
checkArguments("DefaultFuncVector",nargout,nargin,1);
std::vector<int>& i = *unwrap_shared_ptr< std::vector<int> >(in[0], "ptr_stdvectorint");
DefaultFuncVector(i,{"borglab", "gtsam"});
}
void DefaultFuncVector_22(int nargout, mxArray *out[], int nargin, const mxArray *in[])
void DefaultFuncVector_24(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[])
void setPose_25(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 setPose_24(int nargout, mxArray *out[], int nargin, const mxArray *in[])
void setPose_26(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[])
void TemplatedFunctionRot3_27(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");
Expand Down Expand Up @@ -270,40 +282,40 @@ void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
overloadedGlobalFunction_5(nargout, out, nargin-1, in+1);
break;
case 6:
MultiTemplatedFunctionStringSize_tDouble_6(nargout, out, nargin-1, in+1);
TemplatedFunction_6(nargout, out, nargin-1, in+1);
break;
case 7:
MultiTemplatedFunctionDoubleSize_tDouble_7(nargout, out, nargin-1, in+1);
TemplatedFunction_7(nargout, out, nargin-1, in+1);
break;
case 8:
DefaultFuncInt_8(nargout, out, nargin-1, in+1);
MultiTemplatedFunction_8(nargout, out, nargin-1, in+1);
break;
case 9:
DefaultFuncInt_9(nargout, out, nargin-1, in+1);
MultiTemplatedFunction_9(nargout, out, nargin-1, in+1);
break;
case 10:
DefaultFuncInt_10(nargout, out, nargin-1, in+1);
break;
case 11:
DefaultFuncString_11(nargout, out, nargin-1, in+1);
DefaultFuncInt_11(nargout, out, nargin-1, in+1);
break;
case 12:
DefaultFuncString_12(nargout, out, nargin-1, in+1);
DefaultFuncInt_12(nargout, out, nargin-1, in+1);
break;
case 13:
DefaultFuncString_13(nargout, out, nargin-1, in+1);
break;
case 14:
DefaultFuncObj_14(nargout, out, nargin-1, in+1);
DefaultFuncString_14(nargout, out, nargin-1, in+1);
break;
case 15:
DefaultFuncObj_15(nargout, out, nargin-1, in+1);
DefaultFuncString_15(nargout, out, nargin-1, in+1);
break;
case 16:
DefaultFuncZero_16(nargout, out, nargin-1, in+1);
DefaultFuncObj_16(nargout, out, nargin-1, in+1);
break;
case 17:
DefaultFuncZero_17(nargout, out, nargin-1, in+1);
DefaultFuncObj_17(nargout, out, nargin-1, in+1);
break;
case 18:
DefaultFuncZero_18(nargout, out, nargin-1, in+1);
Expand All @@ -312,22 +324,28 @@ void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
DefaultFuncZero_19(nargout, out, nargin-1, in+1);
break;
case 20:
DefaultFuncVector_20(nargout, out, nargin-1, in+1);
DefaultFuncZero_20(nargout, out, nargin-1, in+1);
break;
case 21:
DefaultFuncVector_21(nargout, out, nargin-1, in+1);
DefaultFuncZero_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);
DefaultFuncVector_23(nargout, out, nargin-1, in+1);
break;
case 24:
setPose_24(nargout, out, nargin-1, in+1);
DefaultFuncVector_24(nargout, out, nargin-1, in+1);
break;
case 25:
TemplatedFunctionRot3_25(nargout, out, nargin-1, in+1);
setPose_25(nargout, out, nargin-1, in+1);
break;
case 26:
setPose_26(nargout, out, nargin-1, in+1);
break;
case 27:
TemplatedFunctionRot3_27(nargout, out, nargin-1, in+1);
break;
}
} catch(const std::exception& e) {
Expand Down
4 changes: 2 additions & 2 deletions tests/expected/matlab/setPose.m
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
function varargout = setPose(varargin)
if length(varargin) == 1 && isa(varargin{1},'gtsam.Pose3')
functions_wrapper(23, varargin{:});
functions_wrapper(25, varargin{:});
elseif length(varargin) == 0
functions_wrapper(24, varargin{:});
functions_wrapper(26, varargin{:});
else
error('Arguments do not match any overload of function setPose');
end
8 changes: 5 additions & 3 deletions tests/expected/python/functions_pybind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@ PYBIND11_MODULE(functions_py, m_) {
m_.def("aGlobalFunction",[](){return ::aGlobalFunction();});
m_.def("overloadedGlobalFunction",[](int a){return ::overloadedGlobalFunction(a);}, py::arg("a"));
m_.def("overloadedGlobalFunction",[](int a, double b){return ::overloadedGlobalFunction(a, b);}, py::arg("a"), py::arg("b"));
m_.def("MultiTemplatedFunctionStringSize_tDouble",[](const T& x, size_t y){return ::MultiTemplatedFunction<string,size_t,double>(x, y);}, py::arg("x"), py::arg("y"));
m_.def("MultiTemplatedFunctionDoubleSize_tDouble",[](const T& x, size_t y){return ::MultiTemplatedFunction<double,size_t,double>(x, y);}, py::arg("x"), py::arg("y"));
m_.def("TemplatedFunction",[](const gtsam::Rot3& t){ ::TemplatedFunction<gtsam::Rot3>(t);}, py::arg("t"));
m_.def("TemplatedFunction",[](const gtsam::Pose3& t){ ::TemplatedFunction<gtsam::Pose3>(t);}, py::arg("t"));
m_.def("MultiTemplatedFunction",[](const string& x, size_t y){return ::MultiTemplatedFunction<string,size_t,double>(x, y);}, py::arg("x"), py::arg("y"));
m_.def("MultiTemplatedFunction",[](const double& x, size_t y){return ::MultiTemplatedFunction<double,size_t,double>(x, y);}, py::arg("x"), py::arg("y"));
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, 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<int>& i, const std::vector<string>& 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<gtsam::Rot3>(t);}, py::arg("t"));
m_.def("TemplatedFunctionRot3",[](const gtsam::Rot3& t){ ::TemplatedFunction2<gtsam::Rot3>(t);}, py::arg("t"));

#include "python/specializations.h"

Expand Down
Loading