ASL
0.1.7
Advanced Simulation Library
Toggle main menu visibility
Loading...
Searching...
No Matches
test
testMath
testReductionFunction.cc
Go to the documentation of this file.
1
/*
2
* Advanced Simulation Library <http://asl.org.il>
3
*
4
* Copyright 2015 Avtech Scientific <http://avtechscientific.com>
5
*
6
*
7
* This file is part of Advanced Simulation Library (ASL).
8
*
9
* ASL is free software: you can redistribute it and/or modify it
10
* under the terms of the GNU Affero General Public License as
11
* published by the Free Software Foundation, version 3 of the License.
12
*
13
* ASL is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU Affero General Public License for more details.
17
*
18
* You should have received a copy of the GNU Affero General Public License
19
* along with ASL. If not, see <http://www.gnu.org/licenses/>.
20
*
21
*/
22
23
27
28
#include "
acl/Kernels/aclKernel.h
"
29
#include "
acl/aclUtilities.h
"
30
#include "
acl/aclMath/aclReductionAlgGenerator.h
"
31
#include "
acl/aclGenerators.h
"
32
#include "
aslUtilities.h
"
33
#include "
acl/aclMath/aclVectorOfElements.h
"
34
35
using namespace
acl
;
36
37
bool
testSum
()
38
{
39
cout <<
"testSum..."
<< flush;
40
unsigned
int
n(101);
41
auto
v(
generateVEData<float>
(n,1u));
42
initData
(v,
generateVEConstant
(2));
43
auto
summator(
generateSumAlg<float>
(v));
44
summator->generateAlg();
45
summator->compute();
46
bool
status(
asl::approxEqual
(summator->res.v()[0],2.f*n));
47
asl::errorMessage
(status);
48
49
return
status;
50
}
51
52
53
bool
testSum1
()
54
{
55
cout <<
"testSum1..."
<< flush;
56
unsigned
int
n(100001);
57
VectorOfElements
v1(
generateVEData<float>
(n,1u));
58
VectorOfElements
v2(
generateVEData<float>
(n,1u));
59
initData
(v1,
generateVEConstant
(2));
60
initData
(v2,
generateVEConstant
(3));
61
auto
summator(
generateSumAlg<float>
(v1*v2));
62
summator->generateAlg();
63
summator->compute();
64
bool
status(
asl::approxEqual
(summator->res.v()[0],6.f*n));
65
asl::errorMessage
(status);
66
67
return
status;
68
}
69
70
71
bool
testMin
()
72
{
73
cout <<
"testMin..."
<< flush;
74
VectorOfElements
vI(
generateVEIndex
());
75
VectorOfElements
v1(
generateVEData<float>
(101u,1u));
76
initData
(v1,
generateVEConstant
(2));
77
auto
minimizer(
generateMinAlg<float>
(v1*((vI-100)*(vI-100)+3)));
78
minimizer->generateAlg();
79
minimizer->compute();
80
bool
status(
asl::approxEqual
(minimizer->res.v()[0],6.f));
81
asl::errorMessage
(status);
82
83
return
status;
84
}
85
86
87
bool
testMax
()
88
{
89
cout <<
"testMax..."
<< flush;
90
VectorOfElements
vI(
generateVEIndex
());
91
VectorOfElements
v1(
generateVEData<float>
(100001u,1u));
92
initData
(v1,
generateVEConstant
(2));
93
auto
maximizer(
generateMaxAlg<float>
(v1*((1000.-vI)*(vI-1000.)-10.)));
94
maximizer->generateAlg();
95
maximizer->compute();
96
bool
status(
asl::approxEqual
(maximizer->res.v()[0],-20.f));
97
asl::errorMessage
(status);
98
99
return
status;
100
}
101
102
bool
testProduct
()
103
{
104
cout <<
"testProduct..."
<< flush;
105
typedef
double
FT;
106
VectorOfElements
vI(
generateVEIndex
());
107
VectorOfElements
v1(
generateVEData<FT>
(100001u,1u));
108
initData
(v1,
generateVEConstant
(2));
109
auto
alg(
generateProductAlg<FT>
(
select
(
generateVEConstant
(1.),
110
v1,
111
vI >=1000 && vI <= 1007,
112
acl::typeToTypeID<FT>
())));
113
alg->generateAlg();
114
alg->compute();
115
bool
status(
asl::approxEqual
(alg->res.v()[0],256));
116
asl::errorMessage
(status);
117
118
return
status;
119
}
120
121
122
int
main
()
123
{
124
bool
allTestsPassed(
true
);
125
126
allTestsPassed &=
testSum
();
127
allTestsPassed &=
testSum1
();
128
allTestsPassed &=
testMin
();
129
allTestsPassed &=
testMax
();
130
allTestsPassed &=
testProduct
();
131
132
return
allTestsPassed ? EXIT_SUCCESS : EXIT_FAILURE;
133
}
aclGenerators.h
aclKernel.h
aclReductionAlgGenerator.h
aclUtilities.h
aclVectorOfElements.h
aslUtilities.h
useful common utilities
acl::VectorOfElements
The class represents several Element.
Definition
aclVectorOfElementsDef.h:92
asl::errorMessage
void errorMessage(cl_int status, const char *errorMessage)
Prints errorMessage and exits depending on the status.
acl::initData
void initData(Element a, Element initializationValue, const KernelConfiguration &kernelConfig=KERNEL_BASIC)
acl::VectorOfElements::select
VectorOfElements select(const VectorOfElements &a, const VectorOfElements &b, const VectorOfElements &c)
acl::generateVEData
VectorOfElementsData generateVEData(unsigned int length, unsigned int nComponents, CommandQueue queue)
Generates VectorOfElements with nComponents Elements acl::Vector with size length.
acl::generateVEConstant
VectorOfElements generateVEConstant(T a)
Generates VectorOfElements with 1 Element acl::Constant with value a.
acl::generateVEIndex
VectorOfElements generateVEIndex(unsigned int size=0)
acl
Advanced Computational Language.
Definition
acl.h:41
acl::generateSumAlg
std::shared_ptr< ReductionAlgGenerator< ResType, ROT_SUM > > generateSumAlg(VectorOfElements v)
acl::generateProductAlg
std::shared_ptr< ReductionAlgGenerator< ResType, ROT_PRODUCT > > generateProductAlg(VectorOfElements v)
acl::typeToTypeID
constexpr const TypeID typeToTypeID()
acl::generateMaxAlg
std::shared_ptr< ReductionAlgGenerator< ResType, ROT_MAXIMUM > > generateMaxAlg(VectorOfElements v)
acl::generateMinAlg
std::shared_ptr< ReductionAlgGenerator< ResType, ROT_MINIMUM > > generateMinAlg(VectorOfElements v)
asl::approxEqual
const bool approxEqual(const double &a, const double &b, const double p_=1e-6)
Approximately equal; the precision is defined as p_.
Definition
aslUtilities.h:105
testProduct
bool testProduct()
Definition
testReductionFunction.cc:102
testSum1
bool testSum1()
Definition
testReductionFunction.cc:53
testMin
bool testMin()
Definition
testReductionFunction.cc:71
testSum
bool testSum()
Definition
testReductionFunction.cc:37
main
int main()
Definition
testReductionFunction.cc:122
testMax
bool testMax()
Definition
testReductionFunction.cc:87
Generated by
1.17.0