iterator_utilities.hpp
1 /*
2  * Copyright (c) 2021-2024, NVIDIA CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <cudf/detail/iterator.cuh>
20 #include <cudf/types.hpp>
21 #include <cudf/utilities/export.hpp>
22 
23 #include <thrust/iterator/constant_iterator.h>
24 #include <thrust/iterator/transform_iterator.h>
25 
26 #include <iterator>
27 
28 namespace CUDF_EXPORT cudf {
29 namespace test {
30 namespace iterators {
52 template <typename Iter>
53 [[maybe_unused]] static auto nulls_at(Iter index_start, Iter index_end)
54 {
55  using index_type = typename std::iterator_traits<Iter>::value_type;
56 
57  return cudf::detail::make_counting_transform_iterator(
58  0, [indices = std::vector<index_type>{index_start, index_end}](auto i) {
59  return std::find(indices.cbegin(), indices.cend(), i) == indices.cend();
60  });
61 }
62 
80 [[maybe_unused]] static auto nulls_at(std::vector<cudf::size_type> const& indices)
81 {
82  return nulls_at(indices.cbegin(), indices.cend());
83 }
84 
100 [[maybe_unused]] static auto null_at(cudf::size_type index)
101 {
102  return nulls_at(std::vector<cudf::size_type>{index});
103 }
104 
110 [[maybe_unused]] static auto all_nulls() { return thrust::make_constant_iterator(false); }
111 
117 [[maybe_unused]] static auto no_nulls() { return thrust::make_constant_iterator(true); }
118 
132 template <class T>
133 [[maybe_unused]] static auto nulls_from_nullptrs(std::vector<T const*> const& ptrs)
134 {
135  return thrust::make_transform_iterator(ptrs.begin(), [](auto ptr) { return ptr != nullptr; });
136 }
137 
138 } // namespace iterators
139 } // namespace test
140 } // namespace CUDF_EXPORT cudf
std::unique_ptr< column > find(strings_column_view const &input, string_scalar const &target, size_type start=0, size_type stop=-1, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Returns a column of character position values where the target string is first found in each string o...
int32_t size_type
Row index type for columns and tables.
Definition: types.hpp:95
cuDF interfaces
Definition: aggregation.hpp:35
Type declarations for libcudf.