Bolt
1.1
C++ template library with support for OpenCL
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
Bolt_Clone_master
include
bolt
amp
functional.h
Go to the documentation of this file.
1
/***************************************************************************
2
* Copyright 2012 - 2013 Advanced Micro Devices, Inc.
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
#if !defined( BOLT_AMP_FUNCTIONAL_H )
25
#define BOLT_AMP_FUNCTIONAL_H
26
27
#include "
bolt/amp/bolt.h
"
28
29
30
namespace
bolt {
31
namespace
amp {
32
template
<
typename
Argument1,
33
typename
Result>
34
struct
unary_function
35
:
public
std::unary_function<Argument1, Result>
36
{
37
};
38
39
template
<
typename
Argument1,
40
typename
Argument2,
41
typename
Result>
42
struct
binary_function
43
:
public
std::binary_function<Argument1, Argument2, Result>
44
{
45
};
46
47
/******************************************************************************
48
* Unary Operators
49
*****************************************************************************/
50
template
<
typename
T>
51
struct
square
:
public
unary_function
<T,T>
52
{
53
T operator() (
const
T& x)
const
restrict(cpu,amp) {
54
return
x * x;
55
}
56
};
57
58
template
<
typename
T >
59
struct
cube
:
public
unary_function
<T,T>
60
{
61
T operator() (
const
T& x)
const
restrict(cpu,amp) {
return
x * x * x; }
62
};
63
64
65
template
<
typename
T>
66
struct
negate
:
public
unary_function
<T,T>
67
{
68
T operator()(
const
T &__x)
const
restrict(cpu,amp) {
return
-__x;}
69
};
70
71
/******************************************************************************
72
* Binary Operators
73
*****************************************************************************/
74
75
template
<
typename
T>
76
struct
plus
:
public
binary_function
<T,T,T>
77
{
78
T operator()(
const
T &lhs,
const
T &rhs)
const
restrict(cpu,amp) {
return
lhs + rhs;}
79
};
80
81
template
<
typename
T>
82
struct
minus
:
public
binary_function
<T,T,T>
83
{
84
T operator()(
const
T &lhs,
const
T &rhs)
const
restrict(cpu,amp) {
return
lhs - rhs;}
85
};
86
87
template
<
typename
T>
88
struct
multiplies
:
public
binary_function
<T,T,T>
89
{
90
T operator()(
const
T &lhs,
const
T &rhs)
const
restrict(cpu,amp) {
return
lhs * rhs;}
91
};
92
93
template
<
typename
T>
94
struct
divides
:
public
binary_function
<T,T,T>
95
{
96
T operator()(
const
T &lhs,
const
T &rhs)
const
restrict(cpu,amp) {
return
lhs / rhs;}
97
};
98
99
100
template
<
typename
T>
101
struct
maximum
:
public
binary_function
<T,T,T>
102
{
103
T operator()(
const
T &lhs,
const
T &rhs)
const
restrict(cpu,amp) {
return
rhs > lhs ? rhs:lhs;}
104
};
105
106
template
<
typename
T>
107
struct
minimum
:
public
binary_function
<T,T,T>
108
{
109
T operator()(
const
T &lhs,
const
T &rhs)
const
restrict(cpu,amp) {
return
rhs < lhs ? rhs:lhs;}
110
};
111
112
template
<
typename
T>
113
struct
modulus
:
public
binary_function
<T,T,T>
114
{
115
T operator()(
const
T &lhs,
const
T &rhs)
const
restrict(cpu,amp) {
return
lhs % rhs;}
116
};
117
118
template
<
typename
T>
119
struct
bit_and
:
public
binary_function
<T,T,T>
120
{
121
T operator()(
const
T &lhs,
const
T &rhs)
const
restrict(cpu,amp) {
return
lhs & rhs;}
122
};
123
124
template
<
typename
T>
125
struct
bit_or
:
public
binary_function
<T,T,T>
126
{
127
T operator()(
const
T &lhs,
const
T &rhs)
const
restrict(cpu,amp) {
return
lhs | rhs;}
128
};
129
130
template
<
typename
T>
131
struct
bit_xor
:
public
binary_function
<T,T,T>
132
{
133
T operator()(
const
T &lhs,
const
T &rhs)
const
restrict(cpu,amp) {
return
lhs ^ rhs;}
134
};
135
136
137
/******************************************************************************
138
* Unary Predicates
139
*****************************************************************************/
140
141
template
<
typename
T>
142
struct
logical_not
:
public
unary_function
<T,T>
143
{
144
bool
operator()(
const
T &x)
const
restrict(cpu,amp) {
return
!x;}
145
};
146
147
148
/******************************************************************************
149
* Binary Predicates
150
*****************************************************************************/
151
152
template
<
typename
T>
153
struct
equal_to
:
public
binary_function
<T,T,T>
154
{
155
bool
operator()(
const
T &lhs,
const
T &rhs)
const
restrict(cpu,amp) {
return
lhs == rhs;}
156
};
157
158
template
<
typename
T>
159
struct
not_equal_to
:
public
binary_function
<T,T,T>
160
{
161
bool
operator()(
const
T &lhs,
const
T &rhs)
const
restrict(cpu,amp) {
return
lhs != rhs;}
162
};
163
164
template
<
typename
T>
165
struct
greater
:
public
binary_function
<T,T,T>
166
{
167
bool
operator()(
const
T &lhs,
const
T &rhs)
const
restrict(cpu,amp) {
return
lhs > rhs;}
168
};
169
170
template
<
typename
T>
171
struct
less
:
public
binary_function
<T,T,T>
172
{
173
bool
operator()(
const
T &lhs,
const
T &rhs)
const
restrict(cpu,amp) {
return
lhs < rhs;}
174
};
175
176
template
<
typename
T>
177
struct
greater_equal
:
public
binary_function
<T,T,T>
178
{
179
bool
operator()(
const
T &lhs,
const
T &rhs)
const
restrict(cpu,amp) {
return
lhs >= rhs;}
180
};
181
182
template
<
typename
T>
183
struct
less_equal
:
public
binary_function
<T,T,T>
184
{
185
bool
operator()(
const
T &lhs,
const
T &rhs)
const
restrict(cpu,amp) {
return
lhs <= rhs;}
186
};
187
188
template
<
typename
T>
189
struct
logical_and
:
public
binary_function
<T,T,T>
190
{
191
bool
operator()(
const
T &lhs,
const
T &rhs)
const
restrict(cpu,amp) {
return
lhs && rhs;}
192
};
193
194
template
<
typename
T>
195
struct
logical_or
:
public
binary_function
<T,T,T>
196
{
197
bool
operator()(
const
T &lhs,
const
T &rhs)
const
restrict(cpu,amp) {
return
lhs || rhs;}
198
};
199
200
201
};
202
};
203
204
#endif
Generated on Mon Nov 11 2013 14:17:19 for Bolt by
1.8.3