libcudf  24.04.00
iterator_utilities.hpp
1 /*
2  * Copyright (c) 2021-2023, 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 
22 #include <thrust/iterator/constant_iterator.h>
23 #include <thrust/iterator/transform_iterator.h>
24 
25 #include <iterator>
26 
27 namespace cudf {
28 namespace test {
29 namespace iterators {
51 template <typename Iter>
52 [[maybe_unused]] static auto nulls_at(Iter index_start, Iter index_end)
53 {
54  using index_type = typename std::iterator_traits<Iter>::value_type;
55 
56  return cudf::detail::make_counting_transform_iterator(
57  0, [indices = std::vector<index_type>{index_start, index_end}](auto i) {
58  return std::find(indices.cbegin(), indices.cend(), i) == indices.cend();
59  });
60 }
61 
79 [[maybe_unused]] static auto nulls_at(std::vector<cudf::size_type> const& indices)
80 {
81  return nulls_at(indices.cbegin(), indices.cend());
82 }
83 
99 [[maybe_unused]] static auto null_at(cudf::size_type index)
100 {
101  return nulls_at(std::vector<cudf::size_type>{index});
102 }
103 
109 [[maybe_unused]] static auto all_nulls() { return thrust::make_constant_iterator(false); }
110 
116 [[maybe_unused]] static auto no_nulls() { return thrust::make_constant_iterator(true); }
117 
131 template <class T>
132 [[maybe_unused]] static auto nulls_from_nullptrs(std::vector<T const*> const& ptrs)
133 {
134  return thrust::make_transform_iterator(ptrs.begin(), [](auto ptr) { return ptr != nullptr; });
135 }
136 
137 } // namespace iterators
138 } // namespace test
139 } // namespace 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::mr::device_memory_resource *mr=rmm::mr::get_current_device_resource())
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:93
cuDF interfaces
Definition: aggregation.hpp:34
Type declarations for libcudf.