Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scikit build #277

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
8 changes: 6 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 16 additions & 0 deletions src/cpp/pixel_math.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <pybind11/numpy.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

#include <vector>
#include "pixel_math.h"

std::vector<std::vector<unsigned long long int> > generate_alignment(
const std::vector<unsigned long long int> &histogram,
unsigned short highest_order,
unsigned short lowest_order,
unsigned long long int threshold
){
std::vector<std::vector<unsigned long long int> > result (order2npix(highest_order));
return result;
}
30 changes: 30 additions & 0 deletions src/cpp/pixel_math.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef PIXEL_MATH_H_
#define PIXEL_MATH_H_

#include <pybind11/pybind11.h>

#include <vector>

namespace py = pybind11;


float square(float x) { return x * x; }

unsigned long order2npix(unsigned short pix) {
return 12 * 1 << (2 * pix);
}

std::vector<std::vector<unsigned long long int> > generate_alignment(
const std::vector<unsigned long long int> &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
9 changes: 9 additions & 0 deletions tests/hipscat/pixel_math/test_the_cpp.py
Original file line number Diff line number Diff line change
@@ -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
Loading