gstlearn  0.3.3
CCC
LinkMatrixSparse.cpp File Reference
#include "Matrix/LinkMatrixSparse.hpp"
#include "Basic/AStringable.hpp"
#include "Basic/Utilities.hpp"
#include "Basic/VectorHelper.hpp"
#include "Basic/File.hpp"
#include "Basic/String.hpp"
#include "Basic/OptDbg.hpp"
#include "geoslib_old_f.h"
#include <set>
#include "csparse_d.h"
#include "csparse_f.h"

Macros

#define MAX_NEIGH   100
 
#define XCR(ilevel, i)   (xcr[(ilevel) * ncur + (i)])
 
#define RHS(ilevel, i)   (rhs[(ilevel) * ncur + (i)])
 
#define MAT(i, j)   (mat[(i) * n + (j)])
 
#define DEBUG   0
 

Functions

cs * cs_spalloc2 (int m, int n, int nzmax, int values, int triplet)
 
cs * cs_spfree2 (cs *A)
 TODO : cs_*2 functions to be removed (encapsulation) More...
 
int cs_entry2 (cs *T, int i, int j, double x)
 
cs * cs_triplet2 (const cs *T)
 
cs * cs_transpose2 (const cs *A, int values)
 
cs * cs_multiply2 (const cs *A, const cs *B)
 
int cs_print2 (const cs *A, int brief)
 
void cs_force_dimension (cs *T, int nrow, int ncol)
 
cs * cs_diag (VectorDouble diag, double tol)
 
cs * cs_prod_norm_diagonal (int mode, cs *B, VectorDouble diag)
 
cs * cs_arrays_to_sparse (int n, int nrow, int ncol, const double *rows, const double *cols, const double *vals)
 
cs * cs_vectors_to_sparse (int nrow, int ncol, const VectorDouble &rows, const VectorDouble &cols, const VectorDouble &values)
 
cs * cs_invert (const cs *A, int order, double epsilon)
 
VectorInt cs_color_coding (cs *Q, int start, int *ncols)
 
cs * cs_extract_submatrix_by_color (cs *C, const VectorInt &colors, int ref_color, int row_ok, int col_ok)
 
int qchol_cholesky (int verbose, QChol *QC)
 
void cs_multigrid_params (cs_MGS *mgs, int flag_cg, int type_coarse, int ngc, int nmg, int ngs, double tolcg, double tolnmg)
 
cs_MGScs_multigrid_manage (cs_MGS *mgs, int mode, int nlevels, int path_type)
 
void cs_multigrid_print (cs_MGS *mgs)
 
int cs_multigrid_get_nlevels (cs_MGS *mgs)
 
void cs_multigrid_coarse2fine (cs_MGS *mgs, double *z, double *work)
 
int cs_multigrid_setup (cs_MGS *mgs, QChol *qctt, int flag_sel, int verbose, double **sel_arg)
 
int cs_scale (cs *A)
 
void cs_chol_invert (QChol *qctt, double *xcr, double *rhs, double *work)
 
void cs_chol_simulate (QChol *qctt, double *simu, double *work)
 
int cs_multigrid_process (cs_MGS *mgs, QChol *qctt, int verbose, double *x0, double *b, double *work)
 
Triplet csToTriplet (const cs *A, bool flagFrom1)
 
String toStringDim (const String &title, const cs *A)
 
String toStringRange (const String &title, const cs *C)
 
bool cs_isSymmetric (const cs *A, bool verbose, bool detail)
 
bool cs_isDiagonalDominant (cs *A, bool verbose, bool detail)
 
bool cs_isDefinitePositive (cs *A, bool verbose)
 
void cs_sparse_to_triplet (const cs *A, int flag_from_1, int *number, int **cols, int **rows, double **vals)
 
cs * cs_extract_submatrix (cs *C, int row_from, int row_length, int col_from, int col_length)
 
cs * cs_extract_submatrix_by_ranks (cs *C, int *rank_rows, int *rank_cols)
 
int cs_get_nrow (const cs *A)
 
int cs_get_ncol (const cs *A)
 
int cs_get_ncell (const cs *A)
 
void cs_print_dim (const char *title, const cs *A)
 
void cs_print_range (const char *title, const cs *C)
 
cs * cs_eye (int number, double value)
 
cs * cs_extract_diag (cs *C, int mode)
 
double * csd_extract_diag (cs *C, int mode)
 
