Template Struct multiplies

Struct Documentation

template<typename T>
struct multiplies

multiplies is a function object. Specifically, it is an Adaptable Binary Function. If f is an object of class minus<T>, and x and y are objects of class T, then f(x,y) returns x*y.

The following code snippet demonstrates how to use

multiplies to multiply two device_vectors of floats.
Template Parameters
  • T: is a model of Assignable, and if x and y are objects of type T, then x*y must be defined and must have a return type that is convertible to T.

#include <thrust/device_vector.h>
#include <thrust/functional.h>
#include <thrust/sequence.h>
#include <thrust/fill.h>
#include <thrust/transform.h>
...
const int N = 1000;
thrust::device_vector<float> V1(N);
thrust::device_vector<float> V2(N);
thrust::device_vector<float> V3(N);

thrust::sequence(V1.begin(), V1.end(), 1);
thrust::fill(V2.begin(), V2.end(), 75);

thrust::transform(V1.begin(), V1.end(), V2.begin(), V3.begin(),
                   thrust::multiplies<float>());
// V3 is now {75, 150, 225, ..., 75000}

See

http://www.sgi.com/tech/stl/multiplies.html

See

binary_function

Public Types

typedef first_argument_type

The type of the function object’s first argument.

typedef second_argument_type

The type of the function object’s second argument.

typedef result_type

The type of the function object’s result;.

Public Functions

__host__ __device__ T thrust::multiplies::operator()(const T & lhs, const T & rhs) const

Function call operator. The return value is lhs * rhs.