From 4ab8bd192100ba37162286541623bfb96be405ee Mon Sep 17 00:00:00 2001 From: David Wendt Date: Tue, 11 Apr 2023 16:08:45 -0400 Subject: [PATCH 1/2] Set null-count in linked_column_view conversion operator --- cpp/CMakeLists.txt | 1 + .../cudf/detail/utilities/linked_column.hpp | 38 +++--------- cpp/src/utilities/linked_column.cpp | 61 +++++++++++++++++++ 3 files changed, 70 insertions(+), 30 deletions(-) create mode 100644 cpp/src/utilities/linked_column.cpp diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 7d6e31d039e..9e091592754 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -604,6 +604,7 @@ add_library( src/unary/nan_ops.cu src/unary/null_ops.cu src/utilities/default_stream.cpp + src/utilities/linked_column.cpp src/utilities/logger.cpp src/utilities/traits.cpp src/utilities/type_checks.cpp diff --git a/cpp/include/cudf/detail/utilities/linked_column.hpp b/cpp/include/cudf/detail/utilities/linked_column.hpp index 059e32730e5..e03fb9a99ff 100644 --- a/cpp/include/cudf/detail/utilities/linked_column.hpp +++ b/cpp/include/cudf/detail/utilities/linked_column.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, NVIDIA CORPORATION. + * Copyright (c) 2022-2023, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,9 +16,11 @@ #pragma once +#include #include -#include +#include +#include namespace cudf::detail { @@ -35,30 +37,11 @@ struct linked_column_view : public column_view_base { linked_column_view(linked_column_view const&) = delete; linked_column_view& operator=(linked_column_view const&) = delete; - linked_column_view(column_view const& col) : linked_column_view(nullptr, col) {} + linked_column_view(column_view const& col); - linked_column_view(linked_column_view* parent, column_view const& col) - : column_view_base(col), parent(parent) - { - children.reserve(col.num_children()); - std::transform( - col.child_begin(), col.child_end(), std::back_inserter(children), [&](column_view const& c) { - return std::make_shared(this, c); - }); - } + linked_column_view(linked_column_view* parent, column_view const& col); - operator column_view() const - { - auto child_it = thrust::make_transform_iterator( - children.begin(), [](auto const& c) { return static_cast(*c); }); - return column_view(this->type(), - this->size(), - this->head(), - this->null_mask(), - UNKNOWN_NULL_COUNT, - this->offset(), - std::vector(child_it, child_it + children.size())); - } + operator column_view() const; linked_column_view* parent; //!< Pointer to parent of this column. Nullptr if root LinkedColVector children; @@ -70,11 +53,6 @@ struct linked_column_view : public column_view_base { * @param table table of columns to convert * @return Vector of converted linked_column_views */ -inline LinkedColVector table_to_linked_columns(table_view const& table) -{ - auto linked_it = thrust::make_transform_iterator( - table.begin(), [](auto const& c) { return std::make_shared(c); }); - return LinkedColVector(linked_it, linked_it + table.num_columns()); -} +LinkedColVector table_to_linked_columns(table_view const& table); } // namespace cudf::detail diff --git a/cpp/src/utilities/linked_column.cpp b/cpp/src/utilities/linked_column.cpp new file mode 100644 index 00000000000..fa29ee7592e --- /dev/null +++ b/cpp/src/utilities/linked_column.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2022-2023, NVIDIA CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include + +namespace cudf::detail { + +linked_column_view::linked_column_view(column_view const& col) : linked_column_view(nullptr, col) {} + +linked_column_view::linked_column_view(linked_column_view* parent, column_view const& col) + : column_view_base(col), parent(parent) +{ + children.reserve(col.num_children()); + std::transform( + col.child_begin(), col.child_end(), std::back_inserter(children), [&](column_view const& c) { + return std::make_shared(this, c); + }); +} + +linked_column_view::operator column_view() const +{ + auto child_it = thrust::make_transform_iterator( + children.begin(), [](auto const& c) { return static_cast(*c); }); + return column_view(this->type(), + this->size(), + this->head(), + this->null_mask(), + this->null_count(), + this->offset(), + std::vector(child_it, child_it + children.size())); +} + +/** + * @brief Converts all column_views of a table into linked_column_views + * + * @param table table of columns to convert + * @return Vector of converted linked_column_views + */ +LinkedColVector table_to_linked_columns(table_view const& table) +{ + auto linked_it = thrust::make_transform_iterator( + table.begin(), [](auto const& c) { return std::make_shared(c); }); + return LinkedColVector(linked_it, linked_it + table.num_columns()); +} + +} // namespace cudf::detail From c08ca197b5e8e235ce21bfe1cc4780c43afac288 Mon Sep 17 00:00:00 2001 From: David Wendt Date: Thu, 13 Apr 2023 08:47:02 -0400 Subject: [PATCH 2/2] update doxygen --- .../cudf/detail/utilities/linked_column.hpp | 21 +++++++++++++++---- cpp/src/utilities/linked_column.cpp | 6 ------ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/cpp/include/cudf/detail/utilities/linked_column.hpp b/cpp/include/cudf/detail/utilities/linked_column.hpp index e03fb9a99ff..682577a6d2a 100644 --- a/cpp/include/cudf/detail/utilities/linked_column.hpp +++ b/cpp/include/cudf/detail/utilities/linked_column.hpp @@ -30,21 +30,34 @@ using LinkedColPtr = std::shared_ptr; using LinkedColVector = std::vector; /** - * @brief column_view with the added member pointer to the parent of this column. - * + * @brief A column_view class with pointer to parent's column_view */ struct linked_column_view : public column_view_base { linked_column_view(linked_column_view const&) = delete; linked_column_view& operator=(linked_column_view const&) = delete; + /** + * @brief Construct from column_view + * + * @param col column_view to wrap + */ linked_column_view(column_view const& col); + /** + * @brief Construct from column_view with it's parent + * + * @param parent Pointer to the column_view's parent column_view + * @param col column_view to wrap + */ linked_column_view(linked_column_view* parent, column_view const& col); + /** + * @brief Conversion operator to cast this instance to it's column_view + */ operator column_view() const; - linked_column_view* parent; //!< Pointer to parent of this column. Nullptr if root - LinkedColVector children; + linked_column_view* parent; ///< Pointer to parent of this column; nullptr if root + LinkedColVector children; ///< Vector of children of this instance }; /** diff --git a/cpp/src/utilities/linked_column.cpp b/cpp/src/utilities/linked_column.cpp index fa29ee7592e..805cc1d167a 100644 --- a/cpp/src/utilities/linked_column.cpp +++ b/cpp/src/utilities/linked_column.cpp @@ -45,12 +45,6 @@ linked_column_view::operator column_view() const std::vector(child_it, child_it + children.size())); } -/** - * @brief Converts all column_views of a table into linked_column_views - * - * @param table table of columns to convert - * @return Vector of converted linked_column_views - */ LinkedColVector table_to_linked_columns(table_view const& table) { auto linked_it = thrust::make_transform_iterator(