From ab6a81d1fafdbf8670260dee506d689e22b392d6 Mon Sep 17 00:00:00 2001 From: Karthikeyan Natarajan Date: Mon, 25 Apr 2022 20:54:26 +0530 Subject: [PATCH] Use structured bindings instead of std::tie --- cpp/include/cudf_test/column_wrapper.hpp | 30 +++++------- cpp/src/io/parquet/page_enc.cu | 14 ++---- cpp/src/io/parquet/reader_impl.cu | 6 +-- cpp/src/quantiles/quantile.cu | 5 +- cpp/src/reshape/interleave_columns.cu | 5 +- cpp/src/rolling/rolling_collect_list.cuh | 4 +- cpp/src/strings/copying/concatenate.cu | 4 +- .../partitioning/hash_partition_test.cpp | 48 ++++++------------- cpp/tests/rolling/grouped_rolling_test.cpp | 12 ++--- cpp/tests/rolling/rolling_test.cpp | 6 +-- cpp/tests/sort/rank_test.cpp | 3 +- cpp/tests/transform/row_bit_count_test.cu | 24 +++------- cpp/tests/unary/cast_tests.cpp | 4 +- 13 files changed, 48 insertions(+), 117 deletions(-) diff --git a/cpp/include/cudf_test/column_wrapper.hpp b/cpp/include/cudf_test/column_wrapper.hpp index 8a5d4e5efcc..158c4ff20bb 100644 --- a/cpp/include/cudf_test/column_wrapper.hpp +++ b/cpp/include/cudf_test/column_wrapper.hpp @@ -702,13 +702,11 @@ class strings_column_wrapper : public detail::column_wrapper { template strings_column_wrapper(StringsIterator begin, StringsIterator end) : column_wrapper{} { - std::vector chars; - std::vector offsets; - auto all_valid = thrust::make_constant_iterator(true); - std::tie(chars, offsets) = detail::make_chars_and_offsets(begin, end, all_valid); - auto d_chars = cudf::detail::make_device_uvector_sync(chars); - auto d_offsets = cudf::detail::make_device_uvector_sync(offsets); - wrapped = cudf::make_strings_column(d_chars, d_offsets); + auto all_valid = thrust::make_constant_iterator(true); + auto [chars, offsets] = detail::make_chars_and_offsets(begin, end, all_valid); + auto d_chars = cudf::detail::make_device_uvector_sync(chars); + auto d_offsets = cudf::detail::make_device_uvector_sync(offsets); + wrapped = cudf::make_strings_column(d_chars, d_offsets); } /** @@ -744,14 +742,12 @@ class strings_column_wrapper : public detail::column_wrapper { : column_wrapper{} { size_type num_strings = std::distance(begin, end); - std::vector chars; - std::vector offsets; - std::tie(chars, offsets) = detail::make_chars_and_offsets(begin, end, v); - auto null_mask = detail::make_null_mask_vector(v, v + num_strings); - auto d_chars = cudf::detail::make_device_uvector_sync(chars); - auto d_offsets = cudf::detail::make_device_uvector_sync(offsets); - auto d_bitmask = cudf::detail::make_device_uvector_sync(null_mask); - wrapped = cudf::make_strings_column(d_chars, d_offsets, d_bitmask); + auto [chars, offsets] = detail::make_chars_and_offsets(begin, end, v); + auto null_mask = detail::make_null_mask_vector(v, v + num_strings); + auto d_chars = cudf::detail::make_device_uvector_sync(chars); + auto d_offsets = cudf::detail::make_device_uvector_sync(offsets); + auto d_bitmask = cudf::detail::make_device_uvector_sync(null_mask); + wrapped = cudf::make_strings_column(d_chars, d_offsets, d_bitmask); } /** @@ -1479,9 +1475,7 @@ class lists_column_wrapper : public detail::column_wrapper { int32_t const expected_depth = hierarchy_and_depth.second; // preprocess columns so that every column_view in 'cols' is an equivalent hierarchy - std::vector> stubs; - std::vector cols; - std::tie(cols, stubs) = preprocess_columns(elements, expected_hierarchy, expected_depth); + auto [cols, stubs] = preprocess_columns(elements, expected_hierarchy, expected_depth); // generate offsets size_type count = 0; diff --git a/cpp/src/io/parquet/page_enc.cu b/cpp/src/io/parquet/page_enc.cu index da671d4c665..0fe1349d3ee 100644 --- a/cpp/src/io/parquet/page_enc.cu +++ b/cpp/src/io/parquet/page_enc.cu @@ -1662,9 +1662,7 @@ dremel_data get_dremel_data(column_view h_col, } } - std::unique_ptr device_view_owners; - column_device_view* d_nesting_levels; - std::tie(device_view_owners, d_nesting_levels) = + auto [device_view_owners, d_nesting_levels] = contiguous_copy_column_device_views(nesting_levels, stream); thrust::exclusive_scan( @@ -1734,10 +1732,7 @@ dremel_data get_dremel_data(column_view h_col, auto offset_size_at_level = column_ends[level] - column_offsets[level] + 1; // Get empties at this level - rmm::device_uvector empties(0, stream); - rmm::device_uvector empties_idx(0, stream); - size_t empties_size; - std::tie(empties, empties_idx, empties_size) = + auto [empties, empties_idx, empties_size] = get_empties(nesting_levels[level], column_offsets[level], column_ends[level]); // Merge empty at deepest parent level with the rep, def level vals at leaf level @@ -1818,10 +1813,7 @@ dremel_data get_dremel_data(column_view h_col, auto offset_size_at_level = column_ends[level] - column_offsets[level] + 1; // Get empties at this level - rmm::device_uvector empties(0, stream); - rmm::device_uvector empties_idx(0, stream); - size_t empties_size; - std::tie(empties, empties_idx, empties_size) = + auto [empties, empties_idx, empties_size] = get_empties(nesting_levels[level], column_offsets[level], column_ends[level]); auto offset_transformer = [new_child_offsets = new_offsets.data(), diff --git a/cpp/src/io/parquet/reader_impl.cu b/cpp/src/io/parquet/reader_impl.cu index 46b3206f731..cfca0bad518 100644 --- a/cpp/src/io/parquet/reader_impl.cu +++ b/cpp/src/io/parquet/reader_impl.cu @@ -1729,11 +1729,7 @@ table_with_metadata reader::impl::read(size_type skip_rows, continue; } - int32_t type_width; - int32_t clock_rate; - int8_t converted_type; - - std::tie(type_width, clock_rate, converted_type) = + auto [type_width, clock_rate, converted_type] = conversion_info(to_type_id(schema, _strings_to_categorical, _timestamp_type.id()), _timestamp_type.id(), schema.type, diff --git a/cpp/src/quantiles/quantile.cu b/cpp/src/quantiles/quantile.cu index a71fc862bf3..f38d0a921b7 100644 --- a/cpp/src/quantiles/quantile.cu +++ b/cpp/src/quantiles/quantile.cu @@ -113,10 +113,7 @@ struct quantile_functor { ordered_indices, [input = *d_input] __device__(size_type idx) { return input.is_valid_nocheck(idx); }); - rmm::device_buffer mask; - size_type null_count; - - std::tie(mask, null_count) = valid_if( + auto [mask, null_count] = valid_if( q_device.begin(), q_device.end(), [sorted_validity, interp = interp, size = size] __device__(double q) { diff --git a/cpp/src/reshape/interleave_columns.cu b/cpp/src/reshape/interleave_columns.cu index 9954cb4a299..d9e858e8e40 100644 --- a/cpp/src/reshape/interleave_columns.cu +++ b/cpp/src/reshape/interleave_columns.cu @@ -258,10 +258,7 @@ struct interleave_columns_impl()>> { func_value, func_validity); - rmm::device_buffer mask; - size_type null_count; - - std::tie(mask, null_count) = valid_if(index_begin, index_end, func_validity, stream, mr); + auto [mask, null_count] = valid_if(index_begin, index_end, func_validity, stream, mr); output->set_null_mask(std::move(mask), null_count); diff --git a/cpp/src/rolling/rolling_collect_list.cuh b/cpp/src/rolling/rolling_collect_list.cuh index 94703e320d0..13de4693e54 100644 --- a/cpp/src/rolling/rolling_collect_list.cuh +++ b/cpp/src/rolling/rolling_collect_list.cuh @@ -207,9 +207,7 @@ std::unique_ptr rolling_collect_list(column_view const& input, stream, mr); - rmm::device_buffer null_mask; - size_type null_count; - std::tie(null_mask, null_count) = valid_if( + auto [null_mask, null_count] = valid_if( thrust::make_counting_iterator(0), thrust::make_counting_iterator(input.size()), [preceding_begin, following_begin, min_periods] __device__(auto i) { diff --git a/cpp/src/strings/copying/concatenate.cu b/cpp/src/strings/copying/concatenate.cu index fedb8d38a08..0ab7ef5ff2b 100644 --- a/cpp/src/strings/copying/concatenate.cu +++ b/cpp/src/strings/copying/concatenate.cu @@ -72,9 +72,7 @@ auto create_strings_device_views(host_span views, rmm::cuda_s { CUDF_FUNC_RANGE(); // Assemble contiguous array of device views - std::unique_ptr device_view_owners; - column_device_view* device_views_ptr; - std::tie(device_view_owners, device_views_ptr) = + auto [device_view_owners, device_views_ptr] = contiguous_copy_column_device_views(views, stream); // Compute the partition offsets and size of offset column diff --git a/cpp/tests/partitioning/hash_partition_test.cpp b/cpp/tests/partitioning/hash_partition_test.cpp index befd9884b11..3ec6ae97595 100644 --- a/cpp/tests/partitioning/hash_partition_test.cpp +++ b/cpp/tests/partitioning/hash_partition_test.cpp @@ -67,9 +67,7 @@ TEST_F(HashPartition, ZeroPartitions) auto columns_to_hash = std::vector({2}); cudf::size_type const num_partitions = 0; - std::unique_ptr output; - std::vector offsets; - std::tie(output, offsets) = cudf::hash_partition(input, columns_to_hash, num_partitions); + auto [output, offsets] = cudf::hash_partition(input, columns_to_hash, num_partitions); // Expect empty table with same number of columns and zero partitions EXPECT_EQ(input.num_columns(), output->num_columns()); @@ -87,9 +85,7 @@ TEST_F(HashPartition, ZeroRows) auto columns_to_hash = std::vector({2}); cudf::size_type const num_partitions = 3; - std::unique_ptr output; - std::vector offsets; - std::tie(output, offsets) = cudf::hash_partition(input, columns_to_hash, num_partitions); + auto [output, offsets] = cudf::hash_partition(input, columns_to_hash, num_partitions); // Expect empty table with same number of columns and zero partitions EXPECT_EQ(input.num_columns(), output->num_columns()); @@ -104,9 +100,7 @@ TEST_F(HashPartition, ZeroColumns) auto columns_to_hash = std::vector({}); cudf::size_type const num_partitions = 3; - std::unique_ptr output; - std::vector offsets; - std::tie(output, offsets) = cudf::hash_partition(input, columns_to_hash, num_partitions); + auto [output, offsets] = cudf::hash_partition(input, columns_to_hash, num_partitions); // Expect empty table with same number of columns and zero partitions EXPECT_EQ(input.num_columns(), output->num_columns()); @@ -124,10 +118,8 @@ TEST_F(HashPartition, MixedColumnTypes) auto columns_to_hash = std::vector({0, 2}); cudf::size_type const num_partitions = 3; - std::unique_ptr output1, output2; - std::vector offsets1, offsets2; - std::tie(output1, offsets1) = cudf::hash_partition(input, columns_to_hash, num_partitions); - std::tie(output2, offsets2) = cudf::hash_partition(input, columns_to_hash, num_partitions); + auto [output1, offsets1] = cudf::hash_partition(input, columns_to_hash, num_partitions); + auto [output2, offsets2] = cudf::hash_partition(input, columns_to_hash, num_partitions); // Expect output to have size num_partitions EXPECT_EQ(static_cast(num_partitions), offsets1.size()); @@ -148,9 +140,7 @@ TEST_F(HashPartition, NullableStrings) std::vector const columns_to_hash({0}); cudf::size_type const num_partitions = 3; - std::unique_ptr result; - std::vector offsets; - std::tie(result, offsets) = cudf::hash_partition(input, columns_to_hash, num_partitions); + auto [result, offsets] = cudf::hash_partition(input, columns_to_hash, num_partitions); auto const& col = result->get_column(0); EXPECT_EQ(0, col.null_count()); @@ -167,11 +157,9 @@ TEST_F(HashPartition, ColumnsToHash) auto columns_to_hash = std::vector({0}); cudf::size_type const num_partitions = 3; - std::unique_ptr first_result, second_result; - std::vector first_offsets, second_offsets; - std::tie(first_result, first_offsets) = + auto [first_result, first_offsets] = cudf::hash_partition(first_input, columns_to_hash, num_partitions); - std::tie(second_result, second_offsets) = + auto [second_result, second_offsets] = cudf::hash_partition(second_input, columns_to_hash, num_partitions); // Expect offsets to be equal and num_partitions in length @@ -228,11 +216,9 @@ TEST_F(HashPartition, CustomSeedValue) auto columns_to_hash = std::vector({0, 2}); cudf::size_type const num_partitions = 3; - std::unique_ptr output1, output2; - std::vector offsets1, offsets2; - std::tie(output1, offsets1) = cudf::hash_partition( + auto [output1, offsets1] = cudf::hash_partition( input, columns_to_hash, num_partitions, cudf::hash_id::HASH_MURMUR3, 12345); - std::tie(output2, offsets2) = cudf::hash_partition( + auto [output2, offsets2] = cudf::hash_partition( input, columns_to_hash, num_partitions, cudf::hash_id::HASH_MURMUR3, 12345); // Expect output to have size num_partitions @@ -260,9 +246,7 @@ TYPED_TEST(HashPartitionFixedWidth, NullableFixedWidth) std::vector const columns_to_hash({0}); cudf::size_type const num_partitions = 3; - std::unique_ptr result; - std::vector offsets; - std::tie(result, offsets) = cudf::hash_partition(input, columns_to_hash, num_partitions); + auto [result, offsets] = cudf::hash_partition(input, columns_to_hash, num_partitions); auto const& col = result->get_column(0); EXPECT_EQ(0, col.null_count()); @@ -294,10 +278,8 @@ void run_fixed_width_test(size_t cols, auto columns_to_hash = std::vector(cols); std::iota(columns_to_hash.begin(), columns_to_hash.end(), 0); - std::unique_ptr output1, output2; - std::vector offsets1, offsets2; - std::tie(output1, offsets1) = cudf::hash_partition(input, columns_to_hash, num_partitions); - std::tie(output2, offsets2) = cudf::hash_partition(input, columns_to_hash, num_partitions); + auto [output1, offsets1] = cudf::hash_partition(input, columns_to_hash, num_partitions); + auto [output2, offsets2] = cudf::hash_partition(input, columns_to_hash, num_partitions); // Expect output to have size num_partitions EXPECT_EQ(static_cast(num_partitions), offsets1.size()); @@ -367,9 +349,7 @@ TEST_F(HashPartition, FixedPointColumnsToHash) auto columns_to_hash = std::vector({0}); cudf::size_type const num_partitions = 1; - std::unique_ptr first_result; - std::vector first_offsets; - std::tie(first_result, first_offsets) = + auto [first_result, first_offsets] = cudf::hash_partition(first_input, columns_to_hash, num_partitions); // Expect offsets to be equal and num_partitions in length diff --git a/cpp/tests/rolling/grouped_rolling_test.cpp b/cpp/tests/rolling/grouped_rolling_test.cpp index f484661eee8..3a69c13c889 100644 --- a/cpp/tests/rolling/grouped_rolling_test.cpp +++ b/cpp/tests/rolling/grouped_rolling_test.cpp @@ -340,10 +340,8 @@ class GroupedRollingTest : public cudf::test::BaseFixture { thrust::host_vector ref_valid(num_rows); // input data and mask - thrust::host_vector in_col; - std::vector in_valid; - std::tie(in_col, in_valid) = cudf::test::to_host(input); - bitmask_type* valid_mask = in_valid.data(); + auto [in_col, in_valid] = cudf::test::to_host(input); + bitmask_type* valid_mask = in_valid.data(); agg_op op; for (size_type i = 0; i < num_rows; i++) { @@ -973,10 +971,8 @@ class GroupedTimeRangeRollingTest : public cudf::test::BaseFixture { thrust::host_vector ref_valid(num_rows); // input data and mask - thrust::host_vector in_col; - std::vector in_valid; - std::tie(in_col, in_valid) = cudf::test::to_host(input); - bitmask_type* valid_mask = in_valid.data(); + auto [in_col, in_valid] = cudf::test::to_host(input); + bitmask_type* valid_mask = in_valid.data(); agg_op op; for (size_type i = 0; i < num_rows; i++) { diff --git a/cpp/tests/rolling/rolling_test.cpp b/cpp/tests/rolling/rolling_test.cpp index c54fe073e3a..9549569d9f6 100644 --- a/cpp/tests/rolling/rolling_test.cpp +++ b/cpp/tests/rolling/rolling_test.cpp @@ -552,10 +552,8 @@ class RollingTest : public cudf::test::BaseFixture { thrust::host_vector ref_valid(num_rows); // input data and mask - thrust::host_vector in_col; - std::vector in_valid; - std::tie(in_col, in_valid) = cudf::test::to_host(input); - bitmask_type* valid_mask = in_valid.data(); + auto [in_col, in_valid] = cudf::test::to_host(input); + bitmask_type* valid_mask = in_valid.data(); agg_op op; for (size_type i = 0; i < num_rows; i++) { diff --git a/cpp/tests/sort/rank_test.cpp b/cpp/tests/sort/rank_test.cpp index c4d0b6b04f4..28c9b40de11 100644 --- a/cpp/tests/sort/rank_test.cpp +++ b/cpp/tests/sort/rank_test.cpp @@ -91,8 +91,7 @@ struct Rank : public BaseFixture { test_case_t{table_view{{col1, col2, col3}}, table_view{{col1_rank, col2_rank, col3_rank}}}, }) { - table_view input, output; - std::tie(input, output) = test_case; + auto [input, output] = test_case; run_rank_test(input, output, diff --git a/cpp/tests/transform/row_bit_count_test.cu b/cpp/tests/transform/row_bit_count_test.cu index 8ed50b6eae0..9c3326cf575 100644 --- a/cpp/tests/transform/row_bit_count_test.cu +++ b/cpp/tests/transform/row_bit_count_test.cu @@ -123,9 +123,7 @@ TYPED_TEST(RowBitCountTyped, Lists) { using T = TypeParam; - std::unique_ptr col; - std::unique_ptr expected_sizes; - std::tie(col, expected_sizes) = build_list_column(); + auto [col, expected_sizes] = build_list_column(); table_view t({*col}); auto result = cudf::row_bit_count(t); @@ -326,9 +324,7 @@ TEST_F(RowBitCount, StructsNoNulls) TEST_F(RowBitCount, StructsNulls) { - std::unique_ptr struct_col; - std::unique_ptr expected_sizes; - std::tie(struct_col, expected_sizes) = build_struct_column(); + auto [struct_col, expected_sizes] = build_struct_column(); table_view t({*struct_col}); auto result = cudf::row_bit_count(t); @@ -440,9 +436,7 @@ TEST_F(RowBitCount, NestedTypes) { // List, float, List, int16> { - std::unique_ptr col_no_nulls; - std::unique_ptr expected_sizes; - std::tie(col_no_nulls, expected_sizes) = + auto [col_no_nulls, expected_sizes] = build_nested_and_expected_column({1, 1, 1, 1, 1, 1, 1, 1}); table_view no_nulls_t({*col_no_nulls}); auto no_nulls_result = cudf::row_bit_count(no_nulls_t); @@ -600,19 +594,13 @@ struct sum_functor { TEST_F(RowBitCount, Table) { // complex nested column - std::unique_ptr col0; - std::unique_ptr col0_sizes; - std::tie(col0, col0_sizes) = build_nested_and_expected_column({1, 1, 1, 1, 1, 1, 1, 1}); + auto [col0, col0_sizes] = build_nested_and_expected_column({1, 1, 1, 1, 1, 1, 1, 1}); // struct column - std::unique_ptr col1; - std::unique_ptr col1_sizes; - std::tie(col1, col1_sizes) = build_struct_column(); + auto [col1, col1_sizes] = build_struct_column(); // list column - std::unique_ptr col2; - std::unique_ptr col2_sizes; - std::tie(col2, col2_sizes) = build_list_column(); + auto [col2, col2_sizes] = build_list_column(); table_view t({*col0, *col1, *col2}); auto result = cudf::row_bit_count(t); diff --git a/cpp/tests/unary/cast_tests.cpp b/cpp/tests/unary/cast_tests.cpp index f53498bccec..16fb02e06bc 100644 --- a/cpp/tests/unary/cast_tests.cpp +++ b/cpp/tests/unary/cast_tests.cpp @@ -174,9 +174,7 @@ void validate_cast_result(cudf::column_view expected, cudf::column_view actual) { using namespace cudf::test; // round-trip through the host because sizeof(T) may not equal sizeof(R) - thrust::host_vector h_data; - std::vector null_mask; - std::tie(h_data, null_mask) = to_host(expected); + auto [h_data, null_mask] = to_host(expected); if (null_mask.empty()) { CUDF_TEST_EXPECT_COLUMNS_EQUAL(make_column(h_data), actual); } else {