algebra.h
Go to the documentation of this file.
1 #ifndef ALGEBRAH
2 
13 #include "basic_algebra.h"
14 
15 #if !defined(_LAPACK) && !defined(_GSL)
16  #error CuikSuite requires LAPACK or GSL
17 #endif
18 
19 #ifdef _GSL
20  #include <gsl/gsl_linalg.h>
21 
37  typedef struct {
38  unsigned int nr;
39  unsigned int nc;
41  double *Ab;
42  double *bb;
44  gsl_matrix_view A;
45  gsl_vector_view b;
47  gsl_matrix *V;
48  gsl_vector *S;
49  gsl_vector *tmp;
52  gsl_matrix_view VT;
53  gsl_matrix_view UT;
54  gsl_vector_view ST;
56  gsl_vector *w;
58  } TNewton;
59 
68  typedef struct {
69  unsigned int nr;
70  unsigned int nc;
72  double *Ab;
73  double *bb;
74  double *xb;
76  gsl_matrix_view A;
77  gsl_vector_view b;
78  gsl_vector_view x;
80  gsl_permutation *p;
82  gsl_vector *tau;
84  gsl_vector *res;
87  } TLinearSystem;
88 #endif
89 
90 #ifdef _LAPACK
91  #ifdef _LAPACKE
92  #include <lapacke.h>
93  #else
94  /* assuming clapack */
95  #include <clapack.h>
96  #endif
97 
112  typedef struct {
113  int nr;
114  int nc;
116  double *Ab;
117  double *bb;
119  double *s;
121  int lwork;
122  double *work;
123  } TNewton;
124 
133  typedef struct {
134  int nr;
135  int nc;
137  double *Ab;
138  double *bb;
139  double *xb;
141  int *p;
143  int lwork;
144  double *work;
146  } TLinearSystem;
147 #endif
148 
149 
150 /*******************************************************************************/
151 /* The functions below have different implemenatation depending on the helper */
152 /* library being used (gsl, eigen, etc). In other words, these are the */
153 /* functions to re-implement to change to another helper library. */
154 
166 int MatrixDeterminantSgn(double epsilon,unsigned int n,double *A);
167 
181 double MatrixDeterminant(unsigned int n,double *A);
182 
201 unsigned int FindRank(double epsilon,unsigned int nr,unsigned int nc,double *mT);
202 
224 unsigned int FindKernel(unsigned int nr,unsigned int nc,double *mT,
225  unsigned int dof,boolean check,double epsilon,double **T);
226 
260 unsigned int FindKernelAndIndependentRows(unsigned int nr,unsigned int nc,double *mT,
261  unsigned int dof,double epsilon,boolean *singular,
262  boolean **IR,double **T);
263 
277 void InitNewton(unsigned int nr,unsigned int nc,TNewton *n);
278 
292 double *GetNewtonMatrixBuffer(TNewton *n);
293 
294 
304 double *GetNewtonRHBuffer(TNewton *n);
305 
318 void NewtonSetMatrix(unsigned int i,unsigned int j,double v,TNewton *n);
319 
331 void NewtonSetRH(unsigned int i,double v,TNewton *n);
332 
333 
356 int NewtonStep(double nullSingularValue,double *x,double *dif,
357  TNewton *n);
358 
369 double NewtonGetResult(unsigned int i,TNewton *n);
370 
378 void DeleteNewton(TNewton *n);
379 
389 void InitLS(unsigned int nr,unsigned int nc,TLinearSystem *ls);
390 
404 double *GetLSMatrixBuffer(TLinearSystem *ls);
405 
415 double *GetLSRHBuffer(TLinearSystem *ls);
416 
426 double *GetLSSolutionBuffer(TLinearSystem *ls);
427 
438 void LSSetMatrix(unsigned int i,unsigned int j,double v,TLinearSystem *ls);
439 
449 void LSSetRH(unsigned int i,double v,TLinearSystem *ls);
450 
451 
462 int LSSolve(TLinearSystem *ls);
463 
471 void DeleteLS(TLinearSystem *ls);
472 
473 #endif
474 
475 #ifdef _LAPACK
476 
477 
478 
479 #endif
int MatrixDeterminantSgn(double epsilon, unsigned int n, double *A)
Sign of the determinant of a matrix.
void LSSetRH(unsigned int i, double v, TLinearSystem *ls)
Defines the vector being used in a linear system.
Definition: algebra.c:1166
double * GetLSMatrixBuffer(TLinearSystem *ls)
Buffer to store the A matrix.
Definition: algebra.c:1146
double * GetNewtonRHBuffer(TNewton *n)
Buffer to store the Newton right hand.
Definition: algebra.c:1131
double MatrixDeterminant(unsigned int n, double *A)
Determinant of a matrix.
unsigned int FindKernel(unsigned int nr, unsigned int nc, double *mT, unsigned int dof, boolean check, double epsilon, double **T)
Computes the kernel of a matrix.
Definition: algebra.c:1098
unsigned int FindKernelAndIndependentRows(unsigned int nr, unsigned int nc, double *mT, unsigned int dof, double epsilon, boolean *singular, boolean **IR, double **T)
Computes the kernel of a matrix and determines the independent rows of this matrix.
Definition: algebra.c:1112
double * GetNewtonMatrixBuffer(TNewton *n)
Buffer to store the Newton matrix.
Definition: algebra.c:1126
double * GetLSRHBuffer(TLinearSystem *ls)
Buffer to store the linear system right hand (RH).
Definition: algebra.c:1151
int NewtonStep(double nullSingularValue, double *x, double *dif, TNewton *n)
One step in a Newton iteration.
double * GetLSSolutionBuffer(TLinearSystem *ls)
Buffer to store the linear system solution.
Definition: algebra.c:1156
void NewtonSetRH(unsigned int i, double v, TNewton *n)
Defines the vector being used in a Newton step.
Definition: algebra.c:1141
void LSSetMatrix(unsigned int i, unsigned int j, double v, TLinearSystem *ls)
Defines the matrix being used in a linear system.
Definition: algebra.c:1161
void DeleteNewton(TNewton *n)
Releases a Newton structure.
double NewtonGetResult(unsigned int i, TNewton *n)
Gets the vector resulting from a Newton step.
void InitLS(unsigned int nr, unsigned int nc, TLinearSystem *ls)
Defines a linear system structure.
unsigned int FindRank(double epsilon, unsigned int nr, unsigned int nc, double *mT)
Determines the row-rank of a matrix.
Definition: algebra.c:1084
void DeleteLS(TLinearSystem *ls)
Releases a linear system structure.
int LSSolve(TLinearSystem *ls)
Solves the linear sytem.
void NewtonSetMatrix(unsigned int i, unsigned int j, double v, TNewton *n)
Defines the matrix being used in a Newton step.
Definition: algebra.c:1136
void InitNewton(unsigned int nr, unsigned int nc, TNewton *n)
Defines a Newton structure.