|
|
||
|---|---|---|
| .. | ||
| .github/workflows | ||
| cmake | ||
| docs | ||
| pybind11 | ||
| sphinx | ||
| tests | ||
| utilities | ||
| .gitignore | ||
| README.md | ||
| interface_parser.py | ||
| matlab.h | ||
| matlab_wrapper.py | ||
| pybind_wrapper.py | ||
| pybind_wrapper.tpl.example | ||
| requirements.txt | ||
| template_instantiator.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
GTSAM 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-run
cmake ..if files are deleted or added.
- NOTE: You might need to re-run
-
- 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:
Old GTSAM Wrapper
Outdated note from the original wrap.
TODO: Update this.
It was designed to be more general than just wrapping GTSAM, but a small amount of GTSAM specific code exists in matlab.h, the include file that is included by the mex files. The GTSAM-specific functionality consists primarily of handling of Eigen Matrix and Vector classes.
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. For more technical details on the interface, please read comments in matlab.h
Some good things to know:
OBJECT CREATION
- Classes are created by special constructors, e.g.,
new_GaussianFactorGraph_.cpp. These constructors are called from the MATLAB class@GaussianFactorGraph.new_GaussianFactorGraph_calls wrap_constructed inmatlab.h, see documentation there
METHOD (AND CONSTRUCTOR) ARGUMENTS
- Simple argument types of methods, such as "double", will be converted in the
mexwrappers by calling unwrap, defined in matlab.h - Vector and Matrix arguments are normally passed by reference in GTSAM, but
in
gtsam.hyou need to pretend they are passed by value, to trigger the generation of the correct conversion routinesunwrap<Vector>andunwrap<Matrix> - passing classes as arguments works, provided they are passed by reference. This triggers a call to unwrap_shared_ptr