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