29628426d Merge pull request #59 from borglab/fixes a95429ea0 Merge pull request #56 from borglab/fix/this-instantiation 3e22d6516 more documenatation and some formatting 526301499 updated the test to test for non-templated This cdb75f36f Merge branch 'master' into fix/this-instantiation 0f5ae3b7f moved example pybind template to templates directory d55f5db38 remove extra whitespace 21891ad3d skip tests until we figure out what's going on 2ea6307c3 better way of handling the matlab includes in the matlab wrapper d0f8a392c Merge pull request #55 from borglab/feature/refactor3 57d47cbd9 create directories to store generated output 4788a1e37 fixed This instantiation 61d2cbfc4 add namespace test to matlab wrapper ec39023e6 added more, smaller tests for Python wrapper 19c35b857 test for matlab class inheritance and some clean up 06ca5da13 test for matlab functions cb05d7379 minor clean up and separate tests for geometry and class 8d8145cc4 break down test interface file into smaller files that can be easily debugged 97328f057 restructured test files and added dedicated fixtures directory git-subtree-dir: wrap git-subtree-split: 29628426d2c1a7bb728e40307c0f25cb468cd1bc |
||
|---|---|---|
| .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.pyin this library usespyparsingto 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=ONwhile configuring the build withcmake. -
What you can do in the
buildfolder:-
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/*.pyand simply rerun the test. They were symlinked to<build_folder>/gtsam/*.pyto 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 installandcd <gtsam_install_folder>/python. Here, you can:- Run the unittests:
python setup.py test - Install
gtsamto 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.