mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2026-07-31 09:13:37 +02:00
Revert "some benchmarks for this useless sparsemask"
This reverts commit 3b41a798a1.
This commit is contained in:
@@ -19,7 +19,7 @@ add_executable(benchmarks)
|
||||
|
||||
target_sources(
|
||||
benchmarks PRIVATE ndarray_benchmark.cpp calculateeta_benchmark.cpp
|
||||
reduce_benchmark.cpp sparsemask_benchmark.cpp)
|
||||
reduce_benchmark.cpp)
|
||||
|
||||
# Link Google Benchmark and other necessary libraries
|
||||
target_link_libraries(benchmarks PRIVATE benchmark::benchmark aare_core
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include "aare/NDArray.hpp"
|
||||
#include "aare/NDView.hpp"
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
@@ -42,24 +41,11 @@ class SparseMask {
|
||||
/// @brief Get number of bad channels
|
||||
size_t num_bad_channels() const;
|
||||
|
||||
/**
|
||||
* Convert the sparse mask to a dense 2D array representation.
|
||||
* @return An NDArray<bool, 2> representing the dense mask, where true
|
||||
* indicates a bad channel
|
||||
*/
|
||||
NDArray<bool, 2> convert_to_dense() const;
|
||||
|
||||
private:
|
||||
/// @brief storage format of the sparse mask, either row major or column
|
||||
/// @brief stoarge format of the sparse mask, either row major or column
|
||||
/// major
|
||||
STORAGEFORMAT storage_format_;
|
||||
|
||||
/// @brief number of rows in the dense mask
|
||||
size_t rows_;
|
||||
|
||||
/// @brief number of columns in the dense mask
|
||||
size_t cols_;
|
||||
|
||||
/// @brief for column major stores row indices of non-zero elements, for row
|
||||
/// major stores column indices of non-zero elements
|
||||
std::vector<uint32_t> innerindices_;
|
||||
|
||||
+13
-24
@@ -4,17 +4,17 @@ namespace aare {
|
||||
|
||||
SparseMask::SparseMask(const STORAGEFORMAT storage_format, const size_t rows,
|
||||
const size_t cols)
|
||||
: storage_format_(storage_format), rows_(rows), cols_(cols) {
|
||||
: storage_format_(storage_format) {
|
||||
if (storage_format_ == STORAGEFORMAT::ROWMAJOR) {
|
||||
outerindices_.resize(rows_ + 1, 0);
|
||||
outerindices_.resize(rows + 1, 0);
|
||||
} else if (storage_format_ == STORAGEFORMAT::COLUMNMAJOR) {
|
||||
outerindices_.resize(cols_ + 1, 0);
|
||||
outerindices_.resize(cols + 1, 0);
|
||||
} else {
|
||||
throw std::invalid_argument(
|
||||
"Invalid storage format: must be either ROWMAJOR or COLUMNMAJOR");
|
||||
}
|
||||
|
||||
innerindices_.reserve(rows_ * cols_); // Reserve maximum possible size
|
||||
innerindices_.reserve(rows * cols); // Reserve maximum possible size
|
||||
}
|
||||
|
||||
void SparseMask::insert(const size_t row, const size_t col) {
|
||||
@@ -52,33 +52,22 @@ bool SparseMask::is_masked(const size_t row, const size_t col) const {
|
||||
} else {
|
||||
auto start = outerindices_[index_outer_indices];
|
||||
auto end = outerindices_[index_outer_indices + 1];
|
||||
<<<<<<< HEAD
|
||||
// TODO: binary search does not work if not filled along cols e.g. rows
|
||||
// e.g. random row col insert
|
||||
return std::binary_search(innerindices_.begin() + start,
|
||||
innerindices_.begin() + end, nonzero_index);
|
||||
=======
|
||||
for (size_t i = start; i < end; ++i) {
|
||||
if (innerindices_[i] == nonzero_index) {
|
||||
return true; // Found a non-zero element at (row, col)
|
||||
}
|
||||
}
|
||||
return false; // No non-zero element found at (row, col)
|
||||
>>>>>>> parent of 3b41a79 (some benchmarks for this useless sparsemask)
|
||||
}
|
||||
}
|
||||
|
||||
size_t SparseMask::num_bad_channels() const { return innerindices_.size(); }
|
||||
|
||||
NDArray<bool, 2> SparseMask::convert_to_dense() const {
|
||||
NDArray<bool, 2> dense_mask{
|
||||
std::array<ssize_t, 2>{static_cast<ssize_t>(rows_),
|
||||
static_cast<ssize_t>(cols_)},
|
||||
false};
|
||||
|
||||
for (size_t i = 0; i < outerindices_.size() - 1; ++i) {
|
||||
size_t start = outerindices_[i];
|
||||
size_t end = outerindices_[i + 1];
|
||||
for (size_t j = start; j < end; ++j) {
|
||||
if (storage_format_ == STORAGEFORMAT::ROWMAJOR) {
|
||||
dense_mask(i, innerindices_[j]) = true;
|
||||
} else {
|
||||
dense_mask(innerindices_[j], i) = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return dense_mask;
|
||||
}
|
||||
|
||||
} // namespace aare
|
||||
Reference in New Issue
Block a user