Skip to content
This repository was archived by the owner on Mar 21, 2024. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions examples/bounding_box.cu
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ struct bbox
};

// reduce a pair of bounding boxes (a,b) to a bounding box containing a and b
struct bbox_reduction : public thrust::binary_function<bbox,bbox,bbox>
struct bbox_union : public thrust::binary_function<bbox,bbox,bbox>
{
__host__ __device__
bbox operator()(bbox a, bbox b)
Expand All @@ -75,21 +75,17 @@ int main(void)
thrust::device_vector<point2d> points(N);

// generate some random points in the unit square
for(size_t i = 0; i < N; i++)
{
float x = u01(rng);
float y = u01(rng);
points[i] = point2d(x,y);
}
std::generate(points.begin(), points.end(), [&] {
auto x = u01(rng);
auto y = u01(rng);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's avoid auto here, we're not requiring C++11 yet.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're not requiring C++11, we can't use this lambda either, can we?

return point2d(x, y);
});

// initial bounding box contains first point
bbox init = bbox(points[0], points[0]);

// binary reduction operation
bbox_reduction binary_op;
bbox first_point = bbox(points[0], points[0]);

// compute the bounding box for the point set
bbox result = thrust::reduce(points.begin(), points.end(), init, binary_op);
bbox result = thrust::reduce(points.begin(), points.end(), first_point, bbox_union());

// print output
std::cout << "bounding box " << std::fixed;
Expand Down