-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5fdc4f6
commit 15b2ab2
Showing
5 changed files
with
72 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |