-
Notifications
You must be signed in to change notification settings - Fork 13
/
hpc_functional.hpp
89 lines (77 loc) · 1.43 KB
/
hpc_functional.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#pragma once
#include <hpc_macros.hpp>
namespace hpc {
template <class T>
HPC_ALWAYS_INLINE HPC_HOST_DEVICE constexpr T
max(T const& a, T const& b) noexcept
{
return (a < b) ? b : a;
}
template <class T>
HPC_ALWAYS_INLINE HPC_HOST_DEVICE constexpr T
min(T const& a, T const& b) noexcept
{
return (b < a) ? b : a;
}
template <class T>
struct minimum
{
HPC_ALWAYS_INLINE HPC_HOST_DEVICE constexpr T
operator()(T const& a, T const& b) noexcept
{
return ::hpc::min(a, b);
}
};
template <class T>
struct maximum
{
HPC_ALWAYS_INLINE HPC_HOST_DEVICE constexpr T
operator()(T const& a, T const& b) noexcept
{
return ::hpc::max(a, b);
}
};
template <class T>
struct plus
{
HPC_ALWAYS_INLINE HPC_HOST_DEVICE constexpr T
operator()(T const& a, T const& b) noexcept
{
return a + b;
}
};
template <class T>
struct identity
{
HPC_ALWAYS_INLINE HPC_HOST_DEVICE constexpr T
operator()(T const& a) noexcept
{
return a;
}
};
struct logical_or
{
HPC_ALWAYS_INLINE HPC_HOST_DEVICE constexpr bool
operator()(bool const a, bool const b) const noexcept
{
return a || b;
}
};
struct logical_and
{
HPC_ALWAYS_INLINE HPC_HOST_DEVICE constexpr bool
operator()(bool const a, bool const b) const noexcept
{
return a && b;
}
};
template <class To, class From>
struct cast
{
HPC_ALWAYS_INLINE HPC_HOST_DEVICE constexpr To
operator()(From const& a) noexcept
{
return a;
}
};
} // namespace hpc