2020-08-18 23:03:51 +08:00
# README
2019-09-17 04:03:59 +08:00
# Python Wrapper
2020-07-01 09:57:31 +08:00
This is the Python wrapper around the GTSAM C++ library. We use Cython to generate the bindings to the underlying C++ code.
2016-11-25 16:38:00 +08:00
2020-07-01 09:57:31 +08:00
## Requirements
2019-06-14 05:26:07 +08:00
2020-07-02 05:23:24 +08:00
- If you want to build the GTSAM python library for a specific python version (eg 3.6),
use the `-DGTSAM_PYTHON_VERSION=3.6` option when running `cmake` otherwise the default interpreter will be used.
- If the interpreter is inside an environment (such as an anaconda environment or virtualenv environment),
then the environment should be active while building GTSAM.
2020-07-01 09:57:31 +08:00
- This wrapper needs `Cython(>=0.25.2)` , `backports_abc(>=0.5)` , and `numpy(>=1.11.0)` . These can be installed as follows:
2016-11-25 16:38:00 +08:00
2020-07-01 09:57:31 +08:00
```bash
pip install -r < gtsam_folder > /cython/requirements.txt
```
2016-11-25 16:38:00 +08:00
2020-07-02 05:23:24 +08:00
- For compatibility with GTSAM's Eigen version, it contains its own cloned version of [Eigency ](https://github.com/wouterboomsma/eigency.git ),
named `gtsam_eigency` , to interface between C++'s Eigen and Python's numpy.
2020-07-01 09:57:31 +08:00
## Install
2016-11-25 16:38:00 +08:00
2020-07-02 05:23:24 +08:00
- Run cmake with the `GTSAM_INSTALL_CYTHON_TOOLBOX` cmake flag enabled to configure building the wrapper. The wrapped module will be built and copied to the directory defined by `GTSAM_CYTHON_INSTALL_PATH` , which is by default `<PROJECT_BINARY_DIR>/cython` in Release mode and `<PROJECT_BINARY_DIR>/cython<CMAKE_BUILD_TYPE>` for other modes.
2020-07-01 09:57:31 +08:00
- Build GTSAM and the wrapper with `make` .
2020-07-02 05:23:24 +08:00
- To install, simply run `make python-install` .
- The same command can be used to install into a virtual environment if it is active.
- **NOTE**: if you don't want GTSAM to install to a system directory such as `/usr/local` , pass `-DCMAKE_INSTALL_PREFIX="./install"` to cmake to install GTSAM to a subdirectory of the build directory.
- You can also directly run `make python-install` without running `make` , and it will compile all the dependencies accordingly.
2017-05-21 03:23:41 +08:00
2019-09-17 04:03:59 +08:00
## Unit Tests
2019-06-14 05:26:07 +08:00
2016-11-25 16:38:00 +08:00
The Cython toolbox also has a small set of unit tests located in the
test directory. To run them:
2020-07-02 05:23:24 +08:00
```bash
cd < GTSAM_CYTHON_INSTALL_PATH >
python -m unittest discover
```
## Utils
TODO
## Examples
TODO
2016-11-25 16:38:00 +08:00
2019-09-17 04:03:59 +08:00
## Writing Your Own Scripts
2019-06-14 05:26:07 +08:00
2016-11-25 16:38:00 +08:00
See the tests for examples.
2019-09-17 04:03:59 +08:00
### Some Important Notes:
2016-11-25 16:38:00 +08:00
2017-03-16 01:54:00 +08:00
- Vector/Matrix:
2020-07-02 05:23:24 +08:00
- GTSAM expects double-precision floating point vectors and matrices.
2020-07-01 09:57:31 +08:00
Hence, you should pass numpy matrices with `dtype=float` , or `float64` .
2020-07-02 05:23:24 +08:00
- Also, GTSAM expects _column-major_ matrices, unlike the default storage
scheme in numpy. Hence, you should pass column-major matrices to GTSAM using
2017-03-16 01:54:00 +08:00
the flag order='F'. And you always get column-major matrices back.
2020-07-01 09:57:31 +08:00
For more details, see [this link ](https://github.com/wouterboomsma/eigency#storage-layout---why-arrays-are-sometimes-transposed ).
2020-07-02 05:23:24 +08:00
- Passing row-major matrices of different dtype, e.g. `int` , will also work
2017-03-16 01:54:00 +08:00
as the wrapper converts them to column-major and dtype float for you,
using numpy.array.astype(float, order='F', copy=False).
However, this will result a copy if your matrix is not in the expected type
and storage order.
2016-11-25 16:38:00 +08:00
2020-07-02 05:23:24 +08:00
- Inner namespace: Classes in inner namespace will be prefixed by < innerNamespace > \_ in Python.
2020-07-01 09:57:31 +08:00
Examples: `noiseModel_Gaussian` , `noiseModel_mEstimator_Tukey`
2016-11-25 16:38:00 +08:00
- Casting from a base class to a derive class must be done explicitly.
2020-07-01 09:57:31 +08:00
Examples:
2020-07-02 05:23:24 +08:00
2020-07-01 09:57:31 +08:00
```python
noiseBase = factor.noiseModel()
noiseGaussian = dynamic_cast_noiseModel_Gaussian_noiseModel_Base(noiseBase)
```
## Wrapping Custom GTSAM-based Project
2020-07-02 05:23:24 +08:00
Please refer to the template project and the corresponding tutorial available [here ](https://github.com/borglab/GTSAM-project-python ).