dantrim / hamming-codec

Simple encode/decode utilties for bit-error correcting Hamming codes
MIT License
15 stars 4 forks source link

Create `C++` encode decode wrappers using pybind11 #2

Closed dantrim closed 3 years ago

dantrim commented 3 years ago

What

This PR adds pybind11 support for C++ embeddings of the hamming_codec python module. This allows for a shared object file to be built using the usual cmake installation procedures that can then be linked against in a C++ utility.

C++ encode and decode utilities

This PR adds two C++ executables encode and decode that more or less give the same behavior as the python entrypoints for hamming:

$ hamming encode 0x4235 16
0x8a3ac 21

vs.

./build/bin/encode 0x4235 16
0x8a3ac 21

The C++ executables are simple wrappers around the same hamming_codec module functions.

The motivation for wanting to have a standalone C++ shared object is for future utilties that I may build that are purely C++ (e.g. for projects in the ATLAS experiment that may need to encode/decode Hamming encoded quantities within C++ libraries).

Notes

The C++ embedding seems to only work in python<=3.8.2. I could not get it to work properly in python==3.8.5.

The cmake configuration step checks for whether you are in a virtual environment or if there is a defined PYTHONPATH environment, with priority given to the former. From this it bases how to load the hamming_codec module in the C++ hamming_codec wrapper by pre-pending those values to sys.path.

TODO

Document installation and requirements.