Skip to content

Commit

Permalink
Squashed 'wrap/' changes from 9a467794e..96ccdfd0b
Browse files Browse the repository at this point in the history
96ccdfd0b Merge pull request #65 from borglab/fix/special-cases
04c06b7e6 Merge pull request #63 from borglab/fix/cmake
bf2c91bd2 fix issue in template instantiation generator
152dbcb12 test for special cases
d03004b24 fixed the cmake to discover the correct python version and set all corresponding variables
4cf66e0da Merge pull request #61 from borglab/fix/python-variables
80558e35b added more status messages and set the PYBIND11_PYTHON_VERSION each time
73afd1b0a set both sets of Python variables and find python version when including PybindWrap
REVERT: 9a467794e Merge pull request #61 from borglab/fix/python-variables
REVERT: 6bae7af99 added more status messages and set the PYBIND11_PYTHON_VERSION each time
REVERT: 5129cf3b9 set both sets of Python variables and find python version when including PybindWrap

git-subtree-dir: wrap
git-subtree-split: 96ccdfd0b84a4dbf1b3e9ed31b95ebc2758be9cc
  • Loading branch information
varunagrawal committed Mar 26, 2021
1 parent 34aae4f commit c78ca4b
Show file tree
Hide file tree
Showing 10 changed files with 542 additions and 24 deletions.
35 changes: 23 additions & 12 deletions cmake/GtwrapUtils.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Utilities to help with wrapping.

# Use CMake's find_package to find the version of Python installed.
macro(get_python_version)
if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
# Use older version of cmake's find_python
Expand All @@ -13,6 +14,23 @@ macro(get_python_version)

find_package(PythonLibs ${PYTHON_VERSION_STRING})

else()
# Get info about the Python interpreter
# https://cmake.org/cmake/help/latest/module/FindPython.html#module:FindPython
find_package(Python COMPONENTS Interpreter Development)

if(NOT ${Python_FOUND})
message(
FATAL_ERROR
"Cannot find Python interpreter. Please install Python>=3.5.")
endif()

endif()
endmacro()

# Depending on the version of CMake, ensure all the appropriate variables are set.
macro(configure_python_variables)
if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
set(Python_VERSION_MAJOR
${PYTHON_VERSION_MAJOR}
CACHE INTERNAL "")
Expand All @@ -24,19 +42,9 @@ macro(get_python_version)
CACHE INTERNAL "")
set(Python_EXECUTABLE
${PYTHON_EXECUTABLE}
CACHE INTERNAL "")
CACHE PATH "")

else()
# Get info about the Python interpreter
# https://cmake.org/cmake/help/latest/module/FindPython.html#module:FindPython
find_package(Python COMPONENTS Interpreter Development)

if(NOT ${Python_FOUND})
message(
FATAL_ERROR
"Cannot find Python interpreter. Please install Python>=3.5.")
endif()

# Set both sets of variables
set(PYTHON_VERSION_MAJOR
${Python_VERSION_MAJOR}
Expand All @@ -49,7 +57,7 @@ macro(get_python_version)
CACHE INTERNAL "")
set(PYTHON_EXECUTABLE
${Python_EXECUTABLE}
CACHE INTERNAL "")
CACHE PATH "")

endif()
endmacro()
Expand Down Expand Up @@ -85,4 +93,7 @@ macro(gtwrap_get_python_version WRAP_PYTHON_VERSION)
EXACT)
endif()

# (Always) Configure the variables once we find the python package
configure_python_variables()

endmacro()
4 changes: 2 additions & 2 deletions cmake/PybindWrap.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ endif()

# Get the Python version
include(GtwrapUtils)
message(status "Checking Python Version")
message(STATUS "Checking Python Version")
gtwrap_get_python_version(${WRAP_PYTHON_VERSION})

message(status "Setting Python version for wrapper")
message(STATUS "Setting Python version for wrapper")
set(PYBIND11_PYTHON_VERSION ${WRAP_PYTHON_VERSION})

