Matrices.hpp
Go to the documentation of this file.
00001 /*
00002  *      This file is part of qpOASES.
00003  *
00004  *      qpOASES -- An Implementation of the Online Active Set Strategy.
00005  *      Copyright (C) 2007-2011 by Hans Joachim Ferreau, Andreas Potschka,
00006  *      Christian Kirches et al. All rights reserved.
00007  *
00008  *      qpOASES is free software; you can redistribute it and/or
00009  *      modify it under the terms of the GNU Lesser General Public
00010  *      License as published by the Free Software Foundation; either
00011  *      version 2.1 of the License, or (at your option) any later version.
00012  *
00013  *      qpOASES is distributed in the hope that it will be useful,
00014  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00016  *      See the GNU Lesser General Public License for more details.
00017  *
00018  *      You should have received a copy of the GNU Lesser General Public
00019  *      License along with qpOASES; if not, write to the Free Software
00020  *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00021  *
00022  */
00023 
00024 
00037 #ifndef QPOASES_MATRICES_HPP
00038 #define QPOASES_MATRICES_HPP
00039 
00040 
00041 #ifdef __USE_SINGLE_PRECISION__
00042 
00044         #define GEMM sgemm_
00045 
00046         #define SYR ssyr_
00047 
00048         #define SYR2 ssyr2_
00049 
00050         #define POTRF spotrf_
00051 
00052 #else
00053 
00055         #define GEMM dgemm_
00056 
00057         #define SYR  dsyr_
00058 
00059         #define SYR2 dsyr2_
00060 
00061         #define POTRF dpotrf_
00062 
00063 #endif /* __USE_SINGLE_PRECISION__ */
00064 
00065 
00066 extern "C"
00067 {
00069         void dgemm_ ( const char*, const char*, const unsigned long*, const unsigned long*, const unsigned long*,
00070                         const double*, const double*, const unsigned long*, const double*, const unsigned long*,
00071                         const double*, double*, const unsigned long* );
00073         void sgemm_ ( const char*, const char*, const unsigned long*, const unsigned long*, const unsigned long*,
00074                         const float*, const float*, const unsigned long*, const float*, const unsigned long*,
00075                         const float*, float*, const unsigned long* );
00076 
00078         void dsyr_ ( const char *, const unsigned long *, const double *, const double *,
00079                                  const unsigned long *, double *, const unsigned long *);
00081         void ssyr_ ( const char *, const unsigned long *, const float *, const float *,
00082                                  const unsigned long *, float *, const unsigned long *);
00083 
00085         void dsyr2_ ( const char *, const unsigned long *, const double *, const double *,
00086                                   const unsigned long *, const double *, const unsigned long *, double *, const unsigned long *);
00088         void ssyr2_ ( const char *, const unsigned long *, const float *, const float *,
00089                                   const unsigned long *, const float *, const unsigned long *, float *, const unsigned long *);
00090 
00092         void dpotrf_ ( const char *, const unsigned long *, double *, const unsigned long *, long * );
00094         void spotrf_ ( const char *, const unsigned long *, float *, const unsigned long *, long * );
00095 }
00096 
00097 
00098 BEGIN_NAMESPACE_QPOASES
00099 
00100 
00112 class Matrix
00113 {
00114         public:
00116                 Matrix( ) { doNotFreeMemory(); };
00117 
00119                 virtual ~Matrix( ) { };
00120 
00122                 virtual void free( ) = 0;
00123 
00126                 virtual Matrix* duplicate( ) const = 0;
00127 
00130                 virtual real_t diag(    int i                   
00131                                                                 ) const = 0;
00132 
00136                 virtual BooleanType isDiag( ) const = 0;
00137 
00140                 virtual returnValue getRow(
00141                                 int rNum,                                               
00142                                 const Indexlist* const icols,   
00143                                 real_t alpha,                                   
00144                                 real_t *row                                             
00145                                 ) const = 0;
00146 
00149                 virtual returnValue getCol(
00150                                 int cNum,                                               
00151                                 const Indexlist* const irows,   
00152                                 real_t alpha,                                   
00153                                 real_t *col                                             
00154                                 ) const = 0;
00155 
00158                 virtual returnValue times (     int xN,                                 
00159                                                                         real_t alpha,                   
00160                                                                         const real_t *x,                
00161                                                                         int xLD,                                
00162                                                                         real_t beta,                    
00163                                                                         real_t *y,                              
00164                                                                         int yLD                                 
00165                                                                         ) const = 0;
00166 
00169                 virtual returnValue transTimes (        int xN,                         
00170                                                                                         real_t alpha,           
00171                                                                                         const real_t *x,        
00172                                                                                         int xLD,                        
00173                                                                                         real_t beta,            
00174                                                                                         real_t *y,                      
00175                                                                                         int yLD                         
00176                                                                                         ) const = 0;
00177 
00180                 virtual returnValue times (     const Indexlist* const irows,   
00181                                                                         const Indexlist* const icols,   
00182                                                                         int xN,                                                 
00183                                                                         real_t alpha,                                   
00184                                                                         const real_t *x,                                
00185                                                                         int xLD,                                                
00186                                                                         real_t beta,                                    
00187                                                                         real_t *y,                                              
00188                                                                         int yLD,                                                
00189                                                                         BooleanType yCompr = BT_TRUE    
00190                                                                         ) const = 0;
00191 
00194                 virtual returnValue transTimes (        const Indexlist* const irows,   
00195                                                                                         const Indexlist* const icols,   
00196                                                                                         int xN,                                                 
00197                                                                                         real_t alpha,                                   
00198                                                                                         const real_t *x,                                
00199                                                                                         int xLD,                                                
00200                                                                                         real_t beta,                                    
00201                                                                                         real_t *y,                                              
00202                                                                                         int yLD                                                 
00203                                                                                         ) const = 0;
00204 
00208                 virtual returnValue addToDiag(  real_t alpha            
00209                                                                                 ) = 0;
00210                                                                                 
00211 
00215                 virtual returnValue print( ) const = 0;
00216 
00217 
00221                 BooleanType needToFreeMemory( ) const { return freeMemory; };
00222 
00224                 void doFreeMemory( ) { freeMemory = BT_TRUE; };
00225                 
00227                 void doNotFreeMemory( ) { freeMemory = BT_FALSE; };
00228 
00229 
00230         protected:
00231                         BooleanType freeMemory;                         
00233 };
00234 
00235 
00246 class SymmetricMatrix : public virtual Matrix
00247 {
00248         public:
00249 
00252                 virtual returnValue bilinear(
00253                                 const Indexlist* const icols,   
00254                                 int xN,                                                 
00255                                 const real_t *x,                                
00256                                 int xLD,                                                
00257                                 real_t *y,                                              
00258                                 int yLD                                                 
00259                                 ) const = 0;
00260 
00261 };
00262 
00263 
00273 class DenseMatrix : public virtual Matrix
00274 {
00275         public:
00277                 DenseMatrix( ) : nRows(0), nCols(0), leaDim(0), val(0) {};
00278 
00282                 DenseMatrix(    int m,                  
00283                                                 int n,                  
00284                                                 int lD,                 
00285                                                 real_t *v               
00286                                                 ) : nRows(m), nCols(n), leaDim(lD), val(v) {}
00287 
00288 
00290                 virtual ~DenseMatrix();
00291 
00293                 virtual void free( );
00294 
00297                 virtual Matrix *duplicate( ) const;
00298 
00301                 virtual real_t diag(    int i                   
00302                                                                 ) const;
00303 
00307                 virtual BooleanType isDiag( ) const;
00308 
00311                 virtual returnValue getRow(
00312                                 int rNum,                                               
00313                                 const Indexlist* const icols,   
00314                                 real_t alpha,                                   
00315                                 real_t *row                                             
00316                                 ) const;
00317 
00320                 virtual returnValue getCol(
00321                                 int cNum,                                               
00322                                 const Indexlist* const irows,   
00323                                 real_t alpha,                                   
00324                                 real_t *col                                             
00325                                 ) const;
00326 
00329                 returnValue times (     int xN,                                 
00330                                                         real_t alpha,                   
00331                                                         const real_t *x,                
00332                                                         int xLD,                                
00333                                                         real_t beta,                    
00334                                                         real_t *y,                              
00335                                                         int yLD                                 
00336                                                         ) const;
00337 
00340                 returnValue transTimes (        int xN,                         
00341                                                                         real_t alpha,           
00342                                                                         const real_t *x,        
00343                                                                         int xLD,                        
00344                                                                         real_t beta,            
00345                                                                         real_t *y,                      
00346                                                                         int yLD                         
00347                                                                         ) const;
00348 
00351                 virtual returnValue times (     const Indexlist* const irows,   
00352                                                                         const Indexlist* const icols,   
00353                                                                         int xN,                                                 
00354                                                                         real_t alpha,                                   
00355                                                                         const real_t *x,                                
00356                                                                         int xLD,                                                
00357                                                                         real_t beta,                                    
00358                                                                         real_t *y,                                              
00359                                                                         int yLD,                                                
00360                                                                         BooleanType yCompr = BT_TRUE    
00361                                                                         ) const;
00362 
00365                 virtual returnValue transTimes (        const Indexlist* const irows,   
00366                                                                                         const Indexlist* const icols,   
00367                                                                                         int xN,                                                 
00368                                                                                         real_t alpha,                                   
00369                                                                                         const real_t *x,                                
00370                                                                                         int xLD,                                                
00371                                                                                         real_t beta,                                    
00372                                                                                         real_t *y,                                              
00373                                                                                         int yLD                                                 
00374                                                                                         ) const;
00375 
00379                 virtual returnValue addToDiag(  real_t alpha            
00380                                                                                 );
00381 
00384                 virtual returnValue print( ) const;
00385 
00386 
00387         protected:
00388                 int nRows;                      
00389                 int nCols;                      
00390                 int leaDim;                     
00391                 real_t *val;            
00392 };
00393 
00394 
00404 class SymDenseMat : public DenseMatrix, public SymmetricMatrix
00405 {
00406         public:
00408                 SymDenseMat() : DenseMatrix() {}
00409 
00411                 SymDenseMat(    int m,                  
00412                                                 int n,                  
00413                                                 int lD,                 
00414                                                 real_t *v               
00415                                                 ) : DenseMatrix(m, n, lD, v) {}
00416                                                 
00419                 virtual Matrix *duplicate( ) const;
00420 
00423                 virtual returnValue bilinear(
00424                                 const Indexlist* const icols,   
00425                                 int xN,                                                 
00426                                 const real_t *x,                                
00427                                 int xLD,                                                
00428                                 real_t *y,                                              
00429                                 int yLD                                                 
00430                                 ) const;
00431 };
00432 
00433 
00443 class SparseMatrix : public virtual Matrix
00444 {
00445         public:
00447                 SparseMatrix();
00448 
00450                 SparseMatrix(
00451                                 long nr,                
00452                                 long nc,                
00453                                 long *r,                
00454                                 long *c,                
00455                                 real_t *v,              
00456                                 long *d = 0             
00457                                 );
00458 
00460                 SparseMatrix(
00461                                 int nr,                                 
00462                                 int nc,                                 
00463                                 int ld,                                 
00464                                 const real_t * const v  
00465                                 );
00466 
00468                 virtual ~SparseMatrix();
00469 
00471                 virtual void free( );
00472 
00475                 virtual Matrix *duplicate( ) const;
00476 
00479                 virtual real_t diag(    int i                   
00480                                                                 ) const;
00481 
00485                 virtual BooleanType isDiag( ) const;
00486 
00488                 virtual returnValue getRow (
00489                                 int rNum,                                               
00490                                 const Indexlist* const icols,   
00491                                 real_t alpha,                                   
00492                                 real_t *row                                             
00493                                 ) const;
00494 
00496                 virtual returnValue getCol (
00497                                 int cNum,                                               
00498                                 const Indexlist* const irows,   
00499                                 real_t alpha,                                   
00500                                 real_t *col                                             
00501                                 ) const;
00502 
00504                 virtual returnValue times (     int xN,                                 
00505                                                                         real_t alpha,                   
00506                                                                         const real_t *x,                
00507                                                                         int xLD,                                
00508                                                                         real_t beta,                    
00509                                                                         real_t *y,                              
00510                                                                         int yLD                                 
00511                                                                         ) const;
00512 
00514                 virtual returnValue transTimes (        int xN,                         
00515                                                                                         real_t alpha,           
00516                                                                                         const real_t *x,        
00517                                                                                         int xLD,                        
00518                                                                                         real_t beta,            
00519                                                                                         real_t *y,                      
00520                                                                                         int yLD                         
00521                                                                                         ) const;
00522 
00524                 virtual returnValue times (     const Indexlist* const irows,   
00525                                                                         const Indexlist* const icols,   
00526                                                                         int xN,                                                 
00527                                                                         real_t alpha,                                   
00528                                                                         const real_t *x,                                
00529                                                                         int xLD,                                                
00530                                                                         real_t beta,                                    
00531                                                                         real_t *y,                                              
00532                                                                         int yLD,                                                
00533                                                                         BooleanType yCompr = BT_TRUE    
00534                                                                         ) const;
00535 
00537                 virtual returnValue transTimes (        const Indexlist* const irows,   
00538                                                                                         const Indexlist* const icols,   
00539                                                                                         int xN,                                                 
00540                                                                                         real_t alpha,                                   
00541                                                                                         const real_t *x,                                
00542                                                                                         int xLD,                                                
00543                                                                                         real_t beta,                                    
00544                                                                                         real_t *y,                                              
00545                                                                                         int yLD                                                 
00546                                                                                         ) const;
00547 
00551                 virtual returnValue addToDiag(  real_t alpha            
00552                                                                                 );
00553 
00556                 long *createDiagInfo();
00557 
00560                 real_t *full() const;
00561 
00564                 virtual returnValue print( ) const;
00565 
00566 
00567         protected:
00568                 long nRows;                     
00569                 long nCols;                     
00570                 long *ir;                       
00571                 long *jc;                       
00572                 long *jd;                       
00573                 real_t *val;            
00574 };
00575 
00576 
00586 class SymSparseMat : public SymmetricMatrix, public SparseMatrix
00587 {
00588         public:
00590                 SymSparseMat() : SparseMatrix() {}
00591 
00593                 SymSparseMat(
00594                                 long nr,                
00595                                 long nc,                
00596                                 long *r,                
00597                                 long *c,                
00598                                 real_t *v,              
00599                                 long *d = 0             
00600                                 ) : SparseMatrix(nr, nc, r, c, v, d) {}
00601 
00603                 SymSparseMat(
00604                                 int nr,                                 
00605                                 int nc,                                 
00606                                 int ld,                                 
00607                                 const real_t * const v  
00608                                 ) : SparseMatrix(nr, nc, ld, v) {}
00609 
00612                 virtual Matrix *duplicate( ) const;
00613 
00614 
00617                 virtual returnValue bilinear(
00618                                 const Indexlist* const icols,   
00619                                 int xN,                                                 
00620                                 const real_t *x,                                
00621                                 int xLD,                                                
00622                                 real_t *y,                                              
00623                                 int yLD                                                 
00624                                 ) const;
00625 };
00626 
00627 
00628 END_NAMESPACE_QPOASES
00629 
00630 
00631 #endif  /* QPOASES_MATRICES_HPP */


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Thu Aug 27 2015 11:59:10