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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
/*
* Advanced Simulation Library <http://asl.org.il>
*
* Copyright 2015 Avtech Scientific <http://avtechscientific.com>
*
*
* This file is part of Advanced Simulation Library (ASL).
*
* ASL is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, version 3 of the License.
*
* ASL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with ASL. If not, see <http://www.gnu.org/licenses/>.
*
*/
/**
\example testReductionFunction.cc
*/
#include "acl/Kernels/aclKernel.h"
#include "acl/aclUtilities.h"
#include "acl/aclMath/aclReductionAlgGenerator.h"
#include "acl/aclGenerators.h"
#include "aslUtilities.h"
#include "acl/aclMath/aclVectorOfElements.h"
using namespace acl;
bool testSum()
{
cout << "testSum..." << flush;
unsigned int n(101);
auto v(generateVEData<float>(n,1u));
initData(v, generateVEConstant(2));
auto summator(generateSumAlg<float>(v));
summator->generateAlg();
summator->compute();
bool status(asl::approxEqual(summator->res.v()[0],2.f*n));
asl::errorMessage(status);
return status;
}
bool testSum1()
{
cout << "testSum1..." << flush;
unsigned int n(100001);
VectorOfElements v1(generateVEData<float>(n,1u));
VectorOfElements v2(generateVEData<float>(n,1u));
initData(v1, generateVEConstant(2));
initData(v2, generateVEConstant(3));
auto summator(generateSumAlg<float>(v1*v2));
summator->generateAlg();
summator->compute();
bool status(asl::approxEqual(summator->res.v()[0],6.f*n));
asl::errorMessage(status);
return status;
}
bool testMin()
{
cout << "testMin..." << flush;
VectorOfElements vI(generateVEIndex());
VectorOfElements v1(generateVEData<float>(101u,1u));
initData(v1, generateVEConstant(2));
auto minimizer(generateMinAlg<float>(v1*((vI-100)*(vI-100)+3)));
minimizer->generateAlg();
minimizer->compute();
bool status(asl::approxEqual(minimizer->res.v()[0],6.f));
asl::errorMessage(status);
return status;
}
bool testMax()
{
cout << "testMax..." << flush;
VectorOfElements vI(generateVEIndex());
VectorOfElements v1(generateVEData<float>(100001u,1u));
initData(v1, generateVEConstant(2));
auto maximizer(generateMaxAlg<float>(v1*((1000.-vI)*(vI-1000.)-10.)));
maximizer->generateAlg();
maximizer->compute();
bool status(asl::approxEqual(maximizer->res.v()[0],-20.f));
asl::errorMessage(status);
return status;
}
bool testProduct()
{
cout << "testProduct..." << flush;
typedef double FT;
VectorOfElements vI(generateVEIndex());
VectorOfElements v1(generateVEData<FT>(100001u,1u));
initData(v1, generateVEConstant(2));
auto alg(generateProductAlg<FT>(select(generateVEConstant(1.),
v1,
vI >=1000 && vI <= 1007,
acl::typeToTypeID<FT>())));
alg->generateAlg();
alg->compute();
bool status(asl::approxEqual(alg->res.v()[0],256));
asl::errorMessage(status);
return status;
}
int main()
{
bool allTestsPassed(true);
allTestsPassed &= testSum();
allTestsPassed &= testSum1();
allTestsPassed &= testMin();
allTestsPassed &= testMax();
allTestsPassed &= testProduct();
return allTestsPassed ? EXIT_SUCCESS : EXIT_FAILURE;
}
|