1 /*
2 * This file is part of qpOASES.
3 *
4 * qpOASES -- An Implementation of the Online Active Set Strategy.
5 * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka,
6 * Christian Kirches et al. All rights reserved.
7 *
8 * qpOASES is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * qpOASES 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.
16 * See the GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with qpOASES; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 *
22 */
23
24
25 /**
26 * \file testing/cpp/test_matrices2.cpp
27 * \author Hans Joachim Ferreau,Andreas Potschka, Christian Kirches
28 * \version 3.2
29 * \date 2014-2017
30 *
31 * Unit test for Matrix classes.
32 */
33
34
35 #include <stdlib.h>
36
37 #include <qpOASES.hpp>
38 #include <qpOASES/UnitTesting.hpp>
39
40
41 #include "test_qrecipe_data.hpp"
42
43
44 /** Compare deviations when performing matrix operations. */
main()45 int main( )
46 {
47 USING_NAMESPACE_QPOASES
48
49 int_t i;
50
51 real_t errH=0.0, errA=0.0;
52 real_t v[180];
53 real_t resHs[180];
54 real_t resHd[180];
55 real_t resAs[91];
56 real_t resAd[91];
57
58 /* create sparse matrices */
59 SymSparseMat *H = new SymSparseMat(180, 180, H_ir, H_jc, H_val);
60 SparseMatrix *A = new SparseMatrix(91, 180, A_ir, A_jc, A_val);
61
62 H->createDiagInfo();
63
64 real_t* H_full = H->full();
65 real_t* A_full = A->full();
66
67 //print( A_full,91,180 );
68
69
70 SymDenseMat *Hd = new SymDenseMat(180,180,180,H_full);
71 DenseMatrix *Ad = new DenseMatrix(91,180,180,A_full);
72
73 for( i=0; i<180; ++i )
74 v[i] = 2.0 * ((real_t)rand()) / ((real_t)RAND_MAX) - 1.0;
75
76 H ->times(1, 1.0, v, 180, 0.0, resHs, 180);
77 Hd->times(1, 1.0, v, 180, 0.0, resHd, 180);
78
79 A ->times(1, 1.0, v, 180, 0.0, resAs, 91);
80 Ad->times(1, 1.0, v, 180, 0.0, resAd, 91);
81
82
83 for ( i=0; i<180; ++i )
84 if ( getAbs(resHs[i] - resHd[i]) > errH)
85 errH = getAbs(resHs[i] - resHd[i]);
86
87 fprintf(stdFile, "maximum difference in H*v: %9.2e\n", errH);
88
89
90 for ( i=0; i<91; ++i )
91 if ( getAbs(resAs[i] - resAd[i]) > errA)
92 errA = getAbs(resAs[i] - resAd[i]);
93
94 fprintf(stdFile, "maximum difference in A*v: %9.2e\n", errA);
95
96 delete H;
97 delete A;
98 delete[] H_full;
99 delete[] A_full;
100 delete Hd;
101 delete Ad;
102
103
104 QPOASES_TEST_FOR_TOL( errH,1e-13 )
105 QPOASES_TEST_FOR_TOL( errA,1e-13 )
106
107 return TEST_PASSED;
108 }
109
110
111 /*
112 * end of file
113 */
114