Skip to content
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
44 changes: 3 additions & 41 deletions cpp/include/cudf/detail/unary.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2018-2024, NVIDIA CORPORATION.
* SPDX-FileCopyrightText: Copyright (c) 2018-2026, NVIDIA CORPORATION.
* SPDX-License-Identifier: Apache-2.0
*/

Expand All @@ -8,50 +8,12 @@
#include <cudf/column/column_factories.hpp>
#include <cudf/unary.hpp>
#include <cudf/utilities/default_stream.hpp>
#include <cudf/utilities/export.hpp>
#include <cudf/utilities/memory_resource.hpp>

#include <rmm/cuda_stream_view.hpp>
#include <rmm/exec_policy.hpp>

#include <thrust/transform.h>

namespace CUDF_EXPORT cudf {
namespace cudf {
namespace detail {
/**
* @brief Creates a column of `type_id::BOOL8` elements by applying a predicate to every element
* between
* [`begin, `end`) `true` indicates the value is satisfies the predicate and `false` indicates it
* doesn't.
*
* @tparam InputIterator Iterator type for `begin` and `end`
* @tparam Predicate A predicator type which will be evaluated
* @param begin Beginning of the sequence of elements
* @param end End of the sequence of elements
* @param p Predicate to be applied to each element in `[begin,end)`
* @param stream CUDA stream used for device memory operations and kernel launches.
* @param mr Device memory resource used to allocate the returned column's device memory
*
* @returns A column of type `type_id::BOOL8,` with `true` representing predicate is satisfied.
*/

template <typename InputIterator, typename Predicate>
std::unique_ptr<column> true_if(InputIterator begin,
InputIterator end,
size_type size,
Predicate p,
rmm::cuda_stream_view stream,
rmm::device_async_resource_ref mr)
{
auto output =
make_numeric_column(data_type(type_id::BOOL8), size, mask_state::UNALLOCATED, stream, mr);
auto output_mutable_view = output->mutable_view();
auto output_data = output_mutable_view.data<bool>();

thrust::transform(rmm::exec_policy_nosync(stream), begin, end, output_data, p);

return output;
}

/**
* @copydoc cudf::unary_operation
Expand Down Expand Up @@ -91,4 +53,4 @@ std::unique_ptr<column> is_not_nan(cudf::column_view const& input,
rmm::device_async_resource_ref mr);

} // namespace detail
} // namespace CUDF_EXPORT cudf
} // namespace cudf
1 change: 1 addition & 0 deletions cpp/src/unary/math_ops.cu
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <cudf/utilities/type_dispatcher.hpp>

#include <rmm/cuda_stream_view.hpp>
#include <rmm/exec_policy.hpp>

#include <cuda/std/bit>
#include <cuda/std/cmath>
Expand Down
4 changes: 3 additions & 1 deletion cpp/src/unary/nan_ops.cu
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2020-2025, NVIDIA CORPORATION.
* SPDX-FileCopyrightText: Copyright (c) 2020-2026, NVIDIA CORPORATION.
* SPDX-License-Identifier: Apache-2.0
*/

#include "true_if.cuh"

#include <cudf/column/column_device_view.cuh>
#include <cudf/column/column_factories.hpp>
#include <cudf/detail/iterator.cuh>
Expand Down
4 changes: 3 additions & 1 deletion cpp/src/unary/null_ops.cu
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2019-2024, NVIDIA CORPORATION.
* SPDX-FileCopyrightText: Copyright (c) 2019-2026, NVIDIA CORPORATION.
* SPDX-License-Identifier: Apache-2.0
*/

#include "true_if.cuh"

#include <cudf/column/column_device_view.cuh>
#include <cudf/detail/nvtx/ranges.hpp>
#include <cudf/detail/unary.hpp>
Expand Down
55 changes: 55 additions & 0 deletions cpp/src/unary/true_if.cuh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION.
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include <cudf/column/column_factories.hpp>
#include <cudf/utilities/memory_resource.hpp>

#include <rmm/cuda_stream_view.hpp>
#include <rmm/exec_policy.hpp>

#include <thrust/transform.h>

namespace cudf {
namespace detail {
/**
* @brief Creates a column of `type_id::BOOL8` elements by applying a predicate to every element
* between
* [`begin, `end`) `true` indicates the value is satisfies the predicate and `false` indicates it
* doesn't.
*
* @tparam InputIterator Iterator type for `begin` and `end`
* @tparam Predicate A predicator type which will be evaluated
* @param begin Beginning of the sequence of elements
* @param end End of the sequence of elements
* @param size Size of the output column
* @param p Predicate to be applied to each element in `[begin,end)`
Comment thread
davidwendt marked this conversation as resolved.
* @param stream CUDA stream used for device memory operations and kernel launches.
* @param mr Device memory resource used to allocate the returned column's device memory
*
* @returns A column of type `type_id::BOOL8,` with `true` representing predicate is satisfied.
*/

template <typename InputIterator, typename Predicate>
std::unique_ptr<column> true_if(InputIterator begin,
InputIterator end,
size_type size,
Predicate p,
rmm::cuda_stream_view stream,
rmm::device_async_resource_ref mr)
{
auto output =
make_numeric_column(data_type(type_id::BOOL8), size, mask_state::UNALLOCATED, stream, mr);
auto output_mutable_view = output->mutable_view();
auto output_data = output_mutable_view.data<bool>();

thrust::transform(rmm::exec_policy_nosync(stream), begin, end, output_data, p);

return output;
}

} // namespace detail
} // namespace cudf