roadrunner  2.6.0
Fast simulator for SBML models
SVD.h
1 //
2 // Created by Ciaran on 10/03/2021.
3 //
4 
5 #ifndef ROADRUNNER_SVD_H
6 #define ROADRUNNER_SVD_H
7 
8 #include "rr-libstruct/lsMatrix.h"
9 extern "C" {
10  // this one cost me a few hours. Name mangling causes link errors
11  #include "clapack/f2c.h" // must be included before clapack
12  #include "clapack/clapack.h"
13  #include "clapack/blaswrap.h"
14 }
15 #include <memory>
16 
17 namespace rr {
18 
30  class SVD {
31 
32  public:
33 
42  explicit SVD(ls::DoubleMatrix& matrix);
43 
48  const ls::DoubleMatrix &getSingularValues() const;
49 
54  const ls::DoubleMatrix &getLeftSingularVectors() const;
55 
60  const ls::DoubleMatrix &getRightSingularVectors() const;
61 
70  int rank(double tol = 1e-15) const;
71 
80  bool isSingular();
81 
82  private:
83 
84  void compute();
85 
86  ls::DoubleMatrix inputMatrix_;
87  std::unique_ptr<ls::DoubleMatrix> inputMatrixTranspose_ = nullptr;
88  integer nRows_;
89  integer nCols_;
90  integer lda_;
91  integer ldu_;
92  integer ldvt_;
93 
94  ls::DoubleMatrix singularValues_;
95  ls::DoubleMatrix leftSingularVectors_;
96  ls::DoubleMatrix rightSingularVectors_;
97 
98  };
99 }
100 
101 
102 #endif //ROADRUNNER_SVD_H
The routine computes the singular value decomposition (SVD) of a real m-by-n matrix.
Definition: SVD.h:30
SVD(ls::DoubleMatrix &matrix)
constructor for SVD
Definition: SVD.cpp:13
const ls::DoubleMatrix & getSingularValues() const
returns the singular values computed for input matrix
Definition: SVD.cpp:76
const ls::DoubleMatrix & getLeftSingularVectors() const
returns left singular vectors where columns are the left vectors
Definition: SVD.cpp:80
const ls::DoubleMatrix & getRightSingularVectors() const
returns right singular vectors where rows are the right vectors
Definition: SVD.cpp:84
bool isSingular()
return true when the input matrix is singular.
Definition: SVD.cpp:101
int rank(double tol=1e-15) const
estimates the rank of the matrix by counting non 0 singular values.
Definition: SVD.cpp:88