CUSP
Loading...
Searching...
No Matches
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
31namespace cusp
32{
33
49namespace detail
50{
51template <typename> struct base_functor;
52template <typename> struct combine_tuple_base_functor;
53}
93template <typename T>
94struct plus_value : public detail::base_functor< ::cuda::std::plus<T> >
95{
97 _CCCL_HOST_DEVICE
98 plus_value(const T value = T(0)) : detail::base_functor< ::cuda::std::plus<T> >(value) {}
99};
100
136template <typename T>
137struct divide_value : public detail::base_functor< ::cuda::std::divides<T> >
138{
140 _CCCL_HOST_DEVICE
141 divide_value(const T value = T(0)) : detail::base_functor< ::cuda::std::divides<T> >(value) {}
142};
143
179template <typename T>
180struct modulus_value : public detail::base_functor< ::cuda::std::modulus<T> >
181{
183 _CCCL_HOST_DEVICE
184 modulus_value(const T value = T(0)) : detail::base_functor< ::cuda::std::modulus<T> >(value) {}
185};
186
222template <typename T>
223struct multiplies_value : public detail::base_functor< ::cuda::std::multiplies<T> >
224{
226 _CCCL_HOST_DEVICE
227 multiplies_value(const T value) : detail::base_functor< ::cuda::std::multiplies<T> >(value) {}
228};
229
264template <typename T>
265struct greater_value : public detail::base_functor< ::cuda::std::greater<T> >
266{
268 _CCCL_HOST_DEVICE
269 greater_value(const T value) : detail::base_functor< ::cuda::std::greater<T> >(value) {}
270};
271
306template <typename T>
307struct greater_equal_value : public detail::base_functor< ::cuda::std::greater_equal<T> >
308{
310 _CCCL_HOST_DEVICE
311 greater_equal_value(const T value) : detail::base_functor< ::cuda::std::greater_equal<T> >(value) {}
312};
313
349template <typename T>
350struct less_value : public detail::base_functor< ::cuda::std::less<T> >
351{
353 _CCCL_HOST_DEVICE
354 less_value(const T value) : detail::base_functor< ::cuda::std::less<T> >(value) {}
355};
356
391template <typename T>
392struct less_equal_value : public detail::base_functor< ::cuda::std::less_equal<T> >
393{
395 _CCCL_HOST_DEVICE
396 less_equal_value(const T value) : detail::base_functor< ::cuda::std::less_equal<T> >(value) {}
397};
398
433template<typename T>
435{
436 private:
437 T val;
438
439 public:
441 _CCCL_HOST_DEVICE
442 constant_functor(const T val = 0) : val(val) {}
443
445 _CCCL_HOST_DEVICE
446 T operator()(const T& x) const {
447 return val;
448 }
449};
450
485template <typename T>
487{
489 _CCCL_HOST_DEVICE
490 T operator()(const T& x) const {
491 return x * x;
492 }
493};
494
529template <typename T>
531{
533 _CCCL_HOST_DEVICE
534 T operator()(const T& x) const {
535 using thrust::sqrt;
536 using std::sqrt;
537
538 return sqrt(x);
539 }
540};
541
576template <typename T>
578{
580 _CCCL_HOST_DEVICE
581 T operator()(const T& v) const {
582 return T(1.0) / v;
583 }
584};
585
620template<typename T>
622{
624 _CCCL_HOST_DEVICE
625 typename cusp::norm_type<T>::type
626 operator()(const T& t) const {
627 return cusp::abs(t);
628 }
629};
630
666template<typename T>
668{
670 _CCCL_HOST_DEVICE
671 typename cusp::norm_type<T>::type
675};
676
711template<typename T>
713{
715 _CCCL_HOST_DEVICE
716 T operator()(const T& t) const {
717 return cusp::conj(t);
718 }
719};
720
755template<typename T>
757{
759 _CCCL_HOST_DEVICE
760 typename cusp::norm_type<T>::type
761 operator()(const T& t) const {
762 return cusp::norm(t);
763 }
764};
765
806template <typename T>
807struct sum_pair_functor : public detail::combine_tuple_base_functor< ::cuda::std::plus<T> > {};
808
850template <typename T>
851struct divide_pair_functor : public detail::combine_tuple_base_functor< ::cuda::std::divides<T> > {};
852
893template <typename T>
894struct equal_pair_functor : public detail::combine_tuple_base_functor< ::cuda::std::equal_to<T> > {};
895
936template <typename T>
937struct not_equal_pair_functor : public detail::combine_tuple_base_functor< ::cuda::std::not_equal_to<T> > {};
938
942} // end namespace cusp
943
944#include <cusp/detail/functional.inl>
945
Complex numbers.
_CCCL_HOST_DEVICE cusp::norm_type< T >::type abs(const T &z)
Compute the absolute value of z.
Definition complex.h:67
_CCCL_HOST_DEVICE cusp::norm_type< T >::type norm(const T &z)
Compute the norm of z.
Definition complex.h:77
_CCCL_HOST_DEVICE T conj(const T &z)
Compute the complex conjugate of z. For real types, returns z unchanged.
Definition complex.h:57
abs_functor is a function object that computes the absolute value of a given element.
Definition functional.h:622
_CCCL_HOST_DEVICE cusp::norm_type< T >::type operator()(const T &t) const
Return the absolute value of t.
Definition functional.h:626
abs_squared_functor is a function object that computes the square of the absolute value of a given el...
Definition functional.h:668
_CCCL_HOST_DEVICE cusp::norm_type< T >::type operator()(const T &t) const
Return the squared absolute value of t.
Definition functional.h:672
conj_functor is a function object that computes the conjugate of a given element.
Definition functional.h:713
_CCCL_HOST_DEVICE T operator()(const T &t) const
Return the complex conjugate of t.
Definition functional.h:716
constant_functor is a function object returns a constant value, ignores the input.
Definition functional.h:435
_CCCL_HOST_DEVICE T operator()(const T &x) const
Return the stored constant, ignoring input x.
Definition functional.h:446
_CCCL_HOST_DEVICE constant_functor(const T val=0)
Construct with the given constant val.
Definition functional.h:442
divide_pair_functor is a function object that divides the first element of a 2 element tuple by the s...
Definition functional.h:851
divide_value is a function object to divide a given element by a constant value.
Definition functional.h:138
_CCCL_HOST_DEVICE divide_value(const T value=T(0))
Construct with the given constant value.
Definition functional.h:141
equal_pair_functor is a function object that compares 2 element tuple entries.
Definition functional.h:894
greater_equal_value is a function object that compares a given element with a constant value.
Definition functional.h:308
_CCCL_HOST_DEVICE greater_equal_value(const T value)
Construct with the given constant value.
Definition functional.h:311
greater_value is a function object that compares a given element with a constant value.
Definition functional.h:266
_CCCL_HOST_DEVICE greater_value(const T value)
Construct with the given constant value.
Definition functional.h:269
less_equal_value is a function object that compares a given element with a constant value.
Definition functional.h:393
_CCCL_HOST_DEVICE less_equal_value(const T value)
Construct with the given constant value.
Definition functional.h:396
less_value is a function object that compares a given element with a constant value.
Definition functional.h:351
_CCCL_HOST_DEVICE less_value(const T value)
Construct with the given constant value.
Definition functional.h:354
modulus_value is a function object that computes the modulus of a given element by a constant value.
Definition functional.h:181
_CCCL_HOST_DEVICE modulus_value(const T value=T(0))
Construct with the given constant value.
Definition functional.h:184
multiplies_value is a function object that computes the multiply of a given element by a constant val...
Definition functional.h:224
_CCCL_HOST_DEVICE multiplies_value(const T value)
Construct with the given constant value.
Definition functional.h:227
norm_functor is a function object that computes the norm of a given element.
Definition functional.h:757
_CCCL_HOST_DEVICE cusp::norm_type< T >::type operator()(const T &t) const
Return the norm of t.
Definition functional.h:761
not_equal_pair_functor is a function object that compares 2 element tuple entries.
Definition functional.h:937
plus_value is a function object to add a constant value to a given element.
Definition functional.h:95
_CCCL_HOST_DEVICE plus_value(const T value=T(0))
Construct with the given constant value.
Definition functional.h:98
reciprocal_functor is a function object computes the reciprocal, 1/x, of a given element.
Definition functional.h:578
_CCCL_HOST_DEVICE T operator()(const T &v) const
Return the reciprocal of v.
Definition functional.h:581
sqrt_functor is a function object that computes the square root of a given element.
Definition functional.h:531
_CCCL_HOST_DEVICE T operator()(const T &x) const
Return the square root of x.
Definition functional.h:534
square_functor is a function object that computes the square (x*x) of a given element.
Definition functional.h:487
_CCCL_HOST_DEVICE T operator()(const T &x) const
Return the square of x.
Definition functional.h:490
sum_pair_functor is a function object that computes the sum of a 2 element tuple.
Definition functional.h:807