VectorDouble csd_extract_diag_VD (cs *C, int mode)
 
void cs_diag_suppress (cs *C)
 
int cs_sort_i (cs *C)
 
void cs_rowcol (const cs *A, int *nrows, int *ncols, int *count, double *percent)
 
void cs_print_nice (const char *title, const cs *A, int maxrow, int maxcol)
 
void cs_print_only (const char *title, const cs *A, int nlimit)
 
void cs_print_short (const char *title, const cs *L, int nmax)
 
cs * cs_eye_tab (int number, double *values)
 
cs * cs_multiply_and_release (cs *b1, cs *b2, int flag_release)
 
cs * cs_add_and_release (cs *b1, cs *b2, double alpha, double beta, int flag_release)
 
cs * cs_duplicate (const cs *b1)
 
cs * cs_prod_norm_and_release (cs *b1, cs *lambda, int flag_release)
 
double cs_maxsumabscol (const cs *A)
 
double * cs_col_sumrow (const cs *A, int *ncol, int *nrow)
 
void cs_vecmult (const cs *A, int nout, const double *x, double *y)
 
void cs_tmulvec (const cs *A, int nout, const double *x, double *y)
 
void cs_mulvec (const cs *A, int nout, const double *x, double *y)
 
cs * cs_normalize_by_diag_and_release (cs *Q, int flag_release)
 
cs * cs_matvecR (const cs *A, double *x, int oper)
 
cs * cs_matvecL (const cs *A, double *x, int oper)
 
cs * cs_matvecnorm (const cs *A, const double *x, int oper)
 
void cs_matvecnorm_inplace (cs *A, const double *x, int oper)
 
int cs_coarsening (cs *Q, int type, int **indCo_ret, cs **L_ret)
 
cs * cs_interpolate (cs *AA, cs *Lt, int *Co)
 
cs * cs_prod_norm (int mode, cs *A, cs *B)
 
cs * cs_prod_norm_single (int mode, cs *B)
 
cs * cs_triangle (cs *A, int flag_upper, int flag_diag)
 
int cs_lsolve_lowtri (const cs *L, const double *x, double *y)
 
int cs_lsolve_uptri (const cs *L, const double *x, double *y)
 
void cs_mulvec_uptri (const cs *A, int nout, const double *x, double *y, int flag_diag)
 
void cs_mulvec_lowtri (const cs *A, int nout, const double *x, double *y, int flag_diag)
 
cs * cs_compress (cs *A)
 
void cs_keypair (const char *key, cs *A, int flag_from_1)
 
void cs_print_file (const char *radix, int rank, cs *A)
 
bool cs_exist (const cs *A, int row, int col)
 
double cs_get_value (const cs *A, int row, int col)
 
void cs_set_value (const cs *A, int row, int col, double value)
 
void cs_add_value (const cs *A, int row, int col, double value)
 
void cs_add_cste (cs *A, double value)
 
void cs_set_cste (cs *A, double value)
 
double * cs_toArray (const cs *A)
 
int cs_nnz (const cs *A)
 
cs * cs_strip (cs *A, double eps, int hypothesis, bool verbose)
 
bool cs_are_same (const cs *A, const cs *B, double tol)
 

Macro Definition Documentation

◆ DEBUG

#define DEBUG   0

◆ MAT

#define MAT (   i,
 
)    (mat[(i) * n + (j)])

◆ MAX_NEIGH

#define MAX_NEIGH   100

◆ RHS

#define RHS (   ilevel,
 
)    (rhs[(ilevel) * ncur + (i)])

◆ XCR

#define XCR (   ilevel,
 
)    (xcr[(ilevel) * ncur + (i)])

Function Documentation

◆ cs_add_and_release()

cs* cs_add_and_release ( cs *  b1,
cs *  b2,
double  alpha,
double  beta,
int  flag_release 
)

◆ cs_add_cste()

void cs_add_cste ( cs *  A,
double  value 
)

◆ cs_add_value()

void cs_add_value ( const cs *  A,
int  row,
int  col,
double  value 
)

◆ cs_are_same()

bool cs_are_same ( const cs *  A,
const cs *  B,
double  tol 
)

◆ cs_arrays_to_sparse()

cs* cs_arrays_to_sparse ( int  n,
int  nrow,
int  ncol,
const double *  rows,
const double *  cols,
const double *  vals 
)

