Skip to content

Commit

Permalink
Replace typedef by alias declarations in Thrust (#1915)
Browse files Browse the repository at this point in the history
Using:
* clang-tidy modernize-use-using
* regex replace: "typedef ([\w<>,:\s*&+:\[\]\.]+)\s+([\w_]+);" by "using $2 = $1;"
* manual search and edits

Fixes a part of: #1747
  • Loading branch information
bernhardmgruber committed Jul 1, 2024
1 parent 14ee5c9 commit 91b78d8
Show file tree
Hide file tree
Showing 438 changed files with 2,885 additions and 2,918 deletions.
2 changes: 1 addition & 1 deletion thrust/examples/bucket_sort2d.cu
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "include/host_device.h"

// define a 2d float vector
typedef thrust::tuple<float, float> vec2;
using vec2 = thrust::tuple<float, float>;

// return a random vec2 in [0,1)^2
vec2 make_random_vec2()
Expand Down
2 changes: 1 addition & 1 deletion thrust/examples/counting_iterator.cu
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ int main()
thrust::counting_iterator<int> last = first + 8;

// compute indices of nonzero elements
typedef thrust::device_vector<int>::iterator IndexIterator;
using IndexIterator = thrust::device_vector<int>::iterator;

IndexIterator indices_end = thrust::copy_if(first, last, stencil.begin(), indices.begin(), thrust::identity<int>());
// indices now contains [1,2,5,7]
Expand Down
6 changes: 3 additions & 3 deletions thrust/examples/cuda/custom_temporary_allocation.cu
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private:
// A simple allocator for caching cudaMalloc allocations.
struct cached_allocator
{
typedef char value_type;
using value_type = char;

cached_allocator() {}

Expand Down Expand Up @@ -120,8 +120,8 @@ struct cached_allocator
}

private:
typedef std::multimap<std::ptrdiff_t, char*> free_blocks_type;
typedef std::map<char*, std::ptrdiff_t> allocated_blocks_type;
using free_blocks_type = std::multimap<std::ptrdiff_t, char*>;
using allocated_blocks_type = std::map<char*, std::ptrdiff_t>;

free_blocks_type free_blocks;
allocated_blocks_type allocated_blocks;
Expand Down
5 changes: 2 additions & 3 deletions thrust/examples/cuda/global_device_vector.cu
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ extern "C" cudaError_t cudaFreeIgnoreShutdown(void* ptr)
return err;
}

typedef thrust::system::cuda::detail::
cuda_memory_resource<cudaMalloc, cudaFreeIgnoreShutdown, thrust::cuda::pointer<void>>
device_ignore_shutdown_memory_resource;
using device_ignore_shutdown_memory_resource =
thrust::system::cuda::detail::cuda_memory_resource<cudaMalloc, cudaFreeIgnoreShutdown, thrust::cuda::pointer<void>>;

