From 15b2ab246ffa974a15c4da080d9100c56b9594ce Mon Sep 17 00:00:00 2001 From: Melissa DeLucchi Date: Fri, 24 May 2024 15:17:06 -0400 Subject: [PATCH] scikit build --- CMakeLists.txt | 11 +++++++++ pyproject.toml | 8 +++++-- src/cpp/pixel_math.cpp | 16 +++++++++++++ src/cpp/pixel_math.h | 30 ++++++++++++++++++++++++ tests/hipscat/pixel_math/test_the_cpp.py | 9 +++++++ 5 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 src/cpp/pixel_math.cpp create mode 100644 src/cpp/pixel_math.h create mode 100644 tests/hipscat/pixel_math/test_the_cpp.py diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..55cca0bf --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.15...3.26) +project(${SKBUILD_PROJECT_NAME} LANGUAGES CXX) + +set(PYBIND11_NEWPYTHON ON) +find_package(pybind11 CONFIG REQUIRED) +set(TARGET pixel_math_ext) + +pybind11_add_module(${TARGET} src/cpp/pixel_math.cpp ) + +target_include_directories(${TARGET} PUBLIC src/cpp) +install(TARGETS ${TARGET} LIBRARY DESTINATION ${SKBUILD_PROJECT_NAME}) \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 1e783288..1044cf74 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -52,10 +52,14 @@ dev = [ [build-system] requires = [ - "setuptools>=62", # Used to build and package the Python project "setuptools_scm>=6.2", # Gets release version from git. Makes it available programmatically + "scikit-build-core", "pybind11" ] -build-backend = "setuptools.build_meta" +build-backend = "scikit_build_core.build" + +[tool.scikit-build] +metadata.version.provider = "scikit_build_core.metadata.setuptools_scm" +sdist.include = ["src/hipscat/_version.py"] [tool.setuptools_scm] write_to = "src/hipscat/_version.py" diff --git a/src/cpp/pixel_math.cpp b/src/cpp/pixel_math.cpp new file mode 100644 index 00000000..6d8f243c --- /dev/null +++ b/src/cpp/pixel_math.cpp @@ -0,0 +1,16 @@ +#include +#include +#include + +#include +#include "pixel_math.h" + +std::vector > generate_alignment( + const std::vector &histogram, + unsigned short highest_order, + unsigned short lowest_order, + unsigned long long int threshold +){ + std::vector > result (order2npix(highest_order)); + return result; +} diff --git a/src/cpp/pixel_math.h b/src/cpp/pixel_math.h new file mode 100644 index 00000000..da987a50 --- /dev/null +++ b/src/cpp/pixel_math.h @@ -0,0 +1,30 @@ +#ifndef PIXEL_MATH_H_ +#define PIXEL_MATH_H_ + +#include + +#include + +namespace py = pybind11; + + +float square(float x) { return x * x; } + +unsigned long order2npix(unsigned short pix) { + return 12 * 1 << (2 * pix); +} + +std::vector > generate_alignment( + const std::vector &histogram, + unsigned short highest_order, + unsigned short lowest_order, + unsigned long long int threshold +); + +PYBIND11_MODULE(pixel_math_ext, m) { + m.def("square", &square); + m.def("order2npix", &order2npix); + m.def("generate_alignment", &generate_alignment); +} + +#endif \ No newline at end of file diff --git a/tests/hipscat/pixel_math/test_the_cpp.py b/tests/hipscat/pixel_math/test_the_cpp.py new file mode 100644 index 00000000..67841cf8 --- /dev/null +++ b/tests/hipscat/pixel_math/test_the_cpp.py @@ -0,0 +1,9 @@ +from hipscat.pixel_math_ext import order2npix, generate_alignment +import numpy as np + +def test_order2npix(): + assert order2npix(0) == 12 + assert order2npix(4) == 3072 + +def test_generate_alignment(): + assert len(generate_alignment(np.arange(12), 0, 0, 4)) == 12 \ No newline at end of file