There are python wrappers for some C++ types. I am using pybind11 which has great documentation and many examples. pybind11 is just a header only library that makes it easy to write python extensions, https://thomasnyberg.com/what_are_extension_modules.html .
The C++ sources need to be compiled as a shared library to be imported by python.
I am using cppimport to do this automatically on import but it is theoretically possible to compile using cmake, pio, pip ...
To test the compilation run python estimatortest/pythonwrapper/test_compilation.py Which should print a bunch of compiler errors if there is a mistake.
psim/estimatortest/pwrap.cpp Is the main module file.
The giant comment at the top is used in a python script that sets the compiler configuration.
cfg['dependencies'] is a list of filenames that are checked for changes to see if recompiling is needed.
cfg['sources'] are the sources to compile.
cfg['include_dirs'] are the include directories.
cfg['compiler_args'] are the compiler args, I also made a section for platform specific compiler args because my mac needed '-mmacosx-version-min=10.9' to compile.
orb wrappers
psim/estimatortest/orb_ext.cpp Has the orb wrappers.
For now orb::Orbit as python type orb_Orbit is mostly wrapped.
lin wrappers
psim/estimatortest/lin_ext.cpp Has the lin wrappers.
These create python types named lin_Matrix6x6d and lin_Vector3d
for C++ types lin::Matrix<double, 6, 6, 6, 6> and lin::Vector<double, 3, 3>.
These are compatible with numpy arrays, so numpy.array(lin_Vector3d([1.0,2.0,3.0])) will work.
The wrapper doesn't wrap all of the lin features, so it's usually best to always convert the lin types into numpy arrays if you want to do math with them in python.
If you need other lin types in python make sure to wrap them in this file using the macros.
Python lin and orb Wrappers
Fixes #215
Python Wrappers
There are python wrappers for some C++ types. I am using pybind11 which has great documentation and many examples. pybind11 is just a header only library that makes it easy to write python extensions, https://thomasnyberg.com/what_are_extension_modules.html .
The C++ sources need to be compiled as a shared library to be imported by python. I am using cppimport to do this automatically on import but it is theoretically possible to compile using cmake, pio, pip ...
To test the compilation run
python estimatortest/pythonwrapper/test_compilation.py
Which should print a bunch of compiler errors if there is a mistake.psim/estimatortest/pwrap.cpp
Is the main module file.The giant comment at the top is used in a python script that sets the compiler configuration.
cfg['dependencies']
is a list of filenames that are checked for changes to see if recompiling is needed.cfg['sources']
are the sources to compile.cfg['include_dirs']
are the include directories.cfg['compiler_args']
are the compiler args, I also made a section for platform specific compiler args because my mac needed'-mmacosx-version-min=10.9'
to compile.orb wrappers
psim/estimatortest/orb_ext.cpp
Has theorb
wrappers.For now
orb::Orbit
as python typeorb_Orbit
is mostly wrapped.lin wrappers
psim/estimatortest/lin_ext.cpp
Has thelin
wrappers.Most of this file is from https://pybind11.readthedocs.io/en/stable/advanced/pycpp/numpy.html examples.
Because
lin
uses templates, each type that you want to use in python must be specifically wrapped. For example, right now inlin_ext.cpp
I have:These create python types named
lin_Matrix6x6d
andlin_Vector3d
for C++ typeslin::Matrix<double, 6, 6, 6, 6>
andlin::Vector<double, 3, 3>
. These are compatible with numpy arrays, so numpy.array(lin_Vector3d([1.0,2.0,3.0])) will work. The wrapper doesn't wrap all of thelin
features, so it's usually best to always convert the lin types into numpy arrays if you want to do math with them in python.If you need other
lin
types in python make sure to wrap them in this file using the macros.Testing
I am using pytest to test the wrappers in CI.