Skip to content

Commit

Permalink
[c++] Show which coordinate is out of range in fastercsx error mess…
Browse files Browse the repository at this point in the history
…ages (#3539) (#3541)

* [c++] Show which coordinate is out of range in `fastercsx`

* code-review feedback

* more

Co-authored-by: John Kerl <[email protected]>
  • Loading branch information
github-actions[bot] and johnkerl authored Jan 9, 2025
1 parent 51c95cd commit 0628a87
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions libtiledbsoma/src/utils/fastercsx.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <atomic>
#include <cmath>
#include <cstdint>
#include <format>
#include <numeric>
#include "span/span.hpp"

Expand Down Expand Up @@ -198,8 +199,13 @@ void count_rows_(
auto row = Ai_view[n];
if ((row < 0) ||
(static_cast<std::make_unsigned_t<COO_IDX>>(row) >=
n_row)) [[unlikely]]
throw std::out_of_range("Coordinate out of range.");
n_row)) [[unlikely]] {
throw std::out_of_range(std::format(
"First coordinate {} out of range {}.",
row,
0,
n_row));
}
counts[row]++;
}
}
Expand All @@ -221,8 +227,10 @@ void count_rows_(
auto row = Ai_view[n];
if ((row < 0) ||
(static_cast<std::make_unsigned_t<COO_IDX>>(row) >= n_row))
[[unlikely]]
throw std::out_of_range("Coordinate out of range.");
[[unlikely]] {
throw std::out_of_range(std::format(
"First coordinate {} out of range {}.", row, 0, n_row));
}
Bp[row]++;
}
}
Expand Down Expand Up @@ -268,9 +276,10 @@ void compress_coo_inner_left_(
const auto dest = Bp[row];
if ((Aj_[n] < 0) ||
(static_cast<std::make_unsigned_t<COO_IDX>>(Aj_[n]) >= n_col))
[[unlikely]]
throw std::out_of_range("Coordinate out of range.");

[[unlikely]] {
throw std::out_of_range(std::format(
"Second coordinate {} out of range {}.", Aj_[n], 0, n_col));
}
Bj[dest] = Aj_[n];
Bd[dest] = Ad_[n];
Bp[row]++;
Expand Down Expand Up @@ -302,8 +311,10 @@ void compress_coo_inner_right_(
const auto dest = Bp[row];
if ((Aj_[n] < 0) ||
(static_cast<std::make_unsigned_t<COO_IDX>>(Aj_[n]) >= n_col))
[[unlikely]]
throw std::out_of_range("Coordinate out of range.");
[[unlikely]] {
throw std::out_of_range(std::format(
"Second coordinate {} out of range {}.", Aj_[n], 0, n_col));
}

Bj[dest] = Aj_[n];
Bd[dest] = Ad_[n];
Expand Down

0 comments on commit 0628a87

Please sign in to comment.