qpOASES-3.0beta/include/qpOASES/Matrices.hpp
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-2011 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 
37 #ifndef QPOASES_MATRICES_HPP
38 #define QPOASES_MATRICES_HPP
39 
40 
41 #ifdef __USE_SINGLE_PRECISION__
42 
44  #define GEMM sgemm_
45 
46  #define SYR ssyr_
47 
48  #define SYR2 ssyr2_
49 
50  #define POTRF spotrf_
51 
52 #else
53 
55  #define GEMM dgemm_
56 
57  #define SYR dsyr_
58 
59  #define SYR2 dsyr2_
60 
61  #define POTRF dpotrf_
62 
63 #endif /* __USE_SINGLE_PRECISION__ */
64 
65 
66 extern "C"
67 {
69  void dgemm_ ( const char*, const char*, const unsigned long*, const unsigned long*, const unsigned long*,
70  const double*, const double*, const unsigned long*, const double*, const unsigned long*,
71  const double*, double*, const unsigned long* );
73  void sgemm_ ( const char*, const char*, const unsigned long*, const unsigned long*, const unsigned long*,
74  const float*, const float*, const unsigned long*, const float*, const unsigned long*,
75  const float*, float*, const unsigned long* );
76 
78  void dsyr_ ( const char *, const unsigned long *, const double *, const double *,
79  const unsigned long *, double *, const unsigned long *);
81  void ssyr_ ( const char *, const unsigned long *, const float *, const float *,
82  const unsigned long *, float *, const unsigned long *);
83 
85  void dsyr2_ ( const char *, const unsigned long *, const double *, const double *,
86  const unsigned long *, const double *, const unsigned long *, double *, const unsigned long *);
88  void ssyr2_ ( const char *, const unsigned long *, const float *, const float *,
89  const unsigned long *, const float *, const unsigned long *, float *, const unsigned long *);
90 
92  void dpotrf_ ( const char *, const unsigned long *, double *, const unsigned long *, long * );
94  void spotrf_ ( const char *, const unsigned long *, float *, const unsigned long *, long * );
95 }
96 
97 
99 
100 
112 class Matrix
113 {
114  public:
117 
119  virtual ~Matrix( ) { };
120 
122  virtual void free( ) = 0;
123 
126  virtual Matrix* duplicate( ) const = 0;
127 
130  virtual real_t diag( int i
131  ) const = 0;
132 
136  virtual BooleanType isDiag( ) const = 0;
137 
140  virtual returnValue getRow(
141  int rNum,
142  const Indexlist* const icols,
143  real_t alpha,
144  real_t *row
145  ) const = 0;
146 
149  virtual returnValue getCol(
150  int cNum,
151  const Indexlist* const irows,
152  real_t alpha,
153  real_t *col
154  ) const = 0;
155 
158  virtual returnValue times ( int xN,
159  real_t alpha,
160  const real_t *x,
161  int xLD,
162  real_t beta,
163  real_t *y,
164  int yLD
165  ) const = 0;
166 
169  virtual returnValue transTimes ( int xN,
170  real_t alpha,
171  const real_t *x,
172  int xLD,
173  real_t beta,
174  real_t *y,
175  int yLD
176  ) const = 0;
177 
180  virtual returnValue times ( const Indexlist* const irows,
181  const Indexlist* const icols,
182  int xN,
183  real_t alpha,
184  const real_t *x,
185  int xLD,
186  real_t beta,
187  real_t *y,
188  int yLD,
189  BooleanType yCompr = BT_TRUE
190  ) const = 0;
191 
194  virtual returnValue transTimes ( const Indexlist* const irows,
195  const Indexlist* const icols,
196  int xN,
197  real_t alpha,
198  const real_t *x,
199  int xLD,
200  real_t beta,
201  real_t *y,
202  int yLD
203  ) const = 0;
204 
208  virtual returnValue addToDiag( real_t alpha
209  ) = 0;
210 
211 
215  virtual returnValue print( ) const = 0;
216 
217 
222 
225 
228 
229 
230  protected:
233 };
234 
235 
246 class SymmetricMatrix : public virtual Matrix
247 {
248  public:
249 
252  virtual returnValue bilinear(
253  const Indexlist* const icols,
254  int xN,
255  const real_t *x,
256  int xLD,
257  real_t *y,
258  int yLD
259  ) const = 0;
260 
261 };
262 
263 
273 class DenseMatrix : public virtual Matrix
274 {
275  public:
277  DenseMatrix( ) : nRows(0), nCols(0), leaDim(0), val(0) {};
278 
282  DenseMatrix( int m,
283  int n,
284  int lD,
285  real_t *v
286  ) : nRows(m), nCols(n), leaDim(lD), val(v) {}
287 
288 
290  virtual ~DenseMatrix();
291 
293  virtual void free( );
294 
297  virtual Matrix *duplicate( ) const;
298 
301  virtual real_t diag( int i
302  ) const;
303 
307  virtual BooleanType isDiag( ) const;
308 
311  virtual returnValue getRow(
312  int rNum,
313  const Indexlist* const icols,
314  real_t alpha,
315  real_t *row
316  ) const;
317 
320  virtual returnValue getCol(
321  int cNum,
322  const Indexlist* const irows,
323  real_t alpha,
324  real_t *col
325  ) const;
326 
329  returnValue times ( int xN,
330  real_t alpha,
331  const real_t *x,
332  int xLD,
333  real_t beta,
334  real_t *y,
335  int yLD
336  ) const;
337 
340  returnValue transTimes ( int xN,
341  real_t alpha,
342  const real_t *x,
343  int xLD,
344  real_t beta,
345  real_t *y,
346  int yLD
347  ) const;
348 
351  virtual returnValue times ( const Indexlist* const irows,
352  const Indexlist* const icols,
353  int xN,
354  real_t alpha,
355  const real_t *x,
356  int xLD,
357  real_t beta,
358  real_t *y,
359  int yLD,
360  BooleanType yCompr = BT_TRUE
361  ) const;
362 
365  virtual returnValue transTimes ( const Indexlist* const irows,
366  const Indexlist* const icols,
367  int xN,
368  real_t alpha,
369  const real_t *x,
370  int xLD,
371  real_t beta,
372  real_t *y,
373  int yLD
374  ) const;
375 
379  virtual returnValue addToDiag( real_t alpha
380  );
381 
384  virtual returnValue print( ) const;
385 
386 
387  protected:
388  int nRows;
389  int nCols;
390  int leaDim;
392 };
393 
394 
405 {
406  public:
409 
411  SymDenseMat( int m,
412  int n,
413  int lD,
414  real_t *v
415  ) : DenseMatrix(m, n, lD, v) {}
416 
419  virtual Matrix *duplicate( ) const;
420 
423  virtual returnValue bilinear(
424  const Indexlist* const icols,
425  int xN,
426  const real_t *x,
427  int xLD,
428  real_t *y,
429  int yLD
430  ) const;
431 };
432 
433 
443 class SparseMatrix : public virtual Matrix
444 {
445  public:
447  SparseMatrix();
448 
450  SparseMatrix(
451  long nr,
452  long nc,
453  long *r,
454  long *c,
455  real_t *v,
456  long *d = 0
457  );
458 
460  SparseMatrix(
461  int nr,
462  int nc,
463  int ld,
464  const real_t * const v
465  );
466 
468  virtual ~SparseMatrix();
469 
471  virtual void free( );
472 
475  virtual Matrix *duplicate( ) const;
476 
479  virtual real_t diag( int i
480  ) const;
481 
485  virtual BooleanType isDiag( ) const;
486 
488  virtual returnValue getRow (
489  int rNum,
490  const Indexlist* const icols,
491  real_t alpha,
492  real_t *row
493  ) const;
494 
496  virtual returnValue getCol (
497  int cNum,
498  const Indexlist* const irows,
499  real_t alpha,
500  real_t *col
501  ) const;
502 
504  virtual returnValue times ( int xN,
505  real_t alpha,
506  const real_t *x,
507  int xLD,
508  real_t beta,
509  real_t *y,
510  int yLD
511  ) const;
512 
514  virtual returnValue transTimes ( int xN,
515  real_t alpha,
516  const real_t *x,
517  int xLD,
518  real_t beta,
519  real_t *y,
520  int yLD
521  ) const;
522 
524  virtual returnValue times ( const Indexlist* const irows,
525  const Indexlist* const icols,
526  int xN,
527  real_t alpha,
528  const real_t *x,
529  int xLD,
530  real_t beta,
531  real_t *y,
532  int yLD,
533  BooleanType yCompr = BT_TRUE
534  ) const;
535 
537  virtual returnValue transTimes ( const Indexlist* const irows,
538  const Indexlist* const icols,
539  int xN,
540  real_t alpha,
541  const real_t *x,
542  int xLD,
543  real_t beta,
544  real_t *y,
545  int yLD
546  ) const;
547 
551  virtual returnValue addToDiag( real_t alpha
552  );
553 
556  long *createDiagInfo();
557 
560  real_t *full() const;
561 
564  virtual returnValue print( ) const;
565 
566 
567  protected:
568  long nRows;
569  long nCols;
570  long *ir;
571  long *jc;
572  long *jd;
574 };
575 
576 
587 {
588  public:
591 
594  long nr,
595  long nc,
596  long *r,
597  long *c,
598  real_t *v,
599  long *d = 0
600  ) : SparseMatrix(nr, nc, r, c, v, d) {}
601 
604  int nr,
605  int nc,
606  int ld,
607  const real_t * const v
608  ) : SparseMatrix(nr, nc, ld, v) {}
609 
612  virtual Matrix *duplicate( ) const;
613 
614 
617  virtual returnValue bilinear(
618  const Indexlist* const icols,
619  int xN,
620  const real_t *x,
621  int xLD,
622  real_t *y,
623  int yLD
624  ) const;
625 };
626 
627 
629 
630 
631 #endif /* QPOASES_MATRICES_HPP */
virtual returnValue getCol(int cNum, const Indexlist *const irows, real_t alpha, real_t *col) const =0
Interfaces matrix-vector operations tailored to symmetric sparse matrices.
void dgemm_(const char *, const char *, const unsigned long *, const unsigned long *, const unsigned long *, const double *, const double *, const unsigned long *, const double *, const unsigned long *, const double *, double *, const unsigned long *)
virtual real_t * full() const =0
SymDenseMat(int m, int n, int lD, real_t *v)
virtual returnValue print() const =0
virtual Matrix * duplicate() const =0
void sgemm_(const char *, const char *, const unsigned long *, const unsigned long *, const unsigned long *, const float *, const float *, const unsigned long *, const float *, const unsigned long *, const float *, float *, const unsigned long *)
virtual BooleanType isDiag() const =0
void dsyr_(const char *, const unsigned long *, const double *, const double *, const unsigned long *, double *, const unsigned long *)
Allows to pass back messages to the calling function.
DenseMatrix(int m, int n, int lD, real_t *v)
Interfaces matrix-vector operations tailored to symmetric dense matrices.
virtual returnValue transTimes(int xN, real_t alpha, const real_t *x, int xLD, real_t beta, real_t *y, int yLD) const =0
void ssyr2_(const char *, const unsigned long *, const float *, const float *, const unsigned long *, const float *, const unsigned long *, float *, const unsigned long *)
Interfaces matrix-vector operations tailored to general dense matrices.
void dpotrf_(const char *, const unsigned long *, double *, const unsigned long *, long *)
void dsyr2_(const char *, const unsigned long *, const double *, const double *, const unsigned long *, const double *, const unsigned long *, double *, const unsigned long *)
virtual returnValue times(int xN, real_t alpha, const real_t *x, int xLD, real_t beta, real_t *y, int yLD) const =0
Interfaces matrix-vector operations tailored to general sparse matrices.
virtual void free()=0
Abstract base class for interfacing tailored matrix-vector operations.
#define v
BooleanType needToFreeMemory() const
#define BT_TRUE
Definition: acado_types.hpp:47
virtual real_t diag(int i) const =0
RowXpr row(Index i)
Definition: BlockMethods.h:725
void spotrf_(const char *, const unsigned long *, float *, const unsigned long *, long *)
SymSparseMat(long nr, long nc, long *r, long *c, real_t *v, long *d=0)
virtual returnValue addToDiag(real_t alpha)=0
#define BT_FALSE
Definition: acado_types.hpp:49
ColXpr col(Index i)
Definition: BlockMethods.h:708
double real_t
Definition: AD_test.c:10
virtual returnValue getRow(int rNum, const Indexlist *const icols, real_t alpha, real_t *row) const =0
void ssyr_(const char *, const unsigned long *, const float *, const float *, const unsigned long *, float *, const unsigned long *)
SymSparseMat(int nr, int nc, int ld, const real_t *const v)
Abstract base class for interfacing matrix-vector operations tailored to symmetric matrices...


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