fixed conversion, checking over and underflow
Build on RHEL8 / build (push) Failing after 1m16s
Build on RHEL9 / build (push) Failing after 1m22s
Run tests using data on local RHEL8 / build (push) Failing after 1m53s

This commit is contained in:
Erik Frojdh
2026-05-23 16:28:32 +02:00
parent 5ceb63337d
commit 61b765c4b8
4 changed files with 17 additions and 11 deletions
+4 -2
View File
@@ -28,6 +28,8 @@ class PixelHistogram {
int rows_;
int cols_;
int n_threads_;
const AxisType xmin_;
const AxisType xmax_;
std::vector<Hist> partial_hists_;
// Thread pool members
@@ -35,7 +37,7 @@ class PixelHistogram {
std::mutex work_mutex_;
std::condition_variable work_cv_;
std::condition_variable done_cv_;
const NDView<double, 2>* current_image_;
const NDView<AxisType, 2>* current_image_;
std::atomic<int> completed_threads_;
std::atomic<bool> stop_workers_;
int work_generation_;
@@ -48,7 +50,7 @@ class PixelHistogram {
public:
PixelHistogram(int rows, int cols, int n_bins, double xmin, double xmax, int n_threads = 1);
~PixelHistogram();
void fill(const NDView<double, 2> &image);
void fill(const NDView<AxisType, 2> &image);
NDArray<StorageType, 3> hdata() const;
NDArray<AxisType, 1> bin_centers() const;
NDArray<AxisType, 1> bin_edges() const;
+3 -3
View File
@@ -30,7 +30,7 @@ void define_pixel_histogram_bindings(py::module &m) {
.def("fill",
[](PixelHistogram &self,
py::array_t<double, py::array::forcecast> image) {
py::array_t<PixelHistogram::AxisType, 0> image) {
auto view = make_view_2d(image);
self.fill(view);
},
@@ -38,9 +38,9 @@ void define_pixel_histogram_bindings(py::module &m) {
Fill the histogram with image data.
Args:
image: A 2D numpy array of pixel values (dtype: float64)
image: A 2D numpy array of pixel values (dtype: float32)
)",
py::arg("image"))
py::arg("image").noconvert())
.def("hdata",
[](const PixelHistogram &self) {
+8 -4
View File
@@ -12,7 +12,7 @@ namespace aare {
PixelHistogram::PixelHistogram(int rows, int cols, int n_bins, double xmin, double xmax, int n_threads):
rows_(rows), cols_(cols), n_threads_(n_threads), current_image_(nullptr),
rows_(rows), cols_(cols), n_threads_(n_threads), xmin_(xmin), xmax_(xmax), current_image_(nullptr),
completed_threads_(0), stop_workers_(false), work_generation_(0) {
if (rows_ < 1 || cols_ < 1 || n_bins < 1) {
throw std::invalid_argument("PixelHistogram requires positive rows, cols and bins");
@@ -81,7 +81,7 @@ void PixelHistogram::worker_loop(int thread_id) {
}
// Get work assignment
const NDView<double, 2>& image = *current_image_;
const NDView<AxisType, 2>& image = *current_image_;
const int generation = work_generation_;
const int first_row = row_start(thread_id);
const int local_rows = row_count(thread_id);
@@ -92,7 +92,11 @@ void PixelHistogram::worker_loop(int thread_id) {
for (int local_row = 0; local_row < local_rows; ++local_row) {
const auto row = static_cast<ssize_t>(first_row + local_row);
for (ssize_t col = 0; col < image.shape(1); ++col) {
partial_hists_[thread_id](image(row, col), col, local_row);
const auto val = image(row, col);
if (val < xmin_ || val >= xmax_) {
continue; // Skip out-of-range values
}
partial_hists_[thread_id](val, col, local_row);
}
}
@@ -139,7 +143,7 @@ NDArray<PixelHistogram::StorageType, 3> PixelHistogram::hdata() const {
return data;
}
void PixelHistogram::fill(const NDView<double, 2> &image) {
void PixelHistogram::fill(const NDView<AxisType, 2> &image) {
if (image.shape(0) != rows_ || image.shape(1) != cols_) {
throw std::invalid_argument("PixelHistogram image shape does not match constructor shape");
}
+2 -2
View File
@@ -13,7 +13,7 @@ using aare::NDView;
TEST_CASE("Fill one pixel of a 5x10 histogram"){
PixelHistogram hist(5, 10, 20, 0.0, 10.0);
NDArray<double, 2> image({5, 10}, -1.0); //Need to fill with -1 to not generate counts
NDArray<float, 2> image({5, 10}, -1.0); //Need to fill with -1 to not generate counts
image(2, 3) = 5.7; // This should go into bin 11 (since bins are [0-0.5), [0.5-1.0), ..., [9.5-10.0))
@@ -41,7 +41,7 @@ TEST_CASE("Fill one pixel of a 5x10 histogram"){
TEST_CASE("Fill pixels with uneven partial histogram row slices"){
PixelHistogram hist(5, 4, 10, 0.0, 10.0, 3);
NDArray<double, 2> image({5, 4}, -1.0);
NDArray<float, 2> image({5, 4}, -1.0);
image(0, 0) = 0.2;
image(1, 1) = 1.2;