Fixes #30, Add CMake steps to install python bindings (#31)

This commit is contained in:
Dantali0n
2025-09-17 20:03:28 +02:00
committed by GitHub
parent 8fe8314905
commit bfe752433f
3 changed files with 33 additions and 2 deletions

View File

@@ -8,5 +8,18 @@ if(NOT pybind11_FOUND)
FetchContent_MakeAvailable(pybind11) FetchContent_MakeAvailable(pybind11)
endif() endif()
# Needed to set ${Python_VERSION_MAJOR} and ${Python_VERSION_MINOR}
find_package(
Python REQUIRED
)
pybind11_add_module(pytrigdx bindings.cpp) pybind11_add_module(pytrigdx bindings.cpp)
target_link_libraries(pytrigdx PRIVATE trigdx) target_link_libraries(pytrigdx PRIVATE trigdx)
set_target_properties(pytrigdx PROPERTIES OUTPUT_NAME "trigdx")
set(PYTHON_SITE_PACKAGES
"${CMAKE_INSTALL_LIBDIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages/trigdx"
)
install(TARGETS pytrigdx DESTINATION ${PYTHON_SITE_PACKAGES})
install(FILES __init__.py DESTINATION ${PYTHON_SITE_PACKAGES})

16
python/__init__.py Normal file
View File

@@ -0,0 +1,16 @@
from .trigdx import Reference, Lookup16K, Lookup32K, LookupAVX16K, LookupAVX32K
try:
from .trigdx import MKL
except ImportError:
pass
try:
from .trigdx import GPU
except ImportError:
pass
try:
from .trigdx import LookupXSIMD16K, LookupXSIMD32K
except ImportError:
pass

View File

@@ -72,7 +72,9 @@ void bind_backend(py::module &m, const char *name) {
.def("compute_sincosf", &compute_sincos<float>); .def("compute_sincosf", &compute_sincos<float>);
} }
PYBIND11_MODULE(pytrigdx, m) { PYBIND11_MODULE(trigdx, m) {
m.doc() = "TrigDx python bindings";
py::class_<Backend, std::shared_ptr<Backend>>(m, "Backend") py::class_<Backend, std::shared_ptr<Backend>>(m, "Backend")
.def("init", &Backend::init); .def("init", &Backend::init);
@@ -91,4 +93,4 @@ PYBIND11_MODULE(pytrigdx, m) {
bind_backend<LookupXSIMDBackend<16384>>(m, "LookupXSIMD16K"); bind_backend<LookupXSIMDBackend<16384>>(m, "LookupXSIMD16K");
bind_backend<LookupXSIMDBackend<32768>>(m, "LookupXSIMD32K"); bind_backend<LookupXSIMDBackend<32768>>(m, "LookupXSIMD32K");
#endif #endif
} }