template <typename T>
using device_ignore_shutdown_allocator =
Expand Down
10 changes: 5 additions & 5 deletions thrust/examples/cuda/range_view.cu
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ template <class Iterator>
class range_view
{
public:
typedef Iterator iterator;
typedef typename thrust::iterator_traits<iterator>::value_type value_type;
typedef typename thrust::iterator_traits<iterator>::pointer pointer;
typedef typename thrust::iterator_traits<iterator>::difference_type difference_type;
typedef typename thrust::iterator_traits<iterator>::reference reference;
using iterator = Iterator;
using value_type = typename thrust::iterator_traits<iterator>::value_type;
using pointer = typename thrust::iterator_traits<iterator>::pointer;
using difference_type = typename thrust::iterator_traits<iterator>::difference_type;
using reference = typename thrust::iterator_traits<iterator>::reference;

private:
const iterator first;
Expand Down
8 changes: 4 additions & 4 deletions thrust/examples/dot_products_with_zip.cu
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// into a single virtual Float3 array.

// We'll use a 3-tuple to store our 3d vector type
typedef thrust::tuple<float, float, float> Float3;
using Float3 = thrust::tuple<float, float, float>;

// This functor implements the dot product between 3d vectors
struct DotProduct : public thrust::binary_function<Float3, Float3, float>
Expand Down Expand Up @@ -74,9 +74,9 @@ int main()

// METHOD #1
// Defining a zip_iterator type can be a little cumbersome ...
typedef thrust::device_vector<float>::iterator FloatIterator;
typedef thrust::tuple<FloatIterator, FloatIterator, FloatIterator> FloatIteratorTuple;
typedef thrust::zip_iterator<FloatIteratorTuple> Float3Iterator;
using FloatIterator = thrust::device_vector<float>::iterator;
using FloatIteratorTuple = thrust::tuple<FloatIterator, FloatIterator, FloatIterator>;
using Float3Iterator = thrust::zip_iterator<FloatIteratorTuple>;

// Now we'll create some zip_iterators for A and B
Float3Iterator A_first = thrust::make_zip_iterator(thrust::make_tuple(A0.begin(), A1.begin(), A2.begin()));
Expand Down
4 changes: 2 additions & 2 deletions thrust/examples/expand.cu
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
template <typename InputIterator1, typename InputIterator2, typename OutputIterator>
OutputIterator expand(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, OutputIterator output)
{
typedef typename thrust::iterator_difference<InputIterator1>::type difference_type;
using difference_type = typename thrust::iterator_difference<InputIterator1>::type;

difference_type input_size = thrust::distance(first1, last1);
difference_type output_size = thrust::reduce(first1, last1);
Expand Down Expand Up @@ -53,7 +53,7 @@ OutputIterator expand(InputIterator1 first1, InputIterator1 last1, InputIterator
template <typename Vector>
void print(const std::string& s, const Vector& v)
{
typedef typename Vector::value_type T;
using T = typename Vector::value_type;

std::cout << s;
thrust::copy(v.begin(), v.end(), std::ostream_iterator<T>(std::cout, " "));
Expand Down
10 changes: 5 additions & 5 deletions thrust/examples/histogram.cu
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
template <typename Vector>
void print_vector(const std::string& name, const Vector& v)
{
typedef typename Vector::value_type T;
using T = typename Vector::value_type;
std::cout << " " << std::setw(20) << name << " ";
thrust::copy(v.begin(), v.end(), std::ostream_iterator<T>(std::cout, " "));
std::cout << std::endl;
Expand All @@ -59,8 +59,8 @@ void print_vector(const std::string& name, const Vector& v)
template <typename Vector1, typename Vector2>
void dense_histogram(const Vector1& input, Vector2& histogram)
{
typedef typename Vector1::value_type ValueType; // input value type
typedef typename Vector2::value_type IndexType; // histogram index type
using ValueType = typename Vector1::value_type; // input value type
using IndexType = typename Vector2::value_type; // histogram index type

// copy input data (could be skipped if input is allowed to be modified)
thrust::device_vector<ValueType> data(input);
Expand Down Expand Up @@ -98,8 +98,8 @@ void dense_histogram(const Vector1& input, Vector2& histogram)
template <typename Vector1, typename Vector2, typename Vector3>
void sparse_histogram(const Vector1& input, Vector2& histogram_values, Vector3& histogram_counts)
{
typedef typename Vector1::value_type ValueType; // input value type
typedef typename Vector3::value_type IndexType; // histogram index type
using ValueType = typename Vector1::value_type; // input value type
using IndexType = typename Vector3::value_type; // histogram index type

// copy input data (could be skipped if input is allowed to be modified)
thrust::device_vector<ValueType> data(input);
Expand Down
19 changes: 9 additions & 10 deletions thrust/examples/mr_basic.cu
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ int main()

{
// no virtual calls will be issued
typedef thrust::mr::allocator<int, thrust::mr::new_delete_resource> Alloc;
using Alloc = thrust::mr::allocator<int, thrust::mr::new_delete_resource>;
Alloc alloc(&memres);

do_stuff_with_vector<thrust::host_vector<int, Alloc>>(alloc);
Expand All @@ -39,38 +39,37 @@ int main()
{
// virtual calls will be issued - wrapping in a polymorphic wrapper
thrust::mr::polymorphic_adaptor_resource<void*> adaptor(&memres);
typedef thrust::mr::polymorphic_allocator<int, void*> Alloc;
using Alloc = thrust::mr::polymorphic_allocator<int, void*>;
Alloc alloc(&adaptor);

do_stuff_with_vector<thrust::host_vector<int, Alloc>>(alloc);
}

{
// use the global device_ptr-flavored device memory resource
typedef thrust::device_ptr_memory_resource<thrust::device_memory_resource> Resource;
using Resource = thrust::device_ptr_memory_resource<thrust::device_memory_resource>;
thrust::mr::polymorphic_adaptor_resource<thrust::device_ptr<void>> adaptor(
thrust::mr::get_global_resource<Resource>());
typedef thrust::mr::polymorphic_allocator<int, thrust::device_ptr<void>> Alloc;
using Alloc = thrust::mr::polymorphic_allocator<int, thrust::device_ptr<void>>;
Alloc alloc(&adaptor);

do_stuff_with_vector<thrust::device_vector<int, Alloc>>(alloc);
}

typedef thrust::mr::unsynchronized_pool_resource<thrust::mr::new_delete_resource> Pool;
using Pool = thrust::mr::unsynchronized_pool_resource<thrust::mr::new_delete_resource>;
Pool pool(&memres);
{
typedef thrust::mr::allocator<int, Pool> Alloc;
using Alloc = thrust::mr::allocator<int, Pool>;
Alloc alloc(&pool);

do_stuff_with_vector<thrust::host_vector<int, Alloc>>(alloc);
}

typedef thrust::mr::disjoint_unsynchronized_pool_resource<thrust::mr::new_delete_resource,
thrust::mr::new_delete_resource>
DisjointPool;
using DisjointPool =
thrust::mr::disjoint_unsynchronized_pool_resource<thrust::mr::new_delete_resource, thrust::mr::new_delete_resource>;
DisjointPool disjoint_pool(&memres, &memres);
{
typedef thrust::mr::allocator<int, DisjointPool> Alloc;
using Alloc = thrust::mr::allocator<int, DisjointPool>;
Alloc alloc(&disjoint_pool);

do_stuff_with_vector<thrust::host_vector<int, Alloc>>(alloc);
Expand Down
8 changes: 4 additions & 4 deletions thrust/examples/padded_grid_reduction.cu
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ template <typename IndexType, typename ValueType>
struct transform_tuple
: public thrust::unary_function<thrust::tuple<IndexType, ValueType>, thrust::tuple<bool, ValueType, ValueType>>
{
typedef typename thrust::tuple<IndexType, ValueType> InputTuple;
typedef typename thrust::tuple<bool, ValueType, ValueType> OutputTuple;
using InputTuple = typename thrust::tuple<IndexType, ValueType>;
using OutputTuple = typename thrust::tuple<bool, ValueType, ValueType>;

IndexType n, N;

Expand All @@ -49,7 +49,7 @@ struct reduce_tuple
thrust::tuple<bool, ValueType, ValueType>,
thrust::tuple<bool, ValueType, ValueType>>
{
typedef typename thrust::tuple<bool, ValueType, ValueType> Tuple;
using Tuple = typename thrust::tuple<bool, ValueType, ValueType>;

__host__ __device__ Tuple operator()(const Tuple& t0, const Tuple& t1) const
{
Expand Down Expand Up @@ -108,7 +108,7 @@ int main()
std::cout << "\n";

// compute min & max over valid region of the 2d grid
typedef thrust::tuple<bool, float, float> result_type;
using result_type = thrust::tuple<bool, float, float>;

result_type init(true, FLT_MAX, -FLT_MAX); // initial value
transform_tuple<int, float> unary_op(n, N); // transformation operator
Expand Down
8 changes: 4 additions & 4 deletions thrust/examples/raw_reference_cast.cu
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct copy_iterators
template <typename Vector>
void print(const std::string& name, const Vector& v)
{
typedef typename Vector::value_type T;
using T = typename Vector::value_type;

std::cout << name << ": ";
thrust::copy(v.begin(), v.end(), std::ostream_iterator<T>(std::cout, " "));
Expand All @@ -79,9 +79,9 @@ void print(const std::string& name, const Vector& v)

int main()
{
typedef thrust::device_vector<int> Vector;
typedef Vector::iterator Iterator;
typedef thrust::device_system_tag System;
using Vector = thrust::device_vector<int>;
using Iterator = Vector::iterator;
using System = thrust::device_system_tag;

// allocate device memory
Vector A(5);
Expand Down
12 changes: 6 additions & 6 deletions thrust/examples/repeated_range.cu
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ template <typename Iterator>
class repeated_range
{
public:
typedef typename thrust::iterator_difference<Iterator>::type difference_type;
using difference_type = typename thrust::iterator_difference<Iterator>::type;

struct repeat_functor : public thrust::unary_function<difference_type, difference_type>
{
Expand All @@ -37,12 +37,12 @@ public:
}
};

typedef typename thrust::counting_iterator<difference_type> CountingIterator;
typedef typename thrust::transform_iterator<repeat_functor, CountingIterator> TransformIterator;
typedef typename thrust::permutation_iterator<Iterator, TransformIterator> PermutationIterator;
using CountingIterator = typename thrust::counting_iterator<difference_type>;
using TransformIterator = typename thrust::transform_iterator<repeat_functor, CountingIterator>;
using PermutationIterator = typename thrust::permutation_iterator<Iterator, TransformIterator>;

// type of the repeated_range iterator
typedef PermutationIterator iterator;
using iterator = PermutationIterator;

// construct repeated_range for the range [first,last)
repeated_range(Iterator first, Iterator last, difference_type repeats)
Expand Down Expand Up @@ -80,7 +80,7 @@ int main()
thrust::copy(data.begin(), data.end(), std::ostream_iterator<int>(std::cout, " "));
std::cout << std::endl;

typedef thrust::device_vector<int>::iterator Iterator;
using Iterator = thrust::device_vector<int>::iterator;

// create repeated_range with elements repeated twice
repeated_range<Iterator> twice(data.begin(), data.end(), 2);
Expand Down
2 changes: 1 addition & 1 deletion thrust/examples/simple_moving_average.cu
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct minus_and_divide : public thrust::binary_function<T, T, T>
template <typename InputVector, typename OutputVector>
void simple_moving_average(const InputVector& data, size_t w, OutputVector& output)
{
typedef typename InputVector::value_type T;
using T = typename InputVector::value_type;

if (data.size() < w)
{
Expand Down
4 changes: 2 additions & 2 deletions thrust/examples/sparse_vector.cu
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ void sum_sparse_vectors(
IndexVector3& C_index,
ValueVector3& C_value)
{
typedef typename IndexVector3::value_type IndexType;
typedef typename ValueVector3::value_type ValueType;
using IndexType = typename IndexVector3::value_type;
using ValueType = typename ValueVector3::value_type;

assert(A_index.size() == A_value.size());
assert(B_index.size() == B_value.size());
Expand Down
6 changes: 3 additions & 3 deletions thrust/examples/stream_compaction.cu
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct is_odd : public thrust::unary_function<T, bool>
template <typename Iterator>
void print_range(const std::string& name, Iterator first, Iterator last)
{
typedef typename std::iterator_traits<Iterator>::value_type T;
using T = typename std::iterator_traits<Iterator>::value_type;

std::cout << name << ": ";
thrust::copy(first, last, std::ostream_iterator<T>(std::cout, " "));
Expand All @@ -36,8 +36,8 @@ int main()
size_t N = 10;

// define some types
typedef thrust::device_vector<int> Vector;
typedef Vector::iterator Iterator;
using Vector = thrust::device_vector<int>;
using Iterator = Vector::iterator;

// allocate storage for array
Vector values(N);
Expand Down
12 changes: 6 additions & 6 deletions thrust/examples/strided_range.cu
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ template <typename Iterator>
class strided_range
{
public:
typedef typename thrust::iterator_difference<Iterator>::type difference_type;
using difference_type = typename thrust::iterator_difference<Iterator>::type;

struct stride_functor : public thrust::unary_function<difference_type, difference_type>
{
Expand All @@ -37,12 +37,12 @@ public:
}
};

typedef typename thrust::counting_iterator<difference_type> CountingIterator;
typedef typename thrust::transform_iterator<stride_functor, CountingIterator> TransformIterator;
typedef typename thrust::permutation_iterator<Iterator, TransformIterator> PermutationIterator;
using CountingIterator = typename thrust::counting_iterator<difference_type>;
using TransformIterator = typename thrust::transform_iterator<stride_functor, CountingIterator>;
using PermutationIterator = typename thrust::permutation_iterator<Iterator, TransformIterator>;

// type of the strided_range iterator
typedef PermutationIterator iterator;
using iterator = PermutationIterator;

// construct strided_range for the range [first,last)
strided_range(Iterator first, Iterator last, difference_type stride)
Expand Down Expand Up @@ -84,7 +84,7 @@ int main()
thrust::copy(data.begin(), data.end(), std::ostream_iterator<int>(std::cout, " "));
std::cout << std::endl;

typedef thrust::device_vector<int>::iterator Iterator;
using Iterator = thrust::device_vector<int>::iterator;

// create strided_range with indices [0,2,4,6]
strided_range<Iterator> evens(data.begin(), data.end(), 2);
Expand Down
4 changes: 2 additions & 2 deletions thrust/examples/summary_statistics.cu
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ struct summary_stats_binary_op
template <typename Iterator>
void print_range(const std::string& name, Iterator first, Iterator last)
{
typedef typename std::iterator_traits<Iterator>::value_type T;
using T = typename std::iterator_traits<Iterator>::value_type;

std::cout << name << ": ";
thrust::copy(first, last, std::ostream_iterator<T>(std::cout, " "));
Expand All @@ -133,7 +133,7 @@ void print_range(const std::string& name, Iterator first, Iterator last)

int main()
{
typedef float T;
using T = float;

// initialize host array
T h_x[] = {4, 7, 13, 16};
Expand Down
Loading

0 comments on commit 91b78d8

Please sign in to comment.