◆ cs_chol_invert()

void cs_chol_invert ( QChol qctt,
double *  xcr,
double *  rhs,
double *  work 
)

Inversion using Cholesky

Parameters
[in]qcttQchol structure
[in,out]xcrCurrent vector
[in]rhsCurrent R.H.S. vector
[out]workWorking array

◆ cs_chol_simulate()

void cs_chol_simulate ( QChol qctt,
double *  simu,
double *  work 
)

Simulate using Cholesky

Parameters
[in]qcttQchol structure
[out]simuSimulated array
[out]workWorking array

◆ cs_coarsening()

int cs_coarsening ( cs *  Q,
int  type,
int **  indCo_ret,
cs **  L_ret 
)

◆ cs_col_sumrow()

double* cs_col_sumrow ( const cs *  A,
int *  ncol,
int *  nrow 
)

◆ cs_color_coding()

VectorInt cs_color_coding ( cs *  Q,
int  start,
int *  ncols 
)

Creating the color coding for mesh nodes

Returns
Error return code
Parameters
[in]Qcs structure
[in]startStarting value for colors ranking (usually 0 or 1)
[out]ncolsNumber of colors

◆ cs_compress()

cs* cs_compress ( cs *  A)

◆ cs_diag()

cs* cs_diag ( VectorDouble  diag,
double  tol 
)

◆ cs_diag_suppress()

void cs_diag_suppress ( cs *  C)

◆ cs_duplicate()

cs* cs_duplicate ( const cs *  b1)

◆ cs_entry2()

int cs_entry2 ( cs *  T,
int  i,
int  j,
double  x 
)

◆ cs_exist()

bool cs_exist ( const cs *  A,
int  row,
int  col 
)

◆ cs_extract_diag()

cs* cs_extract_diag ( cs *  C,
int  mode 
)

◆ cs_extract_submatrix()

cs* cs_extract_submatrix ( cs *  C,
int  row_from,
int  row_length,
int  col_from,
int  col_length 
)

◆ cs_extract_submatrix_by_color()

cs* cs_extract_submatrix_by_color ( cs *  C,
const VectorInt colors,
int  ref_color,
int  row_ok,
int  col_ok 
)

◆ cs_extract_submatrix_by_ranks()

cs* cs_extract_submatrix_by_ranks ( cs *  C,
int *  rank_rows,
int *  rank_cols 
)

◆ cs_eye()

cs* cs_eye ( int  number,
double  value 
)

◆ cs_eye_tab()

cs* cs_eye_tab ( int  number,
double *  values 
)

◆ cs_force_dimension()

void cs_force_dimension ( cs *  T,
int  nrow,
int  ncol 
)

◆ cs_get_ncell()

int cs_get_ncell ( const cs *  A)

◆ cs_get_ncol()

int cs_get_ncol ( const cs *  A)

◆ cs_get_nrow()

int cs_get_nrow ( const cs *  A)

◆ cs_get_value()

double cs_get_value ( const cs *  A,
int  row,
int  col 
)

◆ cs_interpolate()

cs* cs_interpolate ( cs *  AA,
cs *  Lt,
int *  Co 
)

◆ cs_invert()

cs* cs_invert ( const cs *  A,
int  order,
double  epsilon 
)

◆ cs_isDefinitePositive()

bool cs_isDefinitePositive ( cs *  A,
bool  verbose 
)

◆ cs_isDiagonalDominant()

bool cs_isDiagonalDominant ( cs *  A,
bool  verbose,
bool  detail 
)

◆ cs_isSymmetric()

bool cs_isSymmetric ( const cs *  A,
bool  verbose,
bool  detail 
)

◆ cs_keypair()

void cs_keypair ( const char *  key,
cs *  A,
int  flag_from_1 
)

◆ cs_lsolve_lowtri()

int cs_lsolve_lowtri ( const cs *  L,
const double *  x,
double *  y 
)

◆ cs_lsolve_uptri()

int cs_lsolve_uptri ( const cs *  L,
const double *  x,
double *  y 
)

◆ cs_matvecL()

cs* cs_matvecL ( const cs *  A,
double *  x,
int  oper 
)

◆ cs_matvecnorm()

cs* cs_matvecnorm ( const cs *  A,
const double *  x,
int  oper 
)

◆ cs_matvecnorm_inplace()

void cs_matvecnorm_inplace ( cs *  A,
const double *  x,
int  oper 
)

