Skip to content

Commit

Permalink
Fix error message when #TypeAxisNames != #TypeAxes.
Browse files Browse the repository at this point in the history
The error message was being generated after moving strings out of `names`, so some of the axis names were blank.
This moves the check + error before any strings are moved.
  • Loading branch information
alliepiper committed Nov 20, 2024
1 parent f52aa4b commit 25b09d9
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions nvbench/axes_metadata.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
*/

#include <nvbench/axes_metadata.cuh>

#include <nvbench/detail/throw.cuh>

#include <fmt/format.h>
#include <fmt/ranges.h>

#include <algorithm>
#include <cassert>
#include <stdexcept>

#include <fmt/format.h>
#include <fmt/ranges.h>

namespace nvbench
{

Expand All @@ -52,21 +52,18 @@ axes_metadata &axes_metadata::operator=(const axes_metadata &other)
void axes_metadata::set_type_axes_names(std::vector<std::string> names)
try
{
if (names.size() < m_axes.size())
if (names.size() != m_axes.size())
{
NVBENCH_THROW(std::runtime_error,
"Number of names exceeds number of axes ({}).",
"Number of type axis names ({}) exceeds number of type axes ({}).",
names.size(),
m_axes.size());
}

for (std::size_t i = 0; i < names.size(); ++i)
{
auto &axis = *m_axes[i];
if (axis.get_type() != nvbench::axis_type::type)
{
NVBENCH_THROW(std::runtime_error, "Number of names exceeds number of type axes ({})", i);
}

assert(axis.get_type() != nvbench::axis_type::type);
axis.set_name(std::move(names[i]));
}
}
Expand Down

0 comments on commit 25b09d9

Please sign in to comment.