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

Use structured bindings instead of std::tie #10726

Merged
merged 1 commit into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
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
30 changes: 12 additions & 18 deletions cpp/include/cudf_test/column_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,13 +702,11 @@ class strings_column_wrapper : public detail::column_wrapper {
template <typename StringsIterator>
strings_column_wrapper(StringsIterator begin, StringsIterator end) : column_wrapper{}
{
std::vector<char> chars;
std::vector<cudf::size_type> 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);
}

/**
Expand Down Expand Up @@ -744,14 +742,12 @@ class strings_column_wrapper : public detail::column_wrapper {
: column_wrapper{}
{
size_type num_strings = std::distance(begin, end);
std::vector<char> chars;
std::vector<size_type> 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);
}

/**
Expand Down Expand Up @@ -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<std::unique_ptr<column>> stubs;
std::vector<column_view> 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;
Expand Down
14 changes: 3 additions & 11 deletions cpp/src/io/parquet/page_enc.cu
Original file line number Diff line number Diff line change
Expand Up @@ -1662,9 +1662,7 @@ dremel_data get_dremel_data(column_view h_col,
}
}

std::unique_ptr<rmm::device_buffer> 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<column_device_view>(nesting_levels, stream);

thrust::exclusive_scan(
Expand Down Expand Up @@ -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<size_type> empties(0, stream);
rmm::device_uvector<size_type> 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
Expand Down Expand Up @@ -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<size_type> empties(0, stream);
rmm::device_uvector<size_type> 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(),
Expand Down
6 changes: 1 addition & 5 deletions cpp/src/io/parquet/reader_impl.cu
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 1 addition & 4 deletions cpp/src/quantiles/quantile.cu
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 1 addition & 4 deletions cpp/src/reshape/interleave_columns.cu
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,7 @@ struct interleave_columns_impl<T, std::enable_if_t<cudf::is_fixed_width<T>()>> {
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);

Expand Down
4 changes: 1 addition & 3 deletions cpp/src/rolling/rolling_collect_list.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,7 @@ std::unique_ptr<column> 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<size_type>(0),
thrust::make_counting_iterator<size_type>(input.size()),
[preceding_begin, following_begin, min_periods] __device__(auto i) {
Expand Down
4 changes: 1 addition & 3 deletions cpp/src/strings/copying/concatenate.cu
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ auto create_strings_device_views(host_span<column_view const> views, rmm::cuda_s
{
CUDF_FUNC_RANGE();
// Assemble contiguous array of device views
std::unique_ptr<rmm::device_buffer> 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<column_device_view>(views, stream);

// Compute the partition offsets and size of offset column
Expand Down
48 changes: 14 additions & 34 deletions cpp/tests/partitioning/hash_partition_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ TEST_F(HashPartition, ZeroPartitions)
auto columns_to_hash = std::vector<cudf::size_type>({2});

cudf::size_type const num_partitions = 0;
std::unique_ptr<cudf::table> output;
std::vector<cudf::size_type> 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());
Expand All @@ -87,9 +85,7 @@ TEST_F(HashPartition, ZeroRows)
auto columns_to_hash = std::vector<cudf::size_type>({2});

cudf::size_type const num_partitions = 3;
std::unique_ptr<cudf::table> output;
std::vector<cudf::size_type> 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());
Expand All @@ -104,9 +100,7 @@ TEST_F(HashPartition, ZeroColumns)
auto columns_to_hash = std::vector<cudf::size_type>({});

cudf::size_type const num_partitions = 3;
std::unique_ptr<cudf::table> output;
std::vector<cudf::size_type> 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());
Expand All @@ -124,10 +118,8 @@ TEST_F(HashPartition, MixedColumnTypes)
auto columns_to_hash = std::vector<cudf::size_type>({0, 2});

cudf::size_type const num_partitions = 3;
std::unique_ptr<cudf::table> output1, output2;
std::vector<cudf::size_type> 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<size_t>(num_partitions), offsets1.size());
Expand All @@ -148,9 +140,7 @@ TEST_F(HashPartition, NullableStrings)
std::vector<cudf::size_type> const columns_to_hash({0});
cudf::size_type const num_partitions = 3;

std::unique_ptr<cudf::table> result;
std::vector<cudf::size_type> 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());
Expand All @@ -167,11 +157,9 @@ TEST_F(HashPartition, ColumnsToHash)
auto columns_to_hash = std::vector<cudf::size_type>({0});

cudf::size_type const num_partitions = 3;
std::unique_ptr<cudf::table> first_result, second_result;
std::vector<cudf::size_type> 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
Expand Down Expand Up @@ -228,11 +216,9 @@ TEST_F(HashPartition, CustomSeedValue)
auto columns_to_hash = std::vector<cudf::size_type>({0, 2});

cudf::size_type const num_partitions = 3;
std::unique_ptr<cudf::table> output1, output2;
std::vector<cudf::size_type> 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
Expand Down Expand Up @@ -260,9 +246,7 @@ TYPED_TEST(HashPartitionFixedWidth, NullableFixedWidth)
std::vector<cudf::size_type> const columns_to_hash({0});
cudf::size_type const num_partitions = 3;

std::unique_ptr<cudf::table> result;
std::vector<cudf::size_type> 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());
Expand Down Expand Up @@ -294,10 +278,8 @@ void run_fixed_width_test(size_t cols,
auto columns_to_hash = std::vector<cudf::size_type>(cols);
std::iota(columns_to_hash.begin(), columns_to_hash.end(), 0);

std::unique_ptr<cudf::table> output1, output2;
std::vector<cudf::size_type> 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<size_t>(num_partitions), offsets1.size());
Expand Down Expand Up @@ -367,9 +349,7 @@ TEST_F(HashPartition, FixedPointColumnsToHash)
auto columns_to_hash = std::vector<cudf::size_type>({0});

cudf::size_type const num_partitions = 1;
std::unique_ptr<cudf::table> first_result;
std::vector<cudf::size_type> 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
Expand Down
12 changes: 4 additions & 8 deletions cpp/tests/rolling/grouped_rolling_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,8 @@ class GroupedRollingTest : public cudf::test::BaseFixture {
thrust::host_vector<bool> ref_valid(num_rows);

// input data and mask
thrust::host_vector<T> in_col;
std::vector<bitmask_type> in_valid;
std::tie(in_col, in_valid) = cudf::test::to_host<T>(input);
bitmask_type* valid_mask = in_valid.data();
auto [in_col, in_valid] = cudf::test::to_host<T>(input);
bitmask_type* valid_mask = in_valid.data();

agg_op op;
for (size_type i = 0; i < num_rows; i++) {
Expand Down Expand Up @@ -973,10 +971,8 @@ class GroupedTimeRangeRollingTest : public cudf::test::BaseFixture {
thrust::host_vector<bool> ref_valid(num_rows);

// input data and mask
thrust::host_vector<T> in_col;
std::vector<bitmask_type> in_valid;
std::tie(in_col, in_valid) = cudf::test::to_host<T>(input);
bitmask_type* valid_mask = in_valid.data();
auto [in_col, in_valid] = cudf::test::to_host<T>(input);
bitmask_type* valid_mask = in_valid.data();

agg_op op;
for (size_type i = 0; i < num_rows; i++) {
Expand Down
6 changes: 2 additions & 4 deletions cpp/tests/rolling/rolling_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,10 +552,8 @@ class RollingTest : public cudf::test::BaseFixture {
thrust::host_vector<bool> ref_valid(num_rows);

// input data and mask
thrust::host_vector<T> in_col;
std::vector<bitmask_type> in_valid;
std::tie(in_col, in_valid) = cudf::test::to_host<T>(input);
bitmask_type* valid_mask = in_valid.data();
auto [in_col, in_valid] = cudf::test::to_host<T>(input);
bitmask_type* valid_mask = in_valid.data();

agg_op op;
for (size_type i = 0; i < num_rows; i++) {
Expand Down
3 changes: 1 addition & 2 deletions cpp/tests/sort/rank_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
24 changes: 6 additions & 18 deletions cpp/tests/transform/row_bit_count_test.cu
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,7 @@ TYPED_TEST(RowBitCountTyped, Lists)
{
using T = TypeParam;

std::unique_ptr<column> col;
std::unique_ptr<column> expected_sizes;
std::tie(col, expected_sizes) = build_list_column<T>();
auto [col, expected_sizes] = build_list_column<T>();

table_view t({*col});
auto result = cudf::row_bit_count(t);
Expand Down Expand Up @@ -326,9 +324,7 @@ TEST_F(RowBitCount, StructsNoNulls)

TEST_F(RowBitCount, StructsNulls)
{
std::unique_ptr<column> struct_col;
std::unique_ptr<column> 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);

Expand Down Expand Up @@ -440,9 +436,7 @@ TEST_F(RowBitCount, NestedTypes)
{
// List<Struct<List<int>, float, List<int>, int16>
{
std::unique_ptr<column> col_no_nulls;
std::unique_ptr<column> 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);
Expand Down Expand Up @@ -600,19 +594,13 @@ struct sum_functor {
TEST_F(RowBitCount, Table)
{
// complex nested column
std::unique_ptr<column> col0;
std::unique_ptr<column> 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<column> col1;
std::unique_ptr<column> col1_sizes;
std::tie(col1, col1_sizes) = build_struct_column();
auto [col1, col1_sizes] = build_struct_column();

// list column
std::unique_ptr<column> col2;
std::unique_ptr<column> col2_sizes;
std::tie(col2, col2_sizes) = build_list_column<int16_t>();
auto [col2, col2_sizes] = build_list_column<int16_t>();

table_view t({*col0, *col1, *col2});
auto result = cudf::row_bit_count(t);
Expand Down
4 changes: 1 addition & 3 deletions cpp/tests/unary/cast_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> h_data;
std::vector<cudf::bitmask_type> null_mask;
std::tie(h_data, null_mask) = to_host<T>(expected);
auto [h_data, null_mask] = to_host<T>(expected);
if (null_mask.empty()) {
CUDF_TEST_EXPECT_COLUMNS_EQUAL(make_column<R, T>(h_data), actual);
} else {
Expand Down