diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt index b579fca..ef378e4 100644 --- a/benchmarks/CMakeLists.txt +++ b/benchmarks/CMakeLists.txt @@ -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 diff --git a/include/aare/utils/SparseMask.hpp b/include/aare/utils/SparseMask.hpp index a3dfa55..acb1e4f 100644 --- a/include/aare/utils/SparseMask.hpp +++ b/include/aare/utils/SparseMask.hpp @@ -1,4 +1,3 @@ -#include "aare/NDArray.hpp" #include "aare/NDView.hpp" #include #include @@ -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 representing the dense mask, where true - * indicates a bad channel - */ - NDArray 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 innerindices_; diff --git a/src/utils/SparseMask.cpp b/src/utils/SparseMask.cpp index 1866bc8..f44ee46 100644 --- a/src/utils/SparseMask.cpp +++ b/src/utils/SparseMask.cpp @@ -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 SparseMask::convert_to_dense() const { - NDArray dense_mask{ - std::array{static_cast(rows_), - static_cast(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 \ No newline at end of file