Fork me on GitHub
 All Classes Files Functions Variables Groups Pages
functional.h
Go to the documentation of this file.
1 /*
2  * Copyright 2008-2014 NVIDIA Corporation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
23 #pragma once
24 
25 #include <cusp/detail/config.h>
26 
27 #include <cusp/complex.h>
28 
29 #include <thrust/functional.h>
30 
31 namespace cusp
32 {
33 
49 namespace detail
50 {
51 template <typename> struct base_functor;
52 template <typename> struct combine_tuple_base_functor;
53 }
93 template <typename T>
94 struct plus_value : public detail::base_functor< thrust::plus<T> >
95 {
96  __host__ __device__
97  plus_value(const T value = T(0)) : detail::base_functor< thrust::plus<T> >(value) {}
98 };
99 
135 template <typename T>
136 struct divide_value : public detail::base_functor< thrust::divides<T> >
137 {
138  __host__ __device__
139  divide_value(const T value = T(0)) : detail::base_functor< thrust::divides<T> >(value) {}
140 };
141 
177 template <typename T>
178 struct modulus_value : public detail::base_functor< thrust::modulus<T> >
179 {
180  __host__ __device__
181  modulus_value(const T value = T(0)) : detail::base_functor< thrust::modulus<T> >(value) {}
182 };
183 
219 template <typename T>
220 struct multiplies_value : public detail::base_functor< thrust::multiplies<T> >
221 {
222  __host__ __device__
223  multiplies_value(const T value) : detail::base_functor< thrust::multiplies<T> >(value) {}
224 };
225 
260 template <typename T>
261 struct greater_value : public detail::base_functor< thrust::greater<T> >
262 {
263  __host__ __device__
264  greater_value(const T value) : detail::base_functor< thrust::greater<T> >(value) {}
265 };
266 
301 template <typename T>
302 struct greater_equal_value : public detail::base_functor< thrust::greater_equal<T> >
303 {
304  __host__ __device__
305  greater_equal_value(const T value) : detail::base_functor< thrust::greater_equal<T> >(value) {}
306 };
307 
343 template <typename T>
344 struct less_value : public detail::base_functor< thrust::less<T> >
345 {
346  __host__ __device__
347  less_value(const T value) : detail::base_functor< thrust::less<T> >(value) {}
348 };
349 
384 template <typename T>
385 struct less_equal_value : public detail::base_functor< thrust::less_equal<T> >
386 {
387  __host__ __device__
388  less_equal_value(const T value) : detail::base_functor< thrust::less_equal<T> >(value) {}
389 };
390 
425 template<typename T>
426 struct constant_functor : public thrust::unary_function<T,T>
427 {
428  private:
429  T val;
430 
431  public:
432  __host__ __device__
433  constant_functor(const T val = 0) : val(val) {}
434 
435  __host__ __device__
436  T operator()(const T& x) const {
437  return val;
438  }
439 };
440 
475 template <typename T>
476 struct square_functor : public thrust::unary_function<T,T>
477 {
478  __host__ __device__
479  T operator()(const T& x) const {
480  return x * x;
481  }
482 };
483 
518 template <typename T>
519 struct sqrt_functor : public thrust::unary_function<T,T>
520 {
521  __host__ __device__
522  T operator()(const T& x) const {
523  using thrust::sqrt;
524  using std::sqrt;
525 
526  return sqrt(x);
527  }
528 };
529 
564 template <typename T>
565 struct reciprocal_functor : public thrust::unary_function<T,T>
566 {
567  __host__ __device__
568  T operator()(const T& v) const {
569  return T(1.0) / v;
570  }
571 };
572 
607 template<typename T>
608 struct abs_functor : public thrust::unary_function<T, typename cusp::norm_type<T>::type>
609 {
610  __host__ __device__
611  typename cusp::norm_type<T>::type
612  operator()(const T& t) const {
613  return cusp::abs(t);
614  }
615 };
616 
652 template<typename T>
653 struct abs_squared_functor : public thrust::unary_function<T, typename cusp::norm_type<T>::type>
654 {
655  __host__ __device__
656  typename cusp::norm_type<T>::type
657  operator()(const T& t) const {
659  }
660 };
661 
696 template<typename T>
697 struct conj_functor : public thrust::unary_function<T,T>
698 {
699  __host__ __device__
700  T operator()(const T& t) const {
701  return cusp::conj(t);
702  }
703 };
704 
739 template<typename T>
740 struct norm_functor : public thrust::unary_function<T, typename cusp::norm_type<T>::type>
741 {
742  __host__ __device__
743  typename cusp::norm_type<T>::type
744  operator()(const T& t) const {
745  return cusp::norm(t);
746  }
747 };
748 
789 template <typename T>
790 struct sum_pair_functor : public detail::combine_tuple_base_functor< thrust::plus<T> > {};
791 
833 template <typename T>
834 struct divide_pair_functor : public detail::combine_tuple_base_functor< thrust::divides<T> > {};
835 
876 template <typename T>
877 struct equal_pair_functor : public detail::combine_tuple_base_functor< thrust::equal_to<T> > {};
878 
919 template <typename T>
920 struct not_equal_pair_functor : public detail::combine_tuple_base_functor< thrust::not_equal_to<T> > {};
921 
925 } // end namespace cusp
926 
927 #include <cusp/detail/functional.inl>
928 
sum_pair_functor is a function object that computes the sum of a 2 element tuple. ...
Definition: functional.h:790
Complex numbers.
less_equal_value is a function object that compares a given element with a constant value...
Definition: functional.h:385
modulus_value is a function object that computes the modulus of a given element by a constant value...
Definition: functional.h:178
norm_functor is a function object that computes the norm of a given element.
Definition: functional.h:740
abs_squared_functor is a function object that computes the square of the absolute value of a given el...
Definition: functional.h:653
not_equal_pair_functor is a function object that compares 2 element tuple entries.
Definition: functional.h:920
equal_pair_functor is a function object that compares 2 element tuple entries.
Definition: functional.h:877
sqrt_functor is a function object that computes the square root of a given element.
Definition: functional.h:519
conj_functor is a function object that computes the conjugate of a given element. ...
Definition: functional.h:697
plus_value is a function object to add a constant value to a given element.
Definition: functional.h:94
abs_functor is a function object that computes the absolute value of a given element.
Definition: functional.h:608
greater_value is a function object that compares a given element with a constant value.
Definition: functional.h:261
greater_equal_value is a function object that compares a given element with a constant value...
Definition: functional.h:302
divide_value is a function object to divide a given element by a constant value.
Definition: functional.h:136
square_functor is a function object that computes the square (x*x) of a given element.
Definition: functional.h:476
divide_pair_functor is a function object that divides the first element of a 2 element tuple by the s...
Definition: functional.h:834
multiplies_value is a function object that computes the multiply of a given element by a constant val...
Definition: functional.h:220
reciprocal_functor is a function object computes the reciprocal, 1/x, of a given element.
Definition: functional.h:565
constant_functor is a function object returns a constant value, ignores the input.
Definition: functional.h:426
less_value is a function object that compares a given element with a constant value.
Definition: functional.h:344