ASL 0.1.7
Advanced Simulation Library
Loading...
Searching...
No Matches
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
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
35using namespace acl;
36
37bool testSum()
38{
39 cout << "testSum..." << flush;
40 unsigned int n(101);
41 auto v(generateVEData<float>(n,1u));
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
54{
55 cout << "testSum1..." << flush;
56 unsigned int n(100001);
57 VectorOfElements v1(generateVEData<float>(n,1u));
58 VectorOfElements v2(generateVEData<float>(n,1u));
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
71bool testMin()
72{
73 cout << "testMin..." << flush;
75 VectorOfElements v1(generateVEData<float>(101u,1u));
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
87bool testMax()
88{
89 cout << "testMax..." << flush;
91 VectorOfElements v1(generateVEData<float>(100001u,1u));
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
103{
104 cout << "testProduct..." << flush;
105 typedef double FT;
107 VectorOfElements v1(generateVEData<FT>(100001u,1u));
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
122int 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}
The class represents several Element.
void errorMessage(cl_int status, const char *errorMessage)
Prints errorMessage and exits depending on the status.
void initData(Element a, Element initializationValue, const KernelConfiguration &kernelConfig=KERNEL_BASIC)
VectorOfElements generateVEConstant(T a)
Generates VectorOfElements with 1 Element acl::Constant with value a.
VectorOfElements generateVEIndex(unsigned int size=0)
Advanced Computational Language.
Definition acl.h:41
const bool approxEqual(const double &a, const double &b, const double p_=1e-6)
Approximately equal; the precision is defined as p_.
bool testProduct()
bool testSum1()
bool testMin()
bool testSum()
bool testMax()