thrust::square#
-
template<typename T = void>
struct square# squareis a function object. Specifically, it is an Adaptable Unary Function. Iffis an object of classsquare<T>, andxis an object of classT, thenf(x)returnsx*x.The following code snippet demonstrates how to use
squareto square the elements of a device_vector offloats.#include <thrust/device_vector.h> #include <thrust/functional.h> #include <thrust/sequence.h> #include <thrust/transform.h> ... const int N = 1000; thrust::device_vector<float> V1(N); thrust::device_vector<float> V2(N); thrust::sequence(V1.begin(), V1.end(), 1); thrust::transform(V1.begin(), V1.end(), V2.begin(), thrust::square<float>()); // V2 is now {1, 4, 9, ..., 1000000}
- Template Parameters:
T – is a model of Assignable, and if
xis an object of typeT, thenx*xmust be defined and must have a return type that is convertible toT.