test_matrices2.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of qpOASES.
3  *
4  * qpOASES -- An Implementation of the Online Active Set Strategy.
5  * Copyright (C) 2007-2015 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 
35 #include <stdlib.h>
36 
37 #include <qpOASES.hpp>
38 #include <qpOASES/UnitTesting.hpp>
39 
40 
41 #include "test_qrecipe_data.hpp"
42 
43 
45 int main( )
46 {
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  */
Interfaces matrix-vector operations tailored to symmetric sparse matrices.
real_t getAbs(real_t x)
int main()
Interfaces matrix-vector operations tailored to symmetric dense matrices.
#define stdFile
virtual returnValue times(int xN, real_t alpha, const real_t *x, int xLD, real_t beta, real_t *y, int yLD) const
Interfaces matrix-vector operations tailored to general dense matrices.
Interfaces matrix-vector operations tailored to general sparse matrices.
#define QPOASES_TEST_FOR_TOL(x, tol)
Definition: UnitTesting.hpp:61
#define TEST_PASSED
Definition: UnitTesting.hpp:45
#define v
returnValue times(int xN, real_t alpha, const real_t *x, int xLD, real_t beta, real_t *y, int yLD) const
double real_t
Definition: AD_test.c:10


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:35:12