diff --git a/cpp/include/cudf/detail/scatter.cuh b/cpp/include/cudf/detail/scatter.cuh index dbf7bfa9527..d5484b14510 100644 --- a/cpp/include/cudf/detail/scatter.cuh +++ b/cpp/include/cudf/detail/scatter.cuh @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2023, NVIDIA CORPORATION. + * Copyright (c) 2020-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -212,7 +213,7 @@ struct column_scatterer_impl { // check the keys match dictionary_column_view const source(source_in); dictionary_column_view const target(target_in); - CUDF_EXPECTS(source.keys().type() == target.keys().type(), + CUDF_EXPECTS(cudf::column_types_equal(source.keys(), target.keys()), "scatter dictionary keys must be the same type"); // first combine keys so both dictionaries have the same set diff --git a/cpp/include/cudf/utilities/type_checks.hpp b/cpp/include/cudf/utilities/type_checks.hpp index b925fc8ae92..2b326afe1f8 100644 --- a/cpp/include/cudf/utilities/type_checks.hpp +++ b/cpp/include/cudf/utilities/type_checks.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023, NVIDIA CORPORATION. + * Copyright (c) 2021-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,8 @@ #include +#include + namespace cudf { /** @@ -47,4 +49,23 @@ bool column_types_equal(column_view const& lhs, column_view const& rhs); */ bool column_types_equivalent(column_view const& lhs, column_view const& rhs); +/** + * @brief Compare the types of a range of `column_views` + * + * This function returns true if cudf::column_types_equal is true for every + * pair of consecutive columns in the range. + * + * @tparam ForwardIt Forward iterator + * @param first The first column + * @param last The last column + * @return true if all column types match + */ +template +inline bool all_column_types_equal(ForwardIt first, ForwardIt last) +{ + return std::all_of(std::next(first), last, [want = *first](auto const& c) { + return cudf::column_types_equal(want, c); + }); +} + } // namespace cudf diff --git a/cpp/src/copying/concatenate.cu b/cpp/src/copying/concatenate.cu index b1d850e0b27..d3c9a5f3579 100644 --- a/cpp/src/copying/concatenate.cu +++ b/cpp/src/copying/concatenate.cu @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -460,11 +461,7 @@ void traverse_children::operator()(host_span */ void bounds_and_type_check(host_span cols, rmm::cuda_stream_view stream) { - CUDF_EXPECTS(std::all_of(cols.begin(), - cols.end(), - [expected_type = cols.front().type()](auto const& c) { - return c.type() == expected_type; - }), + CUDF_EXPECTS(cudf::all_column_types_equal(cols.begin(), cols.end()), "Type mismatch in columns to concatenate."); // total size of all concatenated rows diff --git a/cpp/src/copying/copy.cu b/cpp/src/copying/copy.cu index 6b7fae32d48..9fe4c31ced5 100644 --- a/cpp/src/copying/copy.cu +++ b/cpp/src/copying/copy.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2023, NVIDIA CORPORATION. + * Copyright (c) 2019-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -358,7 +359,7 @@ std::unique_ptr copy_if_else(column_view const& lhs, CUDF_EXPECTS(boolean_mask.size() == lhs.size(), "Boolean mask column must be the same size as lhs and rhs columns"); CUDF_EXPECTS(lhs.size() == rhs.size(), "Both columns must be of the size"); - CUDF_EXPECTS(lhs.type() == rhs.type(), "Both inputs must be of the same type"); + CUDF_EXPECTS(cudf::column_types_equal(lhs, rhs), "Both inputs must be of the same type"); return copy_if_else(lhs, rhs, lhs.has_nulls(), rhs.has_nulls(), boolean_mask, stream, mr); } @@ -372,7 +373,9 @@ std::unique_ptr copy_if_else(scalar const& lhs, CUDF_EXPECTS(boolean_mask.size() == rhs.size(), "Boolean mask column must be the same size as rhs column"); - auto rhs_type = + // TODO: Need some utility like cudf::column_types_equivalent for scalars to + // ensure nested types are handled correctly. + auto const rhs_type = cudf::is_dictionary(rhs.type()) ? cudf::dictionary_column_view(rhs).keys_type() : rhs.type(); CUDF_EXPECTS(lhs.type() == rhs_type, "Both inputs must be of the same type"); @@ -388,6 +391,8 @@ std::unique_ptr copy_if_else(column_view const& lhs, CUDF_EXPECTS(boolean_mask.size() == lhs.size(), "Boolean mask column must be the same size as lhs column"); + // TODO: Need some utility like cudf::column_types_equivalent for scalars to + // ensure nested types are handled correctly. auto lhs_type = cudf::is_dictionary(lhs.type()) ? cudf::dictionary_column_view(lhs).keys_type() : lhs.type(); CUDF_EXPECTS(lhs_type == rhs.type(), "Both inputs must be of the same type"); @@ -401,6 +406,8 @@ std::unique_ptr copy_if_else(scalar const& lhs, rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* mr) { + // TODO: Need some utility like cudf::column_types_equivalent for scalars to + // ensure nested types are handled correctly. CUDF_EXPECTS(lhs.type() == rhs.type(), "Both inputs must be of the same type"); return copy_if_else( lhs, rhs, !lhs.is_valid(stream), !rhs.is_valid(stream), boolean_mask, stream, mr); diff --git a/cpp/src/copying/copy_range.cu b/cpp/src/copying/copy_range.cu index 61d51f1d284..e8a1f900ba3 100644 --- a/cpp/src/copying/copy_range.cu +++ b/cpp/src/copying/copy_range.cu @@ -32,6 +32,7 @@ #include #include #include +#include #include @@ -145,7 +146,7 @@ std::unique_ptr out_of_place_copy_range_dispatch::operator()= 0) && (target_begin <= target.size() - (source_end - source_begin)), "Range is out of bounds."); - CUDF_EXPECTS(target.type() == source.type(), "Data type mismatch."); + CUDF_EXPECTS(cudf::column_types_equal(target, source), "Data type mismatch."); CUDF_EXPECTS(target.nullable() || not source.has_nulls(), "target should be nullable if source has null values."); @@ -233,7 +234,7 @@ std::unique_ptr copy_range(column_view const& source, (source_begin <= source_end) && (target_begin >= 0) && (target_begin <= target.size() - (source_end - source_begin)), "Range is out of bounds."); - CUDF_EXPECTS(target.type() == source.type(), "Data type mismatch."); + CUDF_EXPECTS(cudf::column_types_equal(target, source), "Data type mismatch."); return cudf::type_dispatcher( target.type(), diff --git a/cpp/src/copying/scatter.cu b/cpp/src/copying/scatter.cu index baa5d85d4d4..b9755919e07 100644 --- a/cpp/src/copying/scatter.cu +++ b/cpp/src/copying/scatter.cu @@ -109,6 +109,8 @@ struct column_scalar_scatterer_impl { rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* mr) const { + // TODO: Need some utility like cudf::column_types_equivalent for scalars to + // ensure nested types are handled correctly. CUDF_EXPECTS(source.get().type() == target.type(), "scalar and column types must match"); // make a copy of data and null mask from source @@ -140,6 +142,8 @@ struct column_scalar_scatterer_impl { rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* mr) const { + // TODO: Need some utility like cudf::column_types_equivalent for scalars to + // ensure nested types are handled correctly. CUDF_EXPECTS(source.get().type() == target.type(), "scalar and column types must match"); auto const scalar_impl = static_cast(&source.get()); @@ -299,12 +303,7 @@ std::unique_ptr scatter(table_view const& source, "Number of columns in source and target not equal"); CUDF_EXPECTS(scatter_map.size() <= source.num_rows(), "Size of scatter map must be equal to or less than source rows"); - CUDF_EXPECTS(std::equal(source.begin(), - source.end(), - target.begin(), - [](auto const& col1, auto const& col2) { - return col1.type().id() == col2.type().id(); - }), + CUDF_EXPECTS(cudf::have_same_types(source, target), "Column types do not match between source and target"); CUDF_EXPECTS(not scatter_map.has_nulls(), "Scatter map contains nulls"); @@ -430,13 +429,8 @@ std::unique_ptr
boolean_mask_scatter(table_view const& input, "Boolean mask size and number of target rows mismatch"); CUDF_EXPECTS(boolean_mask.type().id() == type_id::BOOL8, "Mask must be of Boolean type"); // Count valid pair of input and columns as per type at each column index i - CUDF_EXPECTS( - std::all_of(thrust::counting_iterator(0), - thrust::counting_iterator(target.num_columns()), - [&input, &target](auto index) { - return ((input.column(index).type().id()) == (target.column(index).type().id())); - }), - "Type mismatch in input column and target column"); + CUDF_EXPECTS(cudf::have_same_types(input, target), + "Type mismatch in input column and target column"); if (target.num_rows() != 0) { std::vector> out_columns(target.num_columns()); @@ -470,6 +464,8 @@ std::unique_ptr
boolean_mask_scatter( // Count valid pair of input and columns as per type at each column/scalar index i CUDF_EXPECTS( + // TODO: Need some utility like cudf::column_types_equivalent for scalars to + // ensure nested types are handled correctly. std::all_of(thrust::counting_iterator(0), thrust::counting_iterator(target.num_columns()), [&input, &target](auto index) { diff --git a/cpp/src/copying/shift.cu b/cpp/src/copying/shift.cu index 89d6551737b..f9308b12659 100644 --- a/cpp/src/copying/shift.cu +++ b/cpp/src/copying/shift.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2023, NVIDIA CORPORATION. + * Copyright (c) 2019-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -156,6 +156,8 @@ std::unique_ptr shift(column_view const& input, rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* mr) { + // TODO: Need some utility like cudf::column_types_equivalent for scalars to + // ensure nested types are handled correctly. CUDF_EXPECTS(input.type() == fill_value.type(), "shift requires each fill value type to match the corresponding column type."); diff --git a/cpp/src/dictionary/add_keys.cu b/cpp/src/dictionary/add_keys.cu index 3973100aced..c992c7eac3f 100644 --- a/cpp/src/dictionary/add_keys.cu +++ b/cpp/src/dictionary/add_keys.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2023, NVIDIA CORPORATION. + * Copyright (c) 2020-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,7 @@ #include #include #include +#include #include @@ -53,7 +54,7 @@ std::unique_ptr add_keys(dictionary_column_view const& dictionary_column { CUDF_EXPECTS(!new_keys.has_nulls(), "Keys must not have nulls"); auto old_keys = dictionary_column.keys(); // [a,b,c,d,f] - CUDF_EXPECTS(new_keys.type() == old_keys.type(), "Keys must be the same type"); + CUDF_EXPECTS(cudf::column_types_equal(new_keys, old_keys), "Keys must be the same type"); // first, concatenate the keys together // [a,b,c,d,f] + [d,b,e] = [a,b,c,d,f,d,b,e] auto combined_keys = cudf::detail::concatenate( diff --git a/cpp/src/dictionary/detail/concatenate.cu b/cpp/src/dictionary/detail/concatenate.cu index 17295fb0345..671df3df9e4 100644 --- a/cpp/src/dictionary/detail/concatenate.cu +++ b/cpp/src/dictionary/detail/concatenate.cu @@ -220,6 +220,8 @@ std::unique_ptr concatenate(host_span columns, // empty column may not have keys so we create an empty column_view place-holder if (dict_view.is_empty()) return column_view{keys_type, 0, nullptr, nullptr, 0}; auto keys = dict_view.keys(); + // TODO: Compare using cudf::column_types_equal to ensure nested types are + // handled correctly. CUDF_EXPECTS(keys.type() == keys_type, "key types of all dictionary columns must match"); return keys; }); diff --git a/cpp/src/dictionary/remove_keys.cu b/cpp/src/dictionary/remove_keys.cu index 86b70f1119b..dc575163c3f 100644 --- a/cpp/src/dictionary/remove_keys.cu +++ b/cpp/src/dictionary/remove_keys.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2023, NVIDIA CORPORATION. + * Copyright (c) 2020-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -154,7 +155,7 @@ std::unique_ptr remove_keys(dictionary_column_view const& dictionary_col { CUDF_EXPECTS(!keys_to_remove.has_nulls(), "keys_to_remove must not have nulls"); auto const keys_view = dictionary_column.keys(); - CUDF_EXPECTS(keys_view.type() == keys_to_remove.type(), "keys types must match"); + CUDF_EXPECTS(cudf::column_types_equal(keys_view, keys_to_remove), "keys types must match"); // locate keys to remove by searching the keys column auto const matches = cudf::detail::contains(keys_to_remove, keys_view, stream, mr); diff --git a/cpp/src/dictionary/replace.cu b/cpp/src/dictionary/replace.cu index 7069993866c..d2673ab19c8 100644 --- a/cpp/src/dictionary/replace.cu +++ b/cpp/src/dictionary/replace.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2022, NVIDIA CORPORATION. + * Copyright (c) 2020-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +24,7 @@ #include #include #include +#include #include @@ -83,7 +84,7 @@ std::unique_ptr replace_nulls(dictionary_column_view const& input, { if (input.is_empty()) { return cudf::empty_like(input.parent()); } if (!input.has_nulls()) { return std::make_unique(input.parent(), stream, mr); } - CUDF_EXPECTS(input.keys().type() == replacement.keys().type(), "keys must match"); + CUDF_EXPECTS(cudf::column_types_equal(input.keys(), replacement.keys()), "keys must match"); CUDF_EXPECTS(replacement.size() == input.size(), "column sizes must match"); // first combine the keys so both input dictionaries have the same set @@ -118,6 +119,8 @@ std::unique_ptr replace_nulls(dictionary_column_view const& input, if (!input.has_nulls() || !replacement.is_valid(stream)) { return std::make_unique(input.parent(), stream, mr); } + // TODO: Need some utility like cudf::column_types_equivalent for scalars to + // ensure nested types are handled correctly. CUDF_EXPECTS(input.keys().type() == replacement.type(), "keys must match scalar type"); // first add the replacement to the keys so only the indices need to be processed diff --git a/cpp/src/dictionary/search.cu b/cpp/src/dictionary/search.cu index e35aded1984..d432bef4982 100644 --- a/cpp/src/dictionary/search.cu +++ b/cpp/src/dictionary/search.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2023, NVIDIA CORPORATION. + * Copyright (c) 2020-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -73,6 +73,8 @@ struct find_index_fn { { if (!key.is_valid(stream)) return type_dispatcher(input.indices().type(), dispatch_scalar_index{}, 0, false, stream, mr); + // TODO: Need some utility like cudf::column_types_equivalent for scalars to + // ensure nested types are handled correctly. CUDF_EXPECTS(input.keys().type() == key.type(), "search key type must match dictionary keys type"); @@ -115,6 +117,8 @@ struct find_insert_index_fn { { if (!key.is_valid(stream)) return type_dispatcher(input.indices().type(), dispatch_scalar_index{}, 0, false, stream, mr); + // TODO: Need some utility like cudf::column_types_equivalent for scalars to + // ensure nested types are handled correctly. CUDF_EXPECTS(input.keys().type() == key.type(), "search key type must match dictionary keys type"); diff --git a/cpp/src/dictionary/set_keys.cu b/cpp/src/dictionary/set_keys.cu index b49cf7850b1..c48de765450 100644 --- a/cpp/src/dictionary/set_keys.cu +++ b/cpp/src/dictionary/set_keys.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2023, NVIDIA CORPORATION. + * Copyright (c) 2020-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -115,7 +116,6 @@ struct dispatch_compute_indices { } // namespace -// std::unique_ptr set_keys(dictionary_column_view const& dictionary_column, column_view const& new_keys, rmm::cuda_stream_view stream, @@ -123,7 +123,7 @@ std::unique_ptr set_keys(dictionary_column_view const& dictionary_column { CUDF_EXPECTS(!new_keys.has_nulls(), "keys parameter must not have nulls"); auto keys = dictionary_column.keys(); - CUDF_EXPECTS(keys.type() == new_keys.type(), "keys types must match"); + CUDF_EXPECTS(cudf::column_types_equal(keys, new_keys), "keys types must match"); // copy the keys -- use cudf::distinct to make sure there are no duplicates, // then sort the results. diff --git a/cpp/src/filling/fill.cu b/cpp/src/filling/fill.cu index 42d1f7592ec..ec64f81fc75 100644 --- a/cpp/src/filling/fill.cu +++ b/cpp/src/filling/fill.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2023, NVIDIA CORPORATION. + * Copyright (c) 2019-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -109,6 +109,8 @@ struct out_of_place_fill_range_dispatch { rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* mr) { + // TODO: Need some utility like cudf::column_types_equivalent for scalars to + // ensure nested types are handled correctly. CUDF_EXPECTS(input.type() == value.type(), "Data type mismatch."); auto p_ret = std::make_unique(input, stream, mr); @@ -136,6 +138,8 @@ std::unique_ptr out_of_place_fill_range_dispatch::operator(); auto p_scalar = static_cast(&value); @@ -152,6 +156,8 @@ std::unique_ptr out_of_place_fill_range_dispatch::operator()(input, stream, mr); cudf::dictionary_column_view const target(input); + // TODO: Need some utility like cudf::column_types_equivalent for scalars to + // ensure nested types are handled correctly. CUDF_EXPECTS(target.keys().type() == value.type(), "Data type mismatch."); // if the scalar is invalid, then just copy the column and fill the null mask @@ -218,6 +224,8 @@ void fill_in_place(mutable_column_view& destination, "Range is out of bounds."); CUDF_EXPECTS(destination.nullable() || value.is_valid(stream), "destination should be nullable or value should be non-null."); + // TODO: Need some utility like cudf::column_types_equivalent for scalars to + // ensure nested types are handled correctly. CUDF_EXPECTS(destination.type() == value.type(), "Data type mismatch."); if (end != begin) { // otherwise no-op diff --git a/cpp/src/filling/sequence.cu b/cpp/src/filling/sequence.cu index 99a17f8b0e0..3120991318b 100644 --- a/cpp/src/filling/sequence.cu +++ b/cpp/src/filling/sequence.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2023, NVIDIA CORPORATION. + * Copyright (c) 2020-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -127,6 +127,8 @@ std::unique_ptr sequence(size_type size, rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* mr) { + // TODO: Need some utility like cudf::column_types_equivalent for scalars to + // ensure nested types are handled correctly. CUDF_EXPECTS(init.type() == step.type(), "init and step must be of the same type."); CUDF_EXPECTS(size >= 0, "size must be >= 0"); CUDF_EXPECTS(is_numeric(init.type()), "Input scalar types must be numeric"); diff --git a/cpp/src/groupby/groupby.cu b/cpp/src/groupby/groupby.cu index e3c021eb66a..877780658b5 100644 --- a/cpp/src/groupby/groupby.cu +++ b/cpp/src/groupby/groupby.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2023, NVIDIA CORPORATION. + * Copyright (c) 2019-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -312,6 +312,8 @@ std::pair, std::unique_ptr
> groupby::shift( CUDF_EXPECTS(values.num_columns() == static_cast(fill_values.size()), "Mismatch number of fill_values and columns."); CUDF_EXPECTS( + // TODO: Need some utility like cudf::column_types_equivalent for scalars to + // ensure nested types are handled correctly. std::all_of(thrust::make_counting_iterator(0), thrust::make_counting_iterator(values.num_columns()), [&](auto i) { return values.column(i).type() == fill_values[i].get().type(); }), diff --git a/cpp/src/interop/dlpack.cpp b/cpp/src/interop/dlpack.cpp index 9f36280930d..794da3b9fbc 100644 --- a/cpp/src/interop/dlpack.cpp +++ b/cpp/src/interop/dlpack.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -230,9 +231,8 @@ DLManagedTensor* to_dlpack(table_view const& input, DLDataType const dltype = data_type_to_DLDataType(type); // Ensure all columns are the same type - CUDF_EXPECTS( - std::all_of(input.begin(), input.end(), [type](auto const& col) { return col.type() == type; }), - "All columns required to have same data type"); + CUDF_EXPECTS(cudf::all_column_types_equal(input.begin(), input.end()), + "All columns required to have same data type"); // Ensure none of the columns have nulls CUDF_EXPECTS( diff --git a/cpp/src/join/hash_join.cu b/cpp/src/join/hash_join.cu index 17616818a58..603c7ccc9cb 100644 --- a/cpp/src/join/hash_join.cu +++ b/cpp/src/join/hash_join.cu @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -568,12 +569,7 @@ hash_join::compute_hash_join(cudf::table_view const& probe, std::make_unique>(0, stream, mr)); } - CUDF_EXPECTS(std::equal(std::cbegin(_build), - std::cend(_build), - std::cbegin(probe), - std::cend(probe), - [](auto const& b, auto const& p) { return b.type() == p.type(); }), - "Mismatch in joining column data types"); + CUDF_EXPECTS(cudf::have_same_types(_build, probe), "Mismatch in joining column data types"); return probe_join_indices(probe, join, output_size, stream, mr); } diff --git a/cpp/src/labeling/label_bins.cu b/cpp/src/labeling/label_bins.cu index 9fecaa1ddb2..578288dfa3e 100644 --- a/cpp/src/labeling/label_bins.cu +++ b/cpp/src/labeling/label_bins.cu @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -207,8 +208,9 @@ std::unique_ptr label_bins(column_view const& input, rmm::mr::device_memory_resource* mr) { CUDF_FUNC_RANGE() - CUDF_EXPECTS((input.type() == left_edges.type()) && (input.type() == right_edges.type()), - "The input and edge columns must have the same types."); + CUDF_EXPECTS( + cudf::column_types_equal(input, left_edges) && cudf::column_types_equal(input, right_edges), + "The input and edge columns must have the same types."); CUDF_EXPECTS(left_edges.size() == right_edges.size(), "The left and right edge columns must be of the same length."); CUDF_EXPECTS(!left_edges.has_nulls() && !right_edges.has_nulls(), diff --git a/cpp/src/lists/combine/concatenate_rows.cu b/cpp/src/lists/combine/concatenate_rows.cu index baecef3b92d..9de567fc321 100644 --- a/cpp/src/lists/combine/concatenate_rows.cu +++ b/cpp/src/lists/combine/concatenate_rows.cu @@ -204,11 +204,8 @@ std::unique_ptr concatenate_rows(table_view const& input, input.end(), [](column_view const& col) { return col.type().id() == cudf::type_id::LIST; }), "All columns of the input table must be of lists column type."); - CUDF_EXPECTS( - std::all_of(std::next(input.begin()), - input.end(), - [a = *input.begin()](column_view const& b) { return column_types_equal(a, b); }), - "The types of entries in the input columns must be the same."); + CUDF_EXPECTS(cudf::all_column_types_equal(input.begin(), input.end()), + "The types of entries in the input columns must be the same."); auto const num_rows = input.num_rows(); auto const num_cols = input.num_columns(); diff --git a/cpp/src/lists/contains.cu b/cpp/src/lists/contains.cu index 378cf678f1f..2a7957fc180 100644 --- a/cpp/src/lists/contains.cu +++ b/cpp/src/lists/contains.cu @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -193,7 +194,7 @@ std::unique_ptr dispatch_index_of(lists_column_view const& lists, // comparisons. auto const child = lists.child(); - CUDF_EXPECTS(child.type() == search_keys.type(), + CUDF_EXPECTS(cudf::column_types_equal(child, search_keys), "Type/Scale of search key does not match list column element type.", cudf::data_type_error); CUDF_EXPECTS(search_keys.type().id() != type_id::EMPTY, "Type cannot be empty."); diff --git a/cpp/src/lists/sequences.cu b/cpp/src/lists/sequences.cu index f92ba782da7..7427619a5c0 100644 --- a/cpp/src/lists/sequences.cu +++ b/cpp/src/lists/sequences.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023, NVIDIA CORPORATION. + * Copyright (c) 2021-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -145,7 +146,7 @@ std::unique_ptr sequences(column_view const& starts, CUDF_EXPECTS(!steps_cv.has_nulls(), "steps input column must not have nulls."); CUDF_EXPECTS(starts.size() == steps_cv.size(), "starts and steps input columns must have the same number of rows."); - CUDF_EXPECTS(starts.type() == steps_cv.type(), + CUDF_EXPECTS(cudf::column_types_equal(starts, steps_cv), "starts and steps input columns must have the same type."); } diff --git a/cpp/src/reductions/reductions.cpp b/cpp/src/reductions/reductions.cpp index 23171baaa45..8f869848064 100644 --- a/cpp/src/reductions/reductions.cpp +++ b/cpp/src/reductions/reductions.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2023, NVIDIA CORPORATION. + * Copyright (c) 2019-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -153,6 +153,8 @@ std::unique_ptr reduce(column_view const& col, rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* mr) { + // TODO: Need some utility like cudf::column_types_equivalent for scalars to + // ensure nested types are handled correctly. CUDF_EXPECTS(!init.has_value() || col.type() == init.value().get().type(), "column and initial value must be the same type"); if (init.has_value() && !(agg.kind == aggregation::SUM || agg.kind == aggregation::PRODUCT || diff --git a/cpp/src/reductions/segmented/reductions.cpp b/cpp/src/reductions/segmented/reductions.cpp index cee82560794..5dae2057be5 100644 --- a/cpp/src/reductions/segmented/reductions.cpp +++ b/cpp/src/reductions/segmented/reductions.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023, NVIDIA CORPORATION. + * Copyright (c) 2022-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -111,6 +111,8 @@ std::unique_ptr segmented_reduce(column_view const& segmented_values, rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* mr) { + // TODO: Need some utility like cudf::column_types_equivalent for scalars to + // ensure nested types are handled correctly. CUDF_EXPECTS(!init.has_value() || segmented_values.type() == init.value().get().type(), "column and initial value must be the same type"); if (init.has_value() && !(agg.kind == aggregation::SUM || agg.kind == aggregation::PRODUCT || diff --git a/cpp/src/replace/clamp.cu b/cpp/src/replace/clamp.cu index 3cd1fdd20a2..195e680cfda 100644 --- a/cpp/src/replace/clamp.cu +++ b/cpp/src/replace/clamp.cu @@ -197,6 +197,8 @@ struct dispatch_clamp { rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* mr) { + // TODO: Need some utility like cudf::column_types_equivalent for scalars to + // ensure nested types are handled correctly. CUDF_EXPECTS(lo.type() == input.type(), "mismatching types of scalar and input"); auto lo_itr = make_optional_iterator(lo, nullate::YES{}); @@ -321,6 +323,8 @@ std::unique_ptr clamp(column_view const& input, rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* mr) { + // TODO: Need some utility like cudf::column_types_equivalent for scalars to + // ensure nested types are handled correctly. CUDF_EXPECTS(lo.type() == hi.type(), "mismatching types of limit scalars"); CUDF_EXPECTS(lo_replace.type() == hi_replace.type(), "mismatching types of replace scalars"); CUDF_EXPECTS(lo.type() == lo_replace.type(), "mismatching types of limit and replace scalars"); diff --git a/cpp/src/replace/nulls.cu b/cpp/src/replace/nulls.cu index 8ea229368cc..69df50343ec 100644 --- a/cpp/src/replace/nulls.cu +++ b/cpp/src/replace/nulls.cu @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -302,6 +303,8 @@ struct replace_nulls_scalar_kernel_forwarder { rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* mr) { + // TODO: Need some utility like cudf::column_types_equivalent for scalars to + // ensure nested types are handled correctly. CUDF_EXPECTS(input.type() == replacement.type(), "Data type mismatch"); std::unique_ptr output = cudf::detail::allocate_like( input, input.size(), cudf::mask_allocation_policy::NEVER, stream, mr); @@ -338,6 +341,8 @@ std::unique_ptr replace_nulls_scalar_kernel_forwarder::operator()< rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* mr) { + // TODO: Need some utility like cudf::column_types_equivalent for scalars to + // ensure nested types are handled correctly. CUDF_EXPECTS(input.type() == replacement.type(), "Data type mismatch"); cudf::strings_column_view input_s(input); cudf::string_scalar const& repl = static_cast(replacement); @@ -404,7 +409,7 @@ std::unique_ptr replace_nulls(cudf::column_view const& input, rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* mr) { - CUDF_EXPECTS(input.type() == replacement.type(), "Data type mismatch"); + CUDF_EXPECTS(cudf::column_types_equal(input, replacement), "Data type mismatch"); CUDF_EXPECTS(replacement.size() == input.size(), "Column size mismatch"); if (input.is_empty()) { return cudf::empty_like(input); } diff --git a/cpp/src/replace/replace.cu b/cpp/src/replace/replace.cu index 184c30246c7..01cc506db8b 100644 --- a/cpp/src/replace/replace.cu +++ b/cpp/src/replace/replace.cu @@ -48,6 +48,7 @@ #include #include #include +#include #include #include @@ -504,9 +505,9 @@ std::unique_ptr find_and_replace_all(cudf::column_view const& inpu CUDF_EXPECTS(values_to_replace.size() == replacement_values.size(), "values_to_replace and replacement_values size mismatch."); - CUDF_EXPECTS( - input_col.type() == values_to_replace.type() && input_col.type() == replacement_values.type(), - "Columns type mismatch"); + CUDF_EXPECTS(cudf::column_types_equal(input_col, values_to_replace) && + cudf::column_types_equal(input_col, replacement_values), + "Columns type mismatch"); CUDF_EXPECTS(not values_to_replace.has_nulls(), "values_to_replace must not have nulls"); if (input_col.is_empty() or values_to_replace.is_empty() or replacement_values.is_empty()) { diff --git a/cpp/src/rolling/detail/lead_lag_nested.cuh b/cpp/src/rolling/detail/lead_lag_nested.cuh index 66104fe5c77..80c7f7e8821 100644 --- a/cpp/src/rolling/detail/lead_lag_nested.cuh +++ b/cpp/src/rolling/detail/lead_lag_nested.cuh @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -98,7 +99,7 @@ std::unique_ptr compute_lead_lag_for_nested(aggregation::Kind op, { CUDF_EXPECTS(op == aggregation::LEAD || op == aggregation::LAG, "Unexpected aggregation type in compute_lead_lag_for_nested"); - CUDF_EXPECTS(default_outputs.type().id() == input.type().id(), + CUDF_EXPECTS(cudf::column_types_equal(input, default_outputs), "Defaults column type must match input column."); // Because LEAD/LAG. CUDF_EXPECTS(default_outputs.is_empty() || (input.size() == default_outputs.size()), diff --git a/cpp/src/search/contains_scalar.cu b/cpp/src/search/contains_scalar.cu index 0b344ec347b..01d7c103032 100644 --- a/cpp/src/search/contains_scalar.cu +++ b/cpp/src/search/contains_scalar.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2023, NVIDIA CORPORATION. + * Copyright (c) 2019-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -62,6 +62,8 @@ struct contains_scalar_dispatch { scalar const& needle, rmm::cuda_stream_view stream) const { + // TODO: Need some utility like cudf::column_types_equivalent for scalars to + // ensure nested types are handled correctly. CUDF_EXPECTS(haystack.type() == needle.type(), "Scalar and column types must match"); // Don't need to check for needle validity. If it is invalid, it should be handled by the caller // before dispatching to this function. @@ -87,6 +89,8 @@ struct contains_scalar_dispatch { scalar const& needle, rmm::cuda_stream_view stream) const { + // TODO: Need some utility like cudf::column_types_equivalent for scalars to + // ensure nested types are handled correctly. CUDF_EXPECTS(haystack.type() == needle.type(), "Scalar and column types must match"); // Don't need to check for needle validity. If it is invalid, it should be handled by the caller // before dispatching to this function. diff --git a/cpp/src/transform/one_hot_encode.cu b/cpp/src/transform/one_hot_encode.cu index 72f864346a4..2c00d278f04 100644 --- a/cpp/src/transform/one_hot_encode.cu +++ b/cpp/src/transform/one_hot_encode.cu @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -60,7 +61,8 @@ std::pair, table_view> one_hot_encode(column_view const& rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* mr) { - CUDF_EXPECTS(input.type() == categories.type(), "Mismatch type between input and categories."); + CUDF_EXPECTS(cudf::column_types_equal(input, categories), + "Mismatch type between input and categories."); if (categories.is_empty()) { return {make_empty_column(type_id::BOOL8), table_view{}}; }