Program listing for file numerics/src/tools/CSparseMatrix.h#
Return to documentation for this file
1#ifndef SparseMatrix_H
2#define SparseMatrix_H
3
4#include <stdio.h>
5
6
7
8#include "SiconosConfig.h"
9
10
11#ifdef SICONOS_INT64
12#ifndef CS_LONG
13#define CS_LONG
14#endif
15#else
16#ifdef CS_LONG
17#error "CS_LONG (set) does not correspond with SICONOS_INT64 (unset)"
18#endif
19#endif
20
21#ifndef CS_INT
22
23
24#ifdef CS_LONG
25#define CS_INT long
26#else
27#define CS_INT int
28#endif
29
30
31struct cs_dl_sparse;
32struct cs_di_sparse;
33struct cs_dl_symbolic;
34struct cs_di_symbolic;
35struct cs_dl_numeric;
36struct cs_di_numeric;
37typedef struct cs_dl_symbolic cs_dls;
38typedef struct cs_di_symbolic cs_dis;
39typedef struct cs_dl_numeric cs_dln;
40typedef struct cs_di_numeric cs_din;
41
42#ifdef SICONOS_INT64
43#ifndef css
44#define css cs_dls
45#endif
46#ifndef csn
47#define csn cs_dln
48#endif
49#else
50#ifndef css
51#define css cs_dis
52#endif
53#ifndef csn
54#define csn cs_din
55#endif
56#endif
57
58#endif
59
60#ifdef SICONOS_INT64
61typedef struct cs_dl_sparse CSparseMatrix;
62#else
63typedef struct cs_di_sparse CSparseMatrix;
64#endif
65
66
67
68
69
70#define NSM_UNKNOWN_ERR(func, orig) \
71fprintf(stderr, #func ": unknown origin %d for sparse matrix\n", orig);
72
73
74#define NSM_NROW_CSR(mat) mat->n
75#define NSM_NCOL_CSR(mat) mat->m
76
77#if defined(__cplusplus) && !defined(BUILD_AS_CPP)
78extern "C"
79{
80#endif
81
82
83 typedef struct {
84 CS_INT n;
85 css* S;
86 csn* N;
87 } CSparseMatrix_factors;
88
89
90 int CSparseMatrix_lu_factorization(CS_INT order, const CSparseMatrix *A, double tol, CSparseMatrix_factors * cs_lu_A);
91
92
93 int CSparseMatrix_chol_factorization(CS_INT order, const CSparseMatrix *A, CSparseMatrix_factors * cs_chol_A);
94
95
96 int CSparseMatrix_ldlt_factorization(CS_INT order, const CSparseMatrix *A, CSparseMatrix_factors * cs_ldlt_A);
97
98
99 CS_INT CSparseMatrix_solve(CSparseMatrix_factors* cs_lu_A, double* x, double *b);
100
101
102 CS_INT CSparseMatrix_spsolve(CSparseMatrix_factors* cs_lu_A, CSparseMatrix* X, CSparseMatrix* B);
103
104
105 CS_INT CSparseMatrix_chol_solve(CSparseMatrix_factors* cs_chol_A, double* x, double *b);
106
107
108 CS_INT CSparseMatrix_chol_spsolve(CSparseMatrix_factors* cs_chol_A, CSparseMatrix* X, CSparseMatrix* B);
109
110
111 CS_INT CSparseMatrix_ldlt_solve(CSparseMatrix_factors* cs_ldlt_A, double* x, double *b);
112
113
114 void CSparseMatrix_free_lu_factors(CSparseMatrix_factors* cs_lu_A);
115
116
117 int CSparseMatrix_aaxpby(const double alpha, const CSparseMatrix *A, const double *x,
118 const double beta, double *y);
119
120
121 CSparseMatrix* CSparseMatrix_alloc_for_copy(const CSparseMatrix* const m);
122
123 CS_INT CSparseMatrix_to_dense(const CSparseMatrix* const A, double * B);
124
125
126 int CSparseMatrix_print(const CSparseMatrix *A, int brief);
127
128
129 int CSparseMatrix_print_in_file(const CSparseMatrix *A, int brief, FILE* file);
130
131 int CSparseMatrix_print_in_Matlab_file(const CSparseMatrix *A, int brief, FILE* file);
132
133 CSparseMatrix * CSparseMatrix_new_from_file(FILE* file);
134
135
136 CS_INT CSparseMatrix_zentry(CSparseMatrix *T, CS_INT i, CS_INT j, double x, double threshold);
137
138
139 CS_INT CSparseMatrix_block_dense_zentry(CSparseMatrix *T, CS_INT row_off, CS_INT col_off, double * x, CS_INT row_size, CS_INT col_size, double threshold);
140
141
142 CS_INT CSparseMatrix_symmetric_zentry(CSparseMatrix *T, CS_INT i, CS_INT j, double x, double threshold);
143
144
145 CS_INT CSparseMatrix_entry(CSparseMatrix *T, CS_INT i, CS_INT j, double x);
146
147
148 CS_INT CSparseMatrix_symmetric_entry(CSparseMatrix *T, CS_INT i, CS_INT j, double x);
149
150
151 int CSparseMatrix_check_triplet(CSparseMatrix *T);
152
153
154 int CSparseMatrix_check_csc(CSparseMatrix *T);
155
156
157 CSparseMatrix* CSparseMatrix_spfree_on_stack(CSparseMatrix* A);
158
159
160 void CSparseMatrix_copy(const CSparseMatrix* const A, CSparseMatrix* B);
161
162
163 int CSparseMatrix_scal(const double alpha, const CSparseMatrix *A);
164
165
166
167 double CSparseMatrix_get_value(const CSparseMatrix *A, CS_INT i, CS_INT j);
168
169
170 void CSparseMatrix_write_in_file_python(const CSparseMatrix* const m, FILE* file);
171
172
173 int CSparseMatrix_max_by_columns(const CSparseMatrix *A, double * max);
174
175
176 int CSparseMatrix_max_abs_by_columns(const CSparseMatrix *A, double * max);
177
178#if defined(__cplusplus) && !defined(BUILD_AS_CPP)
179}
180#endif
181
182#endif