5ddaff8ba Merge pull request #77 from borglab/fix/template-as-template-arg 0b6f2d92b allow templates as paramters to templates 7f3e242b0 Merge pull request #76 from borglab/fix/cmake-config 0caa79b82 macro to find and configure matlab 522557232 fix GTWRAP_INCLUDE_NAME 78a5d3afa Use CMakePackageConfigHelpers to vastly simplify the package config 76f8b9e5d Merge pull request #75 from borglab/fix/template-args 3b8e8389e remove reference from shared pointers 045393c7b docs and flag renaming d23d8beae tests ef96b4bdc don't make template parameters as references d1e1dc697 Merge pull request #74 from borglab/fix/type-recursion 8202ecf10 minor fixes 5855ea85b support for passing templated types as arguments 150cc0578 Support for templated return types 5c58f8d03 Merge pull request #73 from borglab/fix/types-refactor c697aa9c8 refactored the basic and custom types to make it cleaner, added more tests 98e2c3fa1 Merge pull request #68 from borglab/fix/cmake c6d5e786a make config agnostic to install prefix 4d6999f15 Merge pull request #69 from borglab/feature/call-and-index ccf408804 add support for callable and indexing overloads 8f8e3ec93 add status messages 88566eca4 make WRAP_PYTHON_VERSION an optional argument 01b8368ad Merge pull request #67 from borglab/feature/operator-overloading 522a12801 remove unsupported operators 209346133 update check location for unary operator 39e290f60 fix small typo faa589bec update DOCS 7ff83cec8 minor fixes 8ce37766f fixed tests 21c477c4d include pybind11/operators a3534ac5e wrap operator overloads 67c8f2089 instantiate templates for operators e9dce65d8 use ReturnType for ease in other places and use members in Class 3078aa6db added parser rule for operator overloading git-subtree-dir: wrap git-subtree-split: 5ddaff8bab6c05e8a943c94993bf496e13296dd6 |
||
---|---|---|
.github/workflows | ||
cmake | ||
docs | ||
gtwrap | ||
pybind11 | ||
scripts | ||
sphinx | ||
templates | ||
tests | ||
utilities | ||
.gitignore | ||
CMakeLists.txt | ||
DOCS.md | ||
LICENSE | ||
README.md | ||
matlab.h | ||
requirements.txt | ||
setup.py |
README.md
WRAP
The wrap library wraps the GTSAM library into a Python library or MATLAB toolbox.
It was designed to be more general than just wrapping GTSAM. For notes on creating a wrap interface, see gtsam.h
for what features can be wrapped into a toolbox, as well as the current state of the toolbox for GTSAM.
Prerequisites
Pybind11
and pyparsing
- This library uses
pybind11
, which is included as a subdirectory in GTSAM. - The
interface_parser.py
in this library usespyparsing
to parse the interface filegtsam.h
. Please install it first in your current Python environment before attempting the build.
python3 -m pip install pyparsing
Getting Started
Clone this repository to your local machine and perform the standard CMake install:
mkdir build && cd build
cmake ..
make install # use sudo if needed
Using wrap
in your project is straightforward from here. In your CMakeLists.txt
file, you just need to add the following:
find_package(gtwrap)
pybind_wrap(${PROJECT_NAME}_py # target
${PROJECT_SOURCE_DIR}/cpp/${PROJECT_NAME}.h # interface header file
"${PROJECT_NAME}.cpp" # the generated cpp
"${PROJECT_NAME}" # module_name
"${PROJECT_MODULE_NAME}" # top namespace in the cpp file e.g. gtsam
"${ignore}" # ignore classes
${PROJECT_BINARY_DIR}/${PROJECT_NAME}.tpl # the wrapping template file
${PROJECT_NAME} # libs
"${PROJECT_NAME}" # dependencies
ON # use boost
)
For more information, please follow our tutorial.
Documentation
Documentation for wrapping C++ code can be found here.
Python Wrapper
WARNING: On macOS, you have to statically build GTSAM to use the wrapper.
-
Set
GTSAM_BUILD_PYTHON=ON
while configuring the build withcmake
. -
What you can do in the
build
folder:-
Just run python then import GTSAM and play around:
import gtsam gtsam.__dir__()
-
Run the unittests:
python -m unittest discover
-
Edit the unittests in
python/gtsam/*.py
and simply rerun the test. They were symlinked to<build_folder>/gtsam/*.py
to facilitate fast development.python -m unittest gtsam/tests/test_Pose3.py
- NOTE: You might need to re-runcmake ..
if files are deleted or added.
-
-
Do
make install
andcd <gtsam_install_folder>/python
. Here, you can:- Run the unittests:
python setup.py test
- Install
gtsam
to your current Python environment.python setup.py install
- NOTE: It's a good idea to create a virtual environment otherwise it will be installed in your system Python's site-packages.
- Run the unittests:
Matlab Wrapper
In the CMake, simply include the MatlabWrap.cmake
file.
include(MatlabWrap)
This cmake file defines functions for generating MATLAB wrappers.
wrap_and_install_library(interfaceHeader linkLibraries extraIncludeDirs extraMexFlags)
Generates wrap code and compiles the wrapper.
Usage example:
`wrap_and_install_library("lba.h" "" "" "")`
Arguments:
interfaceHeader
: The relative or absolute path to the wrapper interface definition file.linkLibraries
: Any additional libraries to link. Your project library (e.g.lba
), libraries it depends on, and any necessary MATLAB libraries will be linked automatically. So normally, leave this empty.extraIncludeDirs
: Any additional include paths required by dependent libraries that have not already been added by include_directories. Again, normally, leave this empty.extraMexFlags
: Any additional flags to pass to the compiler when building the wrap code. Normally, leave this empty.