Visual Servoing Platform  version 3.0.0
vpMatrix_cholesky.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See http://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Matrix Cholesky decomposition.
32  *
33  * Authors:
34  * Filip Novotny
35  *
36  *****************************************************************************/
37 
38 #include <visp3/core/vpConfig.h>
39 
40 #include <visp3/core/vpMatrix.h>
41 #include <visp3/core/vpMath.h>
42 #include <visp3/core/vpColVector.h>
43 
44 // Exception
45 #include <visp3/core/vpException.h>
46 #include <visp3/core/vpMatrixException.h>
47 
48 // Debug trace
49 #include <visp3/core/vpDebug.h>
50 
51 #ifdef VISP_HAVE_LAPACK_C
52 extern "C" void dpotrf_ (char *uplo, int *n, double *a, int *lda, int *info);
53 extern "C" int dpotri_(char *uplo, int *n, double *a, int *lda, int *info);
54 
56  int rowNum_ = (int)this->getRows();
57  int lda = (int)rowNum_; //lda is the number of rows because we don't use a submatrix
58  int info;
59 
60  vpMatrix A = *this;
61  dpotrf_((char*)"L",&rowNum_,A.data,&lda,&info);
62 
63  if(info!=0)
64  std::cout << "cholesky:dpotrf_:error" << std::endl;
65 
66  dpotri_((char*)"L",&rowNum_,A.data,&lda,&info);
67  if(info!=0){
68  std::cout << "cholesky:dpotri_:error" << std::endl;
70  }
71 
72  for(unsigned int i=0;i<A.getRows();i++)
73  for(unsigned int j=0;j<A.getCols();j++)
74  if(i>j) A[i][j] = A[j][i];
75 
76  return A;
77 }
78 
112 vpMatrix
114 {
115 
116  if ( rowNum != colNum)
117  {
118  vpERROR_TRACE("\n\t\tCannot invert a non-square vpMatrix") ;
120  "Cannot invert a non-square vpMatrix")) ;
121  }
122  return inverseByCholeskyLapack();
123 }
124 
125 #elif !defined(VISP_BUILD_SHARED_LIBS)
126 // Work arround to avoid warning: libvisp_core.a(vpMatrixLapack.cpp.o) has no symbols
127 void dummy_vpMatrixLapack() {};
128 #endif
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:92
vpMatrix inverseByCholesky() const
#define vpERROR_TRACE
Definition: vpDebug.h:391
Type * data
Address of the first element of the data array.
Definition: vpArray2D.h:84
vpMatrix inverseByCholeskyLapack() const
unsigned int getCols() const
Return the number of columns of the 2D array.
Definition: vpArray2D.h:154
unsigned int rowNum
Number of rows in the array.
Definition: vpArray2D.h:74
unsigned int getRows() const
Return the number of rows of the 2D array.
Definition: vpArray2D.h:152
unsigned int colNum
Number of columns in the array.
Definition: vpArray2D.h:76
error that can be emited by the vpMatrix class and its derivates