◆ cs_matvecR()

cs* cs_matvecR ( const cs *  A,
double *  x,
int  oper 
)

◆ cs_maxsumabscol()

double cs_maxsumabscol ( const cs *  A)

Compute the max along the lines of the sum of the absolute values along the columns

◆ cs_multigrid_coarse2fine()

void cs_multigrid_coarse2fine ( cs_MGS mgs,
double *  z,
double *  work 
)

Convert results from coarsest to final scale

Parameters
[in]mgscs_MGS structure
[in,out]zInput vector
[out]workWorking array
Remarks
Arguments 'z' and 'work' maust be dimensioned to the finest size

◆ cs_multigrid_get_nlevels()

int cs_multigrid_get_nlevels ( cs_MGS mgs)

Returns the number of multigrid levels

Parameters
[in]mgscs_MGS structure

◆ cs_multigrid_manage()

cs_MGS* cs_multigrid_manage ( cs_MGS mgs,
int  mode,
int  nlevels,
int  path_type 
)

Allocate the structure for the multigrid manipulation

Parameters
[in]mgscs_MGS structure
[in]mode1 for allocation; -1 for deallocation
[in]nlevelsNumber of levels of the multigrid (only for mode > 0)
[in]path_typeType of the Path (1:V; 2:W, 3:F) (only for mode > 0)

◆ cs_multigrid_params()

void cs_multigrid_params ( cs_MGS mgs,
int  flag_cg,
int  type_coarse,
int  ngc,
int  nmg,
int  ngs,
double  tolcg,
double  tolnmg 
)

Define the parameters for the multigrid manipulation

Parameters
[in]mgscs_MGS structure
[in]flag_cg1 for Conjugate-Gradient use; 0 otherwise
[in]type_coarseType of coarsening algorithm
[in]ngcMaximum number of Conjugate-Gradient iterations
[in]nmgMaximum number of mutligrid iterations
[in]ngsNumber of Gauss-Siedel relaxation cycles
[in]tolcgTolerance for the Conjugate-Gradient algorithm
[in]tolnmgTolerance for the Multigrid algorithm

◆ cs_multigrid_print()

void cs_multigrid_print ( cs_MGS mgs)

Print the cs_MGS structure

Parameters
[in]mgscs_MGS structure

◆ cs_multigrid_process()

int cs_multigrid_process ( cs_MGS mgs,
QChol qctt,
int  verbose,
double *  x0,
double *  b,
double *  work 
)

Perform the multigrid kriging

Returns
Error return code
Parameters
[in]mgscs_MGS structure
[in]qcttQChol matrix of the upper level
[in]verboseVerbose flag
[in]x0Input vector
[in]bR.H.S. vector
[out]workWorking array

◆ cs_multigrid_setup()

int cs_multigrid_setup ( cs_MGS mgs,
QChol qctt,
int  flag_sel,
int  verbose,
double **  sel_arg 
)

Setup the Multigrid system

Returns
Error return code
Parameters
[in]mgscs_MGS structure
[in]qcttQChol matrix of the upper level
[in]flag_selIf 1, an output selection is created
[in]verboseVerbose flag
[out]sel_argVector of selection (in double as used in db)

◆ cs_multiply2()

cs* cs_multiply2 ( const cs *  A,
const cs *  B 
)

◆ cs_multiply_and_release()

cs* cs_multiply_and_release ( cs *  b1,
cs *  b2,
int  flag_release 
)

◆ cs_mulvec()

void cs_mulvec ( const cs *  A,
int  nout,
const double *  x,
double *  y 
)

◆ cs_mulvec_lowtri()

void cs_mulvec_lowtri ( const cs *  A,
int  nout,
const double *  x,
double *  y,
int  flag_diag 
)

◆ cs_mulvec_uptri()

void cs_mulvec_uptri ( const cs *  A,
int  nout,
const double *  x,
double *  y,
int  flag_diag 
)

◆ cs_nnz()

int cs_nnz ( const cs *  A)

◆ cs_normalize_by_diag_and_release()

cs* cs_normalize_by_diag_and_release ( cs *  Q,
int  flag_release 
)

◆ cs_print2()

int cs_print2 ( const cs *  A,
int  brief 
)

◆ cs_print_dim()

void cs_print_dim ( const char *  title,
const cs *  A 
)

◆ cs_print_file()

