diff --git a/cpp/include/cudf_test/column_wrapper.hpp b/cpp/include/cudf_test/column_wrapper.hpp index 55b7096f96f..510cab1ffe7 100644 --- a/cpp/include/cudf_test/column_wrapper.hpp +++ b/cpp/include/cudf_test/column_wrapper.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020, NVIDIA CORPORATION. + * Copyright (c) 2019-2021, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -94,7 +94,7 @@ struct fixed_width_type_converter { template ::value, void>::type* = nullptr> - ToT operator()(FromT element) const + constexpr ToT operator()(FromT element) const { return element; } @@ -106,7 +106,7 @@ struct fixed_width_type_converter { (cudf::is_convertible::value || std::is_constructible::value), void>::type* = nullptr> - ToT operator()(FromT element) const + constexpr ToT operator()(FromT element) const { return static_cast(element); } @@ -117,7 +117,7 @@ struct fixed_width_type_converter { typename ToT = To, typename std::enable_if::value && cudf::is_timestamp_t::value, void>::type* = nullptr> - ToT operator()(FromT element) const + constexpr ToT operator()(FromT element) const { return ToT{typename ToT::duration{element}}; } diff --git a/cpp/tests/utilities/column_utilities.cu b/cpp/tests/utilities/column_utilities.cu index 4f7ac41a00f..091919463a8 100644 --- a/cpp/tests/utilities/column_utilities.cu +++ b/cpp/tests/utilities/column_utilities.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020, NVIDIA CORPORATION. + * Copyright (c) 2019-2021, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -160,39 +160,37 @@ class corresponding_rows_not_equivalent { } }; -std::string differences_message(thrust::device_vector const& differences, - column_view const& lhs, - column_view const& rhs, - bool all_differences, - int depth) +// Stringify the inconsistent values resulted from the comparison of two columns element-wise +std::string stringify_column_differences(thrust::device_vector const& differences, + column_view const& lhs, + column_view const& rhs, + bool print_all_differences, + int depth) { CUDF_EXPECTS(not differences.empty(), "Shouldn't enter this function if `differences` is empty"); - std::string const depth_str = depth > 0 ? "depth " + std::to_string(depth) + '\n' : ""; - - if (all_differences) { + if (print_all_differences) { std::ostringstream buffer; buffer << depth_str << "differences:" << std::endl; + // thrust may crash if a device_vector is passed to fixed_width_column_wrapper, + // thus we construct fixed_width_column_wrapper from a host_vector instead + thrust::host_vector h_differences(differences); auto source_table = cudf::table_view({lhs, rhs}); - auto diff_column = fixed_width_column_wrapper(differences.begin(), differences.end()); - auto diff_table = cudf::gather(source_table, diff_column); - + auto diff_column = + fixed_width_column_wrapper(h_differences.begin(), h_differences.end()); + auto diff_table = cudf::gather(source_table, diff_column); // Need to pull back the differences auto const h_left_strings = to_strings(diff_table->get_column(0)); auto const h_right_strings = to_strings(diff_table->get_column(1)); - - for (size_t i = 0; i < differences.size(); ++i) - buffer << depth_str << "lhs[" << differences[i] << "] = " << h_left_strings[i] << ", rhs[" - << differences[i] << "] = " << h_right_strings[i] << std::endl; - + for (size_t i = 0; i < h_differences.size(); ++i) + buffer << depth_str << "lhs[" << h_differences[i] << "] = " << h_left_strings[i] << ", rhs[" + << h_differences[i] << "] = " << h_right_strings[i] << std::endl; return buffer.str(); } else { - int index = differences[0]; // only stringify first difference - + int index = differences[0]; // only stringify first difference auto diff_lhs = cudf::detail::slice(lhs, index, index + 1); auto diff_rhs = cudf::detail::slice(rhs, index, index + 1); - return depth_str + "first difference: " + "lhs[" + std::to_string(index) + "] = " + to_string(diff_lhs, "") + ", rhs[" + std::to_string(index) + "] = " + to_string(diff_rhs, ""); @@ -224,7 +222,8 @@ struct column_comparator_impl { differences.resize(thrust::distance(differences.begin(), diff_iter)); // shrink back down if (not differences.empty()) - GTEST_FAIL() << differences_message(differences, lhs, rhs, print_all_differences, depth); + GTEST_FAIL() << stringify_column_differences( + differences, lhs, rhs, print_all_differences, depth); } }; @@ -315,7 +314,8 @@ struct column_comparator_impl { differences.resize(thrust::distance(differences.begin(), diff_iter)); // shrink back down if (not differences.empty()) - GTEST_FAIL() << differences_message(differences, lhs, rhs, print_all_differences, depth); + GTEST_FAIL() << stringify_column_differences( + differences, lhs, rhs, print_all_differences, depth); // recurse auto lhs_child = lhs_l.get_sliced_child(0);