56 lines
1.1 KiB
Markdown
56 lines
1.1 KiB
Markdown
# python_cpp_example
|
|
|
|
Minimal example building a C++ python extension.
|
|
|
|
Useful links:
|
|
* [Using NumPy C-API](https://numpy.org/doc/stable/user/c-info.html)
|
|
|
|
|
|
### Build instructions
|
|
|
|
**Simplified build using make**
|
|
```bash
|
|
$ make #build c extension inplace
|
|
```
|
|
|
|
```
|
|
$ make help
|
|
clean Remove the build folder and the shared library
|
|
debug Build extension with debug prints and assertions
|
|
ext [DEFAULT] build c extension in place
|
|
test Run unit tests using pytest
|
|
```
|
|
|
|
**Manual build**
|
|
```bash
|
|
|
|
#build in place and use from the same folder
|
|
#sometimes necessary to remove build folder and .so
|
|
#by hand
|
|
$ python setup.py build_ext --inplace
|
|
```
|
|
|
|
|
|
|
|
To use make sure that the .so and potentially python files are in PYTHONPATH (or installed in developer mode)
|
|
|
|
```bash
|
|
#conda
|
|
$ conda develop install .
|
|
|
|
#or with pip
|
|
$ pip install --editable .
|
|
```
|
|
|
|
## Cluster file specifications
|
|
|
|
```
|
|
[int32 frame_number][int32 n_clusters][clusters....]
|
|
|
|
// Cluster data type
|
|
typedef struct {
|
|
int16_t x;
|
|
int16_t y;
|
|
int32_t data[9];
|
|
} Cluster ;
|
|
``` |