Skip to content

Commit

Permalink
replaces loop for comparing vectors with generic macro
Browse files Browse the repository at this point in the history
  • Loading branch information
elstehle committed Jul 21, 2022
1 parent d42869a commit 6c889f7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
9 changes: 9 additions & 0 deletions cpp/include/cudf_test/cudf_gtest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,12 @@ struct TypeList<Types<TYPES...>> {
} catch (std::exception & e) { \
FAIL() << "statement:" << #statement << std::endl << "reason: " << e.what() << std::endl; \
}

/**
* @brief test macro comparing for equality of \p lhs and and \p rhs for the first \p size elements.
*/
#define CUDF_TEST_EXPECT_VECTOR_EQUAL(lhs, rhs, size) \
do { \
for (decltype(size) i = 0; i < size; i++) \
EXPECT_EQ(lhs[i], rhs[i]) << "Mismatch at index #" << i; \
} while (0)
4 changes: 3 additions & 1 deletion cpp/src/io/fst/in_reg_array.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ class MultiFragmentInRegArray {
/**
* @brief Returns the \p num_bits bits starting at \p bit_start
*/
CUDF_HOST_DEVICE [[nodiscard]] uint32_t bfe(const uint32_t& data, uint32_t bit_start, uint32_t num_bits) const
CUDF_HOST_DEVICE [[nodiscard]] uint32_t bfe(const uint32_t& data,
uint32_t bit_start,
uint32_t num_bits) const
{
#if CUB_PTX_ARCH > 0
return cub::BFE(data, bit_start, num_bits);
Expand Down
8 changes: 2 additions & 6 deletions cpp/tests/io/fst/fst_test.cu
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,8 @@ TEST_F(FstTest, GroundTruth)

// Verify results
ASSERT_EQ(output_gpu_size[0], output_cpu.size());
for (std::size_t i = 0; i < output_cpu.size(); i++) {
EXPECT_EQ(output_gpu[i], output_cpu[i]) << "Mismatch at index #" << i;
}
for (std::size_t i = 0; i < output_cpu.size(); i++) {
EXPECT_EQ(out_indexes_gpu[i], out_index_cpu[i]) << "Mismatch at index #" << i;
}
CUDF_TEST_EXPECT_VECTOR_EQUAL(output_gpu, output_cpu, output_cpu.size());
CUDF_TEST_EXPECT_VECTOR_EQUAL(out_indexes_gpu, out_index_cpu, output_cpu.size());
}

CUDF_TEST_PROGRAM_MAIN()

0 comments on commit 6c889f7

Please sign in to comment.