Skip to content

Commit

Permalink
Fix return type of prefix increment overloads (rapidsai#14544)
Browse files Browse the repository at this point in the history
Prefix increment operators should return a reference to the object. Some of our iterators don't return anything.
This PR fixes those iterators to be in line with what C++ expects.

Authors:
  - Vukasin Milovanovic (https://github.com/vuule)

Approvers:
  - Bradley Dice (https://github.com/bdice)
  - Nghia Truong (https://github.com/ttnghia)

URL: rapidsai#14544
  • Loading branch information
vuule authored and karthikeyann committed Dec 12, 2023
1 parent 302861d commit dec8fb0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
15 changes: 10 additions & 5 deletions cpp/src/copying/contiguous_split.cu
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,11 @@ struct dst_offset_output_iterator {

dst_offset_output_iterator operator+ __host__ __device__(int i) { return {c + i}; }

void operator++ __host__ __device__() { c++; }
dst_offset_output_iterator& operator++ __host__ __device__()
{
c++;
return *this;
}

reference operator[] __device__(int i) { return dereference(c + i); }
reference operator* __device__() { return dereference(c); }
Expand All @@ -873,13 +877,14 @@ struct dst_valid_count_output_iterator {
using reference = size_type&;
using iterator_category = thrust::output_device_iterator_tag;

dst_valid_count_output_iterator operator+ __host__ __device__(int i)
dst_valid_count_output_iterator operator+ __host__ __device__(int i) { return {c + i}; }

dst_valid_count_output_iterator& operator++ __host__ __device__()
{
return dst_valid_count_output_iterator{c + i};
c++;
return *this;
}

void operator++ __host__ __device__() { c++; }

reference operator[] __device__(int i) { return dereference(c + i); }
reference operator* __device__() { return dereference(c); }

Expand Down
27 changes: 16 additions & 11 deletions cpp/src/io/parquet/reader_impl_preprocess.cu
Original file line number Diff line number Diff line change
Expand Up @@ -908,13 +908,14 @@ struct chunk_row_output_iter {
using reference = size_type&;
using iterator_category = thrust::output_device_iterator_tag;

__host__ __device__ chunk_row_output_iter operator+(int i)
__host__ __device__ chunk_row_output_iter operator+(int i) { return {p + i}; }

__host__ __device__ chunk_row_output_iter& operator++()
{
return chunk_row_output_iter{p + i};
p++;
return *this;
}

__host__ __device__ void operator++() { p++; }

__device__ reference operator[](int i) { return p[i].chunk_row; }
__device__ reference operator*() { return p->chunk_row; }
};
Expand Down Expand Up @@ -948,11 +949,14 @@ struct start_offset_output_iterator {

constexpr start_offset_output_iterator operator+(size_t i)
{
return start_offset_output_iterator{
pages, page_indices, cur_index + i, input_cols, max_depth, num_pages};
return {pages, page_indices, cur_index + i, input_cols, max_depth, num_pages};
}

constexpr void operator++() { cur_index++; }
constexpr start_offset_output_iterator& operator++()
{
cur_index++;
return *this;
}

__device__ reference operator[](size_t i) { return dereference(cur_index + i); }
__device__ reference operator*() { return dereference(cur_index); }
Expand Down Expand Up @@ -1087,13 +1091,14 @@ struct page_offset_output_iter {
using reference = size_type&;
using iterator_category = thrust::output_device_iterator_tag;

__host__ __device__ page_offset_output_iter operator+(int i)
__host__ __device__ page_offset_output_iter operator+(int i) { return {p, index + i}; }

__host__ __device__ page_offset_output_iter& operator++()
{
return page_offset_output_iter{p, index + i};
index++;
return *this;
}

__host__ __device__ void operator++() { index++; }

__device__ reference operator[](int i) { return p[index[i]].str_offset; }
__device__ reference operator*() { return p[*index].str_offset; }
};
Expand Down

0 comments on commit dec8fb0

Please sign in to comment.