void cs_print_file ( const char *  radix,
int  rank,
cs *  A 
)

◆ cs_print_nice()

void cs_print_nice ( const char *  title,
const cs *  A,
int  maxrow,
int  maxcol 
)

◆ cs_print_only()

void cs_print_only ( const char *  title,
const cs *  A,
int  nlimit 
)

◆ cs_print_range()

void cs_print_range ( const char *  title,
const cs *  C 
)

◆ cs_print_short()

void cs_print_short ( const char *  title,
const cs *  L,
int  nmax 
)

◆ cs_prod_norm()

cs* cs_prod_norm ( int  mode,
cs *  A,
cs *  B 
)

◆ cs_prod_norm_and_release()

cs* cs_prod_norm_and_release ( cs *  b1,
cs *  lambda,
int  flag_release 
)

◆ cs_prod_norm_diagonal()

cs* cs_prod_norm_diagonal ( int  mode,
cs *  B,
VectorDouble  diag 
)

◆ cs_prod_norm_single()

cs* cs_prod_norm_single ( int  mode,
cs *  B 
)

◆ cs_rowcol()

void cs_rowcol ( const cs *  A,
int *  nrows,
int *  ncols,
int *  count,
double *  percent 
)

◆ cs_scale()

int cs_scale ( cs *  A)

◆ cs_set_cste()

void cs_set_cste ( cs *  A,
double  value 
)

◆ cs_set_value()

void cs_set_value ( const cs *  A,
int  row,
int  col,
double  value 
)

◆ cs_sort_i()

int cs_sort_i ( cs *  C)

◆ cs_spalloc2()

cs* cs_spalloc2 ( int  m,
int  n,
int  nzmax,
int  values,
int  triplet 
)

◆ cs_sparse_to_triplet()

void cs_sparse_to_triplet ( const cs *  A,
int  flag_from_1,
int *  number,
int **  cols,
int **  rows,
double **  vals 
)

◆ cs_spfree2()

cs* cs_spfree2 ( cs *  A)

TODO : cs_*2 functions to be removed (encapsulation)

◆ cs_strip()

cs* cs_strip ( cs *  A,
double  eps,
int  hypothesis,
bool  verbose 
)

Strip off elements of the input Sparse Matrix whose absolute value is smaller than eps. Return a new compressed sparse matrix. Consequently, strip off the vector P[in/out] which contains the order of the samples

Parameters
AInput sparse matrix
epsTolerance on absolute value of the input sparse matrix elements
hypothesisStripping hypothesis
verboseVerbose flag
Returns
A pointer to the new sparse matrix (it must be freed by calling function)
Note
Note that in the current version, the input matrix A is also modified

◆ cs_tmulvec()

void cs_tmulvec ( const cs *  A,
int  nout,
const double *  x,
double *  y 
)

◆ cs_toArray()

double* cs_toArray ( const cs *  A)

◆ cs_transpose2()

cs* cs_transpose2 ( const cs *  A,
int  values 
)

◆ cs_triangle()

cs* cs_triangle ( cs *  A,
int  flag_upper,
int  flag_diag 
)

◆ cs_triplet2()

cs* cs_triplet2 ( const cs *  T)

◆ cs_vecmult()

void cs_vecmult ( const cs *  A,
int  nout,
const double *  x,
double *  y 
)

◆ cs_vectors_to_sparse()

cs* cs_vectors_to_sparse ( int  nrow,
int  ncol,
const VectorDouble rows,
const VectorDouble cols,
const VectorDouble values 
)

◆ csd_extract_diag()

double* csd_extract_diag ( cs *  C,
int  mode 
)

◆ csd_extract_diag_VD()

VectorDouble csd_extract_diag_VD ( cs *  C,
int  mode 
)

◆ csToTriplet()

Triplet csToTriplet ( const cs *  A,
bool  flagFrom1 
)

◆ qchol_cholesky()

int qchol_cholesky ( int  verbose,
QChol QC 
)

Finalize the construction of the QChol structure. Perform the Cholesky decomposition

Returns
Error return code
Parameters
[in]verboseVerbose flag
[in]QCQChol structure to be finalized
Remarks
In case of problem the message is issued in this function
If the decomposition is already performed, nothing is done

◆ toStringDim()

String toStringDim ( const String title,
const cs *  A 
)

◆ toStringRange()

String toStringRange ( const String title,
const cs *  C 
)