Skip to content

Commit 1b13308

Browse files
Use list init for test data in iterator docs (NVIDIA#4738)
1 parent 240ecdf commit 1b13308

File tree

6 files changed

+12
-77
lines changed

6 files changed

+12
-77
lines changed

thrust/thrust/iterator/constant_iterator.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,7 @@ struct make_constant_iterator_base
9595
//!
9696
//! int main()
9797
//! {
98-
//! thrust::device_vector<int> data(4);
99-
//! data[0] = 3;
100-
//! data[1] = 7;
101-
//! data[2] = 2;
102-
//! data[3] = 5;
98+
//! thrust::device_vector<int> data{3, 7, 2, 5};
10399
//!
104100
//! // add 10 to all values in data
105101
//! thrust::transform(data.begin(), data.end(),

thrust/thrust/iterator/counting_iterator.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,7 @@ struct make_counting_iterator_base
134134
//! // this example computes indices for all the nonzero values in a sequence
135135
//!
136136
//! // sequence of zero and nonzero values
137-
//! thrust::device_vector<int> stencil(8);
138-
//! stencil[0] = 0;
139-
//! stencil[1] = 1;
140-
//! stencil[2] = 1;
141-
//! stencil[3] = 0;
142-
//! stencil[4] = 0;
143-
//! stencil[5] = 1;
144-
//! stencil[6] = 0;
145-
//! stencil[7] = 1;
137+
//! thrust::device_vector<int> stencil{0, 1, 1, 0, 0, 1, 0, 1};
146138
//!
147139
//! // storage for the nonzero indices
148140
//! thrust::device_vector<int> indices(8);

thrust/thrust/iterator/discard_iterator.h

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -88,23 +88,8 @@ _CCCL_DIAG_SUPPRESS_MSVC(4244 4267) // possible loss of data
8888
//!
8989
//! int main()
9090
//! {
91-
//! thrust::device_vector<int> keys(7), values(7);
92-
//!
93-
//! keys[0] = 1;
94-
//! keys[1] = 3;
95-
//! keys[2] = 3;
96-
//! keys[3] = 3;
97-
//! keys[4] = 2;
98-
//! keys[5] = 2;
99-
//! keys[6] = 1;
100-
//!
101-
//! values[0] = 9;
102-
//! values[1] = 8;
103-
//! values[2] = 7;
104-
//! values[3] = 6;
105-
//! values[4] = 5;
106-
//! values[5] = 4;
107-
//! values[6] = 3;
91+
//! thrust::device_vector<int> keys{1, 3, 3, 3, 2, 2, 1};
92+
//! thrust::device_vector<int> values{9, 8, 7, 6, 5, 4, 3};
10893
//!
10994
//! thrust::device_vector<int> result(4);
11095
//!

thrust/thrust/iterator/permutation_iterator.h

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -98,21 +98,8 @@ struct make_permutation_iterator_base
9898
//! #include <thrust/iterator/permutation_iterator.h>
9999
//! #include <thrust/device_vector.h>
100100
//! ...
101-
//! thrust::device_vector<float> values(8);
102-
//! values[0] = 10.0f;
103-
//! values[1] = 20.0f;
104-
//! values[2] = 30.0f;
105-
//! values[3] = 40.0f;
106-
//! values[4] = 50.0f;
107-
//! values[5] = 60.0f;
108-
//! values[6] = 70.0f;
109-
//! values[7] = 80.0f;
110-
//!
111-
//! thrust::device_vector<int> indices(4);
112-
//! indices[0] = 2;
113-
//! indices[1] = 6;
114-
//! indices[2] = 1;
115-
//! indices[3] = 3;
101+
//! thrust::device_vector<float> values{10.0f, 20.0f, 30.0f, 40.0f, 50.0f, 60.0f, 70.0f, 80.0f};
102+
//! thrust::device_vector<int> indices{2, 6, 1, 3};
116103
//!
117104
//! using ElementIterator = thrust::device_vector<float>::iterator;
118105
//! using IndexIterator = thrust::device_vector<int>::iterator ;

thrust/thrust/iterator/reverse_iterator.h

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,7 @@ struct make_reverse_iterator_base
8080
//! #include <thrust/iterator/reverse_iterator.h>
8181
//! #include <thrust/device_vector.h>
8282
//! ...
83-
//! thrust::device_vector<float> v(4);
84-
//! v[0] = 0.0f;
85-
//! v[1] = 1.0f;
86-
//! v[2] = 2.0f;
87-
//! v[3] = 3.0f;
83+
//! thrust::device_vector<float> v{0.0f, 1.0f, 2.0f, 3.0f};
8884
//!
8985
//! using Iterator = thrust::device_vector<float>::iterator;
9086
//!
@@ -106,11 +102,7 @@ struct make_reverse_iterator_base
106102
//! \code
107103
//! #include <thrust/device_vector.h>
108104
//! ...
109-
//! thrust::device_vector<float> v(4);
110-
//! v[0] = 0.0f;
111-
//! v[1] = 1.0f;
112-
//! v[2] = 2.0f;
113-
//! v[3] = 3.0f;
105+
//! thrust::device_vector<float> v{0.0f, 1.0f, 2.0f, 3.0f};
114106
//!
115107
//! // we use the nested type reverse_iterator to refer to a reversed view of a device_vector and the method rbegin() to
116108
//! // create a reverse_iterator pointing to the beginning of the reversed device_vector
@@ -135,12 +127,7 @@ struct make_reverse_iterator_base
135127
//! #include <thrust/device_vector.h>
136128
//! #include <thrust/scan.h>
137129
//! ...
138-
//! thrust::device_vector<int> v(5);
139-
//! v[0] = 0;
140-
//! v[1] = 1;
141-
//! v[2] = 2;
142-
//! v[3] = 3;
143-
//! v[4] = 4;
130+
//! thrust::device_vector<int> v{0, 1, 2, 3, 4};
144131
//!
145132
//! thrust::device_vector<int> result(5);
146133
//!

thrust/thrust/iterator/transform_iterator.h

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,7 @@ struct make_transform_iterator_base
131131
//!
132132
//! int main()
133133
//! {
134-
//! thrust::device_vector<float> v(4);
135-
//! v[0] = 1.0f;
136-
//! v[1] = 4.0f;
137-
//! v[2] = 9.0f;
138-
//! v[3] = 16.0f;
134+
//! thrust::device_vector<float> v{1.0f, 4.0f, 9.0f, 16.0f};
139135
//!
140136
//! using FloatIterator = thrust::device_vector<float>::iterator;
141137
//!
@@ -173,11 +169,7 @@ struct make_transform_iterator_base
173169
//! int main()
174170
//! {
175171
//! // initialize a device array
176-
//! thrust::device_vector<float> v(4);
177-
//! v[0] = 1.0f;
178-
//! v[1] = 2.0f;
179-
//! v[2] = 3.0f;
180-
//! v[3] = 4.0f;
172+
//! thrust::device_vector<float> v{1.0f, 2.0f, 3.0f, 4.0f};
181173
//!
182174
//! float sum_of_squares =
183175
//! thrust::reduce(thrust::make_transform_iterator(v.begin(), square()),
@@ -206,11 +198,7 @@ struct make_transform_iterator_base
206198
//!
207199
//! int main()
208200
//! {
209-
//! thrust::device_vector<float> v(4);
210-
//! v[0] = 1.0f;
211-
//! v[1] = 4.0f;
212-
//! v[2] = 9.0f;
213-
//! v[3] = 16.0f;
201+
//! thrust::device_vector<float> v{1.0f, 4.0f, 9.0f, 16.0f};
214202
//!
215203
//! using FloatIterator = thrust::device_vector<float>::iterator;
216204
//!

0 commit comments

Comments
 (0)