diff options
author | Josh Morman <mormjb@gmail.com> | 2020-04-23 11:02:25 -0400 |
---|---|---|
committer | Josh Morman <mormjb@gmail.com> | 2020-06-04 10:05:48 -0400 |
commit | a4e6d4d55b35ac36dd5915dec5145073d8ec3b9a (patch) | |
tree | 57f496e1316783cf0e05af0e530bc181e0bd3de0 /gr-wavelet/python | |
parent | 2a5cb62885ab46ae0d8594bee26e256baed9813b (diff) |
wavelet: add pybind11 bindings
Diffstat (limited to 'gr-wavelet/python')
10 files changed, 260 insertions, 9 deletions
diff --git a/gr-wavelet/python/wavelet/CMakeLists.txt b/gr-wavelet/python/wavelet/CMakeLists.txt index 0942522f39..a1fbf173b9 100644 --- a/gr-wavelet/python/wavelet/CMakeLists.txt +++ b/gr-wavelet/python/wavelet/CMakeLists.txt @@ -23,12 +23,6 @@ if(ENABLE_TESTING) set(GR_TEST_LIBRARY_DIRS "") set(GR_TEST_PYTHON_DIRS ${CMAKE_BINARY_DIR}/gnuradio-runtime/python - ${CMAKE_BINARY_DIR}/gnuradio-runtime/swig - ${CMAKE_BINARY_DIR}/gr-blocks/swig - ${CMAKE_BINARY_DIR}/gr-filter/swig - ${CMAKE_BINARY_DIR}/gr-fft/swig - ${CMAKE_BINARY_DIR}/gr-analog/swig - ${CMAKE_BINARY_DIR}/gr-wavelet/swig ) include(GrTest) @@ -38,3 +32,5 @@ if(ENABLE_TESTING) GR_ADD_TEST(${py_qa_test_name} ${QA_PYTHON_EXECUTABLE} -B ${py_qa_test_file}) endforeach(py_qa_test_file) endif(ENABLE_TESTING) + +add_subdirectory(bindings) diff --git a/gr-wavelet/python/wavelet/__init__.py b/gr-wavelet/python/wavelet/__init__.py index ab8c19a4b4..b4eecf24d2 100644 --- a/gr-wavelet/python/wavelet/__init__.py +++ b/gr-wavelet/python/wavelet/__init__.py @@ -14,8 +14,8 @@ from __future__ import unicode_literals import os try: - from .wavelet_swig import * + from .wavelet_python import * except ImportError: dirname, filename = os.path.split(os.path.abspath(__file__)) - __path__.append(os.path.join(dirname, "..", "..", "swig")) - from .wavelet_swig import * + __path__.append(os.path.join(dirname, "bindings")) + from .wavelet_python import * diff --git a/gr-wavelet/python/wavelet/bindings/CMakeLists.txt b/gr-wavelet/python/wavelet/bindings/CMakeLists.txt new file mode 100644 index 0000000000..e79c373fc7 --- /dev/null +++ b/gr-wavelet/python/wavelet/bindings/CMakeLists.txt @@ -0,0 +1,18 @@ +include(GrPybind) + +######################################################################## +# Python Bindings +######################################################################## + +list(APPEND wavelet_python_files + squash_ff_python.cc + wavelet_ff_python.cc + wvps_ff_python.cc + python_bindings.cc) + +GR_PYBIND_MAKE(wavelet + ../../.. + gr::wavelet + "${wavelet_python_files}") + +install(TARGETS wavelet_python DESTINATION ${GR_PYTHON_DIR}/gnuradio/wavelet COMPONENT pythonapi) diff --git a/gr-wavelet/python/wavelet/bindings/docstrings/squash_ff_pydoc_template.h b/gr-wavelet/python/wavelet/bindings/docstrings/squash_ff_pydoc_template.h new file mode 100644 index 0000000000..91d631be43 --- /dev/null +++ b/gr-wavelet/python/wavelet/bindings/docstrings/squash_ff_pydoc_template.h @@ -0,0 +1,24 @@ +/* + * Copyright 2020 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ +#include "pydoc_macros.h" +#define D(...) DOC(gr, wavelet, __VA_ARGS__) +/* + This file contains placeholders for docstrings for the Python bindings. + Do not edit! These were automatically extracted during the binding process + and will be overwritten during the build process + */ + + +static const char* __doc_gr_wavelet_squash_ff = R"doc()doc"; + + +static const char* __doc_gr_wavelet_squash_ff_squash_ff = R"doc()doc"; + + +static const char* __doc_gr_wavelet_squash_ff_make = R"doc()doc"; diff --git a/gr-wavelet/python/wavelet/bindings/docstrings/wavelet_ff_pydoc_template.h b/gr-wavelet/python/wavelet/bindings/docstrings/wavelet_ff_pydoc_template.h new file mode 100644 index 0000000000..3d542abece --- /dev/null +++ b/gr-wavelet/python/wavelet/bindings/docstrings/wavelet_ff_pydoc_template.h @@ -0,0 +1,24 @@ +/* + * Copyright 2020 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ +#include "pydoc_macros.h" +#define D(...) DOC(gr, wavelet, __VA_ARGS__) +/* + This file contains placeholders for docstrings for the Python bindings. + Do not edit! These were automatically extracted during the binding process + and will be overwritten during the build process + */ + + +static const char* __doc_gr_wavelet_wavelet_ff = R"doc()doc"; + + +static const char* __doc_gr_wavelet_wavelet_ff_wavelet_ff = R"doc()doc"; + + +static const char* __doc_gr_wavelet_wavelet_ff_make = R"doc()doc"; diff --git a/gr-wavelet/python/wavelet/bindings/docstrings/wvps_ff_pydoc_template.h b/gr-wavelet/python/wavelet/bindings/docstrings/wvps_ff_pydoc_template.h new file mode 100644 index 0000000000..0389e60234 --- /dev/null +++ b/gr-wavelet/python/wavelet/bindings/docstrings/wvps_ff_pydoc_template.h @@ -0,0 +1,24 @@ +/* + * Copyright 2020 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ +#include "pydoc_macros.h" +#define D(...) DOC(gr, wavelet, __VA_ARGS__) +/* + This file contains placeholders for docstrings for the Python bindings. + Do not edit! These were automatically extracted during the binding process + and will be overwritten during the build process + */ + + +static const char* __doc_gr_wavelet_wvps_ff = R"doc()doc"; + + +static const char* __doc_gr_wavelet_wvps_ff_wvps_ff = R"doc()doc"; + + +static const char* __doc_gr_wavelet_wvps_ff_make = R"doc()doc"; diff --git a/gr-wavelet/python/wavelet/bindings/python_bindings.cc b/gr-wavelet/python/wavelet/bindings/python_bindings.cc new file mode 100644 index 0000000000..a94bc4405d --- /dev/null +++ b/gr-wavelet/python/wavelet/bindings/python_bindings.cc @@ -0,0 +1,44 @@ + +/* + * Copyright 2020 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#include <pybind11/pybind11.h> + +#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION +#include <numpy/arrayobject.h> + +namespace py = pybind11; + +void bind_squash_ff(py::module&); +void bind_wavelet_ff(py::module&); +void bind_wvps_ff(py::module&); + +// We need this hack because import_array() returns NULL +// for newer Python versions. +// This function is also necessary because it ensures access to the C API +// and removes a warning. +void* init_numpy() +{ + import_array(); + return NULL; +} + +PYBIND11_MODULE(wavelet_python, m) +{ + // Initialize the numpy C API + // (otherwise we will see segmentation faults) + init_numpy(); + + // Allow access to base block methods + py::module::import("gnuradio.gr"); + + bind_squash_ff(m); + bind_wavelet_ff(m); + bind_wvps_ff(m); +} diff --git a/gr-wavelet/python/wavelet/bindings/squash_ff_python.cc b/gr-wavelet/python/wavelet/bindings/squash_ff_python.cc new file mode 100644 index 0000000000..a3f4fb8ed8 --- /dev/null +++ b/gr-wavelet/python/wavelet/bindings/squash_ff_python.cc @@ -0,0 +1,41 @@ +/* + * Copyright 2020 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +/* This file is automatically generated using bindtool */ + +#include <pybind11/complex.h> +#include <pybind11/pybind11.h> +#include <pybind11/stl.h> + +namespace py = pybind11; + +#include <gnuradio/wavelet/squash_ff.h> +// pydoc.h is automatically generated in the build directory +#include <squash_ff_pydoc.h> + +void bind_squash_ff(py::module& m) +{ + + using squash_ff = ::gr::wavelet::squash_ff; + + + py::class_<squash_ff, + gr::sync_block, + gr::block, + gr::basic_block, + std::shared_ptr<squash_ff>>(m, "squash_ff", D(squash_ff)) + + .def(py::init(&squash_ff::make), + py::arg("igrid"), + py::arg("ogrid"), + D(squash_ff, make)) + + + ; +} diff --git a/gr-wavelet/python/wavelet/bindings/wavelet_ff_python.cc b/gr-wavelet/python/wavelet/bindings/wavelet_ff_python.cc new file mode 100644 index 0000000000..9ee4ad9731 --- /dev/null +++ b/gr-wavelet/python/wavelet/bindings/wavelet_ff_python.cc @@ -0,0 +1,42 @@ +/* + * Copyright 2020 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +/* This file is automatically generated using bindtool */ + +#include <pybind11/complex.h> +#include <pybind11/pybind11.h> +#include <pybind11/stl.h> + +namespace py = pybind11; + +#include <gnuradio/wavelet/wavelet_ff.h> +// pydoc.h is automatically generated in the build directory +#include <wavelet_ff_pydoc.h> + +void bind_wavelet_ff(py::module& m) +{ + + using wavelet_ff = ::gr::wavelet::wavelet_ff; + + + py::class_<wavelet_ff, + gr::sync_block, + gr::block, + gr::basic_block, + std::shared_ptr<wavelet_ff>>(m, "wavelet_ff", D(wavelet_ff)) + + .def(py::init(&wavelet_ff::make), + py::arg("size") = 1024, + py::arg("order") = 20, + py::arg("forward") = true, + D(wavelet_ff, make)) + + + ; +} diff --git a/gr-wavelet/python/wavelet/bindings/wvps_ff_python.cc b/gr-wavelet/python/wavelet/bindings/wvps_ff_python.cc new file mode 100644 index 0000000000..317066a11c --- /dev/null +++ b/gr-wavelet/python/wavelet/bindings/wvps_ff_python.cc @@ -0,0 +1,38 @@ +/* + * Copyright 2020 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +/* This file is automatically generated using bindtool */ + +#include <pybind11/complex.h> +#include <pybind11/pybind11.h> +#include <pybind11/stl.h> + +namespace py = pybind11; + +#include <gnuradio/wavelet/wvps_ff.h> +// pydoc.h is automatically generated in the build directory +#include <wvps_ff_pydoc.h> + +void bind_wvps_ff(py::module& m) +{ + + using wvps_ff = ::gr::wavelet::wvps_ff; + + + py::class_<wvps_ff, + gr::sync_block, + gr::block, + gr::basic_block, + std::shared_ptr<wvps_ff>>(m, "wvps_ff", D(wvps_ff)) + + .def(py::init(&wvps_ff::make), py::arg("ilen"), D(wvps_ff, make)) + + + ; +} |