Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[c++] Show which coordinate is out of range in fastercsx error messages #3539

Merged
merged 3 commits into from
Jan 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>

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