ASL
0.1.7
Advanced Simulation Library
Toggle main menu visibility
Loading...
Searching...
No Matches
test
testACL
testMatrixOfElements.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/acl.h
"
29
#include "
acl/aclGenerators.h
"
30
#include "
acl/aclMath/aclMatrixOfElements.h
"
31
#include "
acl/aclMath/aclVectorOfElements.h
"
32
#include "
acl/aclMath/aclVectorOfElements.h
"
33
#include "
math/aslMatrices.h
"
34
#include "
acl/Kernels/aclKernel.h
"
35
#include "
acl/DataTypes/aclArray.h
"
36
37
using namespace
asl
;
38
using namespace
acl
;
39
using namespace
std
;
40
41
bool
testMatrixOperations
()
42
{
43
cout <<
"Test of \"Matrix Operations\" function..."
<< flush;
44
45
VectorOfElements
vec0(3);
46
VectorOfElements
vec1(1);
47
copy
(
generateVEData<cl_float>
(10u,3u),vec0);
48
copy
(
generateVEData<cl_float>
(10u,1u),vec1);
49
50
Kernel
k;
51
{
52
using namespace
elementOperators
;
53
k << (vec0=
generateVEConstant
(0.1f,1.f,2.f));
54
k << (vec1=(
elementProduct
(
generateVEConstant
(0.f,1.f,2.f),vec0)*
generateVEConstant
(1.f,0.f,2.f))*vec0);
55
}
56
k.
setup
();
57
k.
compute
();
58
59
vector<cl_float> output(10);
60
copy
(vec1[0], output);
61
62
bool
status(output[1] == 20.5);
63
errorMessage
(status);
64
65
return
status;
66
}
67
68
69
bool
testSystemSolve
()
70
{
71
cout <<
"Test of \"System Solve Cramer's rule\" function..."
<< flush;
72
73
VectorOfElements
vecB(2);
74
VectorOfElements
vecX(2);
75
copy
(
generateVEData<cl_float>
(10u,2u),vecB);
76
copy
(
generateVEData<cl_float>
(10u,2u),vecX);
77
78
auto
matA(
generateMEConstant
(
makeAMatr
(
makeAVec
(4.,1.),
makeAVec
(1.,3.))));
79
80
Kernel
k;
81
{
82
using namespace
elementOperators
;
83
k << (vecB=
generateVEConstant
(1.f,2.f));
84
k <<
gcSolveSystem
(matA,vecB,vecX);
85
}
86
k.
setup
();
87
k.
compute
();
88
89
vector<cl_float> output(10);
90
copy
(vecX[0], output);
91
92
bool
status(output[1] > 0.09 && output[1] < .1);
93
errorMessage
(status);
94
95
return
status;
96
}
97
98
bool
testSystemSolveCG
()
99
{
100
cout <<
"Test of \"System Solve congugate gradient method\" function..."
<< flush;
101
102
VectorOfElements
vecB(2);
103
VectorOfElements
vecX(2);
104
copy
(
generateVEData<cl_float>
(10u,2u),vecB);
105
copy
(
generateVEData<cl_float>
(10u,2u),vecX);
106
107
auto
matA(
generateMEConstant
(
makeAMatr
(
makeAVec
(4.,1.),
makeAVec
(1.,3.))));
108
109
Kernel
k;
110
{
111
using namespace
elementOperators
;
112
k << (vecB=
generateVEConstant
(1.f,2.f));
113
k <<
gcSolveSystemCG
(matA,vecB,vecX);
114
}
115
k.
setup
();
116
k.
compute
();
117
118
vector<cl_float> output(10);
119
copy
(vecX[0], output);
120
121
bool
status(output[1] > 0.09 && output[1] < .1);
122
errorMessage
(status);
123
124
return
status;
125
}
126
127
128
int
main
()
129
{
130
bool
allTestsPassed(
true
);
131
132
allTestsPassed &=
testMatrixOperations
();
133
allTestsPassed &=
testSystemSolve
();
134
allTestsPassed &=
testSystemSolveCG
();
135
136
return
allTestsPassed ? EXIT_SUCCESS : EXIT_FAILURE;
137
}
acl.h
aclArray.h
aclGenerators.h
aclKernel.h
aclMatrixOfElements.h
aclVectorOfElements.h
aslMatrices.h
Matrices.
acl::Kernel
OpenCl Kernel generator.
Definition
aclKernel.h:49
acl::Kernel::setup
void setup()
acl::Kernel::compute
void compute()
acl::MatrixOfElements::elementProduct
MatrixOfElements elementProduct(const VectorOfElements &a, const VectorOfElements &b)
element product of two vectors
acl::VectorOfElements
The class represents several Element.
Definition
aclVectorOfElementsDef.h:92
asl::AMatr::makeAMatr
AMatr< T > makeAMatr(const AVec< T > &a)
generates a matrix with a row
acl::gcSolveSystemCG
vector< Element > gcSolveSystemCG(const MatrixOfElements &a, const VectorOfElements &b, const VectorOfElements &x)
generates code for solving the solution of a system of linear equations
acl::gcSolveSystem
vector< Element > gcSolveSystem(const MatrixOfElements &a, const VectorOfElements &b, const VectorOfElements &x)
generates code for solving the solution of a system of linear equations
asl::errorMessage
void errorMessage(cl_int status, const char *errorMessage)
Prints errorMessage and exits depending on the status.
acl::generateMEConstant
MatrixOfElements generateMEConstant(const asl::AMatr< T > &a)
Generates VectorOfElements correspondinng to a.
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::elementOperators
definitions of mathematical operators and functions for class Element
Definition
acl.h:56
acl
Advanced Computational Language.
Definition
acl.h:41
acl::copy
void copy(MemBlock &source, T *destination)
asl
Advanced Simulation Library.
Definition
aslDataInc.h:31
asl::makeAVec
AVec< T > makeAVec(T a1)
Definition
aslVectorsDynamicLength.h:176
std
STL namespace.
testSystemSolve
bool testSystemSolve()
Definition
testMatrixOfElements.cc:69
testMatrixOperations
bool testMatrixOperations()
Definition
testMatrixOfElements.cc:41
testSystemSolveCG
bool testSystemSolveCG()
Definition
testMatrixOfElements.cc:98
main
int main()
Definition
testMatrixOfElements.cc:128
Generated by
1.17.0