# User-friendly Pybind11 wrapping and installing function.
Expand Down
10 changes: 4 additions & 6 deletions gtwrap/template_instantiator.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class InstantiatedMethod(parser.Method):
"""
We can only instantiate template methods with a single template parameter.
"""
def __init__(self, original, instantiations=''):
def __init__(self, original, instantiations: List[parser.Typename]=''):
self.original = original
self.instantiations = instantiations
self.template = ''
Expand Down Expand Up @@ -246,11 +246,9 @@ def __init__(self, original, instantiations=''):
def to_cpp(self):
"""Generate the C++ code for wrapping."""
if self.original.template:
instantiation_list = [
# Get the fully qualified name
"::".join(x.namespaces + [x.name])
for x in self.instantiations
]
# to_cpp will handle all the namespacing and templating
instantiation_list = [x.to_cpp() for x in self.instantiations]
# now can simply combine the instantiations, separated by commas
ret = "{}<{}>".format(self.original.name,
",".join(instantiation_list))
else:
Expand Down
44 changes: 44 additions & 0 deletions tests/expected/matlab/+gtsam/NonlinearFactorGraph.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
%class NonlinearFactorGraph, see Doxygen page for details
%at https://gtsam.org/doxygen/
%
%-------Methods-------
%addPriorPinholeCameraCal3Bundler(size_t key, PinholeCamera<Cal3Bundler> prior, Base noiseModel) : returns void
%
classdef NonlinearFactorGraph < handle
properties
ptr_gtsamNonlinearFactorGraph = 0
end
methods
function obj = NonlinearFactorGraph(varargin)
if nargin == 2 && isa(varargin{1}, 'uint64') && varargin{1} == uint64(5139824614673773682)
my_ptr = varargin{2};
special_cases_wrapper(0, my_ptr);
else
error('Arguments do not match any overload of gtsam.NonlinearFactorGraph constructor');
end
obj.ptr_gtsamNonlinearFactorGraph = my_ptr;
end

function delete(obj)
special_cases_wrapper(1, obj.ptr_gtsamNonlinearFactorGraph);
end

function display(obj), obj.print(''); end
%DISPLAY Calls print on the object
function disp(obj), obj.display; end
%DISP Calls print on the object
function varargout = addPriorPinholeCameraCal3Bundler(this, varargin)
% ADDPRIORPINHOLECAMERACAL3BUNDLER usage: addPriorPinholeCameraCal3Bundler(size_t key, PinholeCamera<Cal3Bundler> prior, Base noiseModel) : returns void
% Doxygen can be found at https://gtsam.org/doxygen/
if length(varargin) == 3 && isa(varargin{1},'numeric') && isa(varargin{2},'gtsam.PinholeCameraCal3Bundler') && isa(varargin{3},'gtsam.noiseModel.Base')
special_cases_wrapper(2, this, varargin{:});
return
end
error('Arguments do not match any overload of function gtsam.NonlinearFactorGraph.addPriorPinholeCameraCal3Bundler');
end

end

methods(Static = true)
end
end
31 changes: 31 additions & 0 deletions tests/expected/matlab/+gtsam/PinholeCameraCal3Bundler.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
%class PinholeCameraCal3Bundler, see Doxygen page for details
%at https://gtsam.org/doxygen/
%
classdef PinholeCameraCal3Bundler < handle
properties
ptr_gtsamPinholeCameraCal3Bundler = 0
end
methods
function obj = PinholeCameraCal3Bundler(varargin)
if nargin == 2 && isa(varargin{1}, 'uint64') && varargin{1} == uint64(5139824614673773682)
my_ptr = varargin{2};
special_cases_wrapper(3, my_ptr);
else
error('Arguments do not match any overload of gtsam.PinholeCameraCal3Bundler constructor');
end
obj.ptr_gtsamPinholeCameraCal3Bundler = my_ptr;
end

function delete(obj)
special_cases_wrapper(4, obj.ptr_gtsamPinholeCameraCal3Bundler);
end

function display(obj), obj.print(''); end
%DISPLAY Calls print on the object
function disp(obj), obj.display; end
%DISP Calls print on the object
end

methods(Static = true)
end
end
Loading

0 comments on commit c78ca4b

Please sign in to comment.