File: testMatrixOfElements.cc

package info (click to toggle)
asl 0.1.7-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,536 kB
  • sloc: cpp: 36,180; makefile: 26
file content (137 lines) | stat: -rw-r--r-- 3,302 bytes parent folder | download | duplicates (4)
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
134
135
136
137
/*
 * 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 testMatrixOfElements.cc
 */

#include "acl/acl.h"
#include "acl/aclGenerators.h"
#include "acl/aclMath/aclMatrixOfElements.h"
#include "acl/aclMath/aclVectorOfElements.h"
#include "acl/aclMath/aclVectorOfElements.h"
#include "math/aslMatrices.h"
#include "acl/Kernels/aclKernel.h"
#include "acl/DataTypes/aclArray.h"

using namespace asl;
using namespace acl;
using namespace std;

bool testMatrixOperations()
{
	cout << "Test of \"Matrix Operations\" function..." << flush;

	VectorOfElements vec0(3);
	VectorOfElements vec1(1);
	copy(generateVEData<cl_float>(10u,3u),vec0);
	copy(generateVEData<cl_float>(10u,1u),vec1);

	Kernel k;
	{ 
		using namespace elementOperators;
		k << (vec0=generateVEConstant(0.1f,1.f,2.f));
		k << (vec1=(elementProduct(generateVEConstant(0.f,1.f,2.f),vec0)*generateVEConstant(1.f,0.f,2.f))*vec0);
	}
	k.setup();
	k.compute();

	vector<cl_float> output(10);
	copy(vec1[0], output);
	
	bool status(output[1] == 20.5);
	errorMessage(status);

	return status;
}


bool testSystemSolve()
{
	cout << "Test of \"System Solve Cramer's rule\" function..." << flush;

	VectorOfElements vecB(2);
	VectorOfElements vecX(2);
	copy(generateVEData<cl_float>(10u,2u),vecB);
	copy(generateVEData<cl_float>(10u,2u),vecX);
	
	auto matA(generateMEConstant(makeAMatr(makeAVec(4.,1.),makeAVec(1.,3.))));

	Kernel k;
	{ 
		using namespace elementOperators;
		k << (vecB=generateVEConstant(1.f,2.f));
		k << gcSolveSystem(matA,vecB,vecX);
	}
	k.setup();
	k.compute();

	vector<cl_float> output(10);
	copy(vecX[0], output);
	
	bool status(output[1] > 0.09 && output[1] < .1);
	errorMessage(status);

	return status;
}

bool testSystemSolveCG()
{
	cout << "Test of \"System Solve congugate gradient method\" function..." << flush;

	VectorOfElements vecB(2);
	VectorOfElements vecX(2);
	copy(generateVEData<cl_float>(10u,2u),vecB);
	copy(generateVEData<cl_float>(10u,2u),vecX);
	
	auto matA(generateMEConstant(makeAMatr(makeAVec(4.,1.),makeAVec(1.,3.))));

	Kernel k;
	{ 
		using namespace elementOperators;
		k << (vecB=generateVEConstant(1.f,2.f));
		k << gcSolveSystemCG(matA,vecB,vecX);
	}
	k.setup();
	k.compute();

	vector<cl_float> output(10);
	copy(vecX[0], output);
	
	bool status(output[1] > 0.09 && output[1] < .1);
	errorMessage(status);

	return status;		
}


int main()
{
	bool allTestsPassed(true);

	allTestsPassed &= testMatrixOperations();
	allTestsPassed &= testSystemSolve();
	allTestsPassed &= testSystemSolveCG();

	return allTestsPassed ? EXIT_SUCCESS : EXIT_FAILURE;
}