CMR  1.3.0
listmatrix.h
Go to the documentation of this file.
1 #ifndef CMR_LISTMATRIX_INTERNAL_H
2 #define CMR_LISTMATRIX_INTERNAL_H
3 
4 #include <stddef.h>
5 #include <inttypes.h>
6 
7 #include <cmr/env.h>
8 #include <cmr/matrix.h>
9 
10 #include "hashtable.h"
11 
12 #if defined(CMR_WITH_GMP)
13 #include <gmp.h>
14 #endif /* CMR_WITH_GMP */
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
24 typedef struct _ListMat8Nonzero
25 {
30  size_t row;
31  size_t column;
32  int8_t value;
33  int64_t special : 56;
35 
40 typedef struct
41 {
43  size_t numNonzeros;
45 
57 typedef struct
58 {
59  size_t memRows;
60  size_t numRows;
62  size_t memColumns;
63  size_t numColumns;
66  size_t numNonzeros;
68  size_t memNonzeros;
71 } ListMat8;
72 
73 
78 typedef struct _ListMat64Nonzero
79 {
84  size_t row;
85  size_t column;
86  int64_t value;
87  long special;
89 
94 typedef struct
95 {
97  size_t numNonzeros;
99 
111 typedef struct
112 {
113  size_t memRows;
114  size_t numRows;
116  size_t memColumns;
117  size_t numColumns;
120  size_t numNonzeros;
122  size_t memNonzeros;
125 } ListMat64;
126 
127 #if defined(CMR_WITH_GMP)
128 
133 typedef struct _ListMatGMPNonzero
134 {
135  struct _ListMatGMPNonzero* left;
136  struct _ListMatGMPNonzero* right;
137  struct _ListMatGMPNonzero* above;
138  struct _ListMatGMPNonzero* below;
139  size_t row;
140  size_t column;
141  mpz_t value;
142  long special;
143 } ListMatGMPNonzero;
144 
149 typedef struct
150 {
151  ListMatGMPNonzero head;
152  size_t numNonzeros;
153 } ListMatGMPElement;
154 
166 typedef struct
167 {
168  size_t memRows;
169  size_t numRows;
170  ListMatGMPElement* rowElements;
171  size_t memColumns;
172  size_t numColumns;
173  ListMatGMPElement* columnElements;
175  size_t numNonzeros;
176  ListMatGMPNonzero anchor;
177  size_t memNonzeros;
178  ListMatGMPNonzero* nonzeros;
179  ListMatGMPNonzero* firstFreeNonzero;
180 } ListMatGMP;
181 
182 #endif /* CMR_WITH_GMP */
183 
189  CMR* cmr,
190  size_t memRows,
191  size_t memColumns,
192  size_t memNonzeros,
193  ListMat8** presult
194 );
195 
201  CMR* cmr,
202  size_t memRows,
203  size_t memColumns,
204  size_t memNonzeros,
205  ListMat64** presult
206 );
207 
208 #if defined(CMR_WITH_GMP)
209 
214 CMR_ERROR CMRlistmatGMPAlloc(
215  CMR* cmr,
216  size_t memRows,
217  size_t memColumns,
218  size_t memNonzeros,
219  ListMatGMP** presult
220 );
221 
222 #endif /* CMR_WITH_GMP */
223 
229  CMR* cmr,
230  ListMat8** plistmatrix
231 );
232 
238  CMR* cmr,
239  ListMat64** plistmatrix
240 );
241 
242 #if defined(CMR_WITH_GMP)
243 
248 CMR_ERROR CMRlistmatGMPFree(
249  CMR* cmr,
250  ListMatGMP** plistmatrix
251 );
252 
253 #endif /* CMR_WITH_GMP */
254 
260  CMR* cmr,
261  ListMat8* listmatrix,
262  size_t numRows,
263  size_t numColumns
264 );
265 
271  CMR* cmr,
272  ListMat64* listmatrix,
273  size_t numRows,
274  size_t numColumns
275 );
276 
277 #if defined(CMR_WITH_GMP)
278 
283 CMR_ERROR CMRlistmatGMPInitializeZero(
284  CMR* cmr,
285  ListMatGMP* listmatrix,
286  size_t numRows,
287  size_t numColumns
288 );
289 
290 #endif /* CMR_WITH_GMP */
291 
297  CMR* cmr,
298  ListMat8* listmatrix,
299  CMR_CHRMAT* matrix
300 );
301 
307  CMR* cmr,
308  ListMat64* listmatrix,
309  CMR_INTMAT* matrix
310 );
311 
312 #if defined(CMR_WITH_GMP)
313 
318 CMR_ERROR CMRlistmatGMPInitializeFromIntMatrix(
319  CMR* cmr,
320  ListMatGMP* listmatrix,
321  CMR_INTMAT* matrix
322 );
323 
324 #endif /* CMR_WITH_GMP */
325 
331  CMR* cmr,
332  ListMat8* listmatrix,
333  CMR_DBLMAT* matrix,
334  double epsilon
335 );
336 
342  CMR* cmr,
343  ListMat64* listmatrix,
344  CMR_DBLMAT* matrix,
345  double epsilon
346 );
347 
348 #if defined(CMR_WITH_GMP)
349 
354 CMR_ERROR CMRlistmatGMPInitializeFromDoubleMatrix(
355  CMR* cmr,
356  ListMatGMP* listmatrix,
357  CMR_DBLMAT* matrix,
358  double epsilon
359 );
360 
361 #endif /* CMR_WITH_GMP */
362 
368  CMR* cmr,
369  ListMat8* listmatrix,
370  CMR_CHRMAT* matrix,
371  CMR_SUBMAT* submatrix
372 );
373 
379  CMR* cmr,
380  ListMat64* listmatrix,
381  CMR_INTMAT* matrix,
382  CMR_SUBMAT* submatrix
383 );
384 
385 #if defined(CMR_WITH_GMP)
386 
391 CMR_ERROR CMRlistmatGMPInitializeFromIntSubmatrix(
392  CMR* cmr,
393  ListMatGMP* listmatrix,
394  CMR_INTMAT* matrix,
395  CMR_SUBMAT* submatrix
396 );
397 
398 #endif /* CMR_WITH_GMP */
399 
405  CMR* cmr,
406  ListMat8* listmatrix,
407  CMR_CHRMAT* matrix,
408  CMR_SUBMAT* submatrix
409 );
410 
416  CMR* cmr,
417  ListMat64* listmatrix,
418  CMR_INTMAT* matrix,
419  CMR_SUBMAT* submatrix
420 );
421 
422 #if defined(CMR_WITH_GMP)
423 
428 CMR_ERROR CMRlistmatGMPInitializeFromIntSubmatrixComplement(
429  CMR* cmr,
430  ListMatGMP* listmatrix,
431  CMR_INTMAT* matrix,
432  CMR_SUBMAT* submatrix
433 );
434 
435 #endif /* CMR_WITH_GMP */
436 
442  CMR* cmr,
443  ListMat8* listmatrix,
444  FILE* stream
445 );
446 
452  CMR* cmr,
453  ListMat64* listmatrix,
454  FILE* stream
455 );
456 
457 #if defined(CMR_WITH_GMP)
458 
463 CMR_ERROR CMRlistmatGMPPrintDense(
464  CMR* cmr,
465  ListMatGMP* listmatrix,
466  FILE* stream
467 );
468 
469 #endif /* CMR_WITH_GMP */
470 
478  CMR* cmr,
479  ListMat8* listmatrix,
480  size_t row,
481  size_t column,
482  int8_t value,
483  long special,
484  ptrdiff_t* pmemoryShift
485 );
486 
494  CMR* cmr,
495  ListMat64* listmatrix,
496  size_t row,
497  size_t column,
498  int64_t value,
499  long special,
500  ptrdiff_t* pmemoryShift
501 );
502 
503 #if defined(CMR_WITH_GMP)
504 
511 CMR_ERROR CMRlistmatGMPInsert(
512  CMR* cmr,
513  ListMatGMP* listmatrix,
514  size_t row,
515  size_t column,
516  mpz_srcptr value,
517  long special,
518  ptrdiff_t* pmemoryShift
519 );
520 
521 #endif /* CMR_WITH_GMP */
522 
528  CMR* cmr,
529  ListMat8* listmatrix,
530  ListMat8Nonzero* nz
531 );
532 
538  CMR* cmr,
539  ListMat64* listmatrix,
540  ListMat64Nonzero* nz
541 );
542 
543 #if defined(CMR_WITH_GMP)
544 
549 CMR_ERROR CMRlistmatGMPDelete(
550  CMR* cmr,
551  ListMatGMP* listmatrix,
552  ListMatGMPNonzero* nz
553 );
554 
555 #endif /* CMR_WITH_GMP */
556 
557 #ifdef __cplusplus
558 }
559 #endif
560 
561 #endif /* CMR_LISTMATRIX_INTERNAL_H */
Basic functionality of the software library.
CMR_ERROR
Type for return codes of library functions.
Definition: env.h:32
struct _ListMat8Nonzero ListMat8Nonzero
Nonzero of a ListMat8.
struct _ListMat64Nonzero ListMat64Nonzero
Nonzero of a ListMat64.
CMR_ERROR CMRlistmat64InitializeFromIntSubmatrixComplement(CMR *cmr, ListMat64 *listmatrix, CMR_INTMAT *matrix, CMR_SUBMAT *submatrix)
Copies all but submatrix of matrix into listmatrix.
Definition: listmatrix.c:1252
CMR_ERROR CMRlistmat64Free(CMR *cmr, ListMat64 **plistmatrix)
Frees a 64-bit list matrix.
Definition: listmatrix.c:110
CMR_ERROR CMRlistmat8InitializeFromDoubleMatrix(CMR *cmr, ListMat8 *listmatrix, CMR_DBLMAT *matrix, double epsilon)
Copies matrix into listmatrix.
Definition: listmatrix.c:699
CMR_ERROR CMRlistmat8InitializeFromSubmatrixComplement(CMR *cmr, ListMat8 *listmatrix, CMR_CHRMAT *matrix, CMR_SUBMAT *submatrix)
Copies all but submatrix of matrix into listmatrix.
CMR_ERROR CMRlistmat8InitializeFromChrMatrix(CMR *cmr, ListMat8 *listmatrix, CMR_CHRMAT *matrix)
Copies matrix into listmatrix.
Definition: listmatrix.c:485
CMR_ERROR CMRlistmat8PrintDense(CMR *cmr, ListMat8 *listmatrix, FILE *stream)
Prints the 8-bit list matrix as a dense matrix.
Definition: listmatrix.c:1406
CMR_ERROR CMRlistmat64PrintDense(CMR *cmr, ListMat64 *listmatrix, FILE *stream)
Prints the 64-bit list matrix as a dense matrix.
Definition: listmatrix.c:1439
CMR_ERROR CMRlistmat64InitializeFromDoubleMatrix(CMR *cmr, ListMat64 *listmatrix, CMR_DBLMAT *matrix, double epsilon)
Copies matrix into listmatrix.
Definition: listmatrix.c:777
CMR_ERROR CMRlistmat8Alloc(CMR *cmr, size_t memRows, size_t memColumns, size_t memNonzeros, ListMat8 **presult)
Allocates memory for an 8-bit list matrix.
Definition: listmatrix.c:9
CMR_ERROR CMRlistmat64InitializeFromIntSubmatrix(CMR *cmr, ListMat64 *listmatrix, CMR_INTMAT *matrix, CMR_SUBMAT *submatrix)
Copies submatrix of matrix into listmatrix.
Definition: listmatrix.c:1017
CMR_ERROR CMRlistmat8Free(CMR *cmr, ListMat8 **plistmatrix)
Frees an 8-bit list matrix.
Definition: listmatrix.c:93
CMR_ERROR CMRlistmat64Delete(CMR *cmr, ListMat64 *listmatrix, ListMat64Nonzero *nz)
Delete a nonzero element.
Definition: listmatrix.c:1860
CMR_ERROR CMRlistmat8InitializeZero(CMR *cmr, ListMat8 *listmatrix, size_t numRows, size_t numColumns)
Initializes a zero 8-bit list matrix.
Definition: listmatrix.c:151
CMR_ERROR CMRlistmat64Alloc(CMR *cmr, size_t memRows, size_t memColumns, size_t memNonzeros, ListMat64 **presult)
Allocates memory for a 64-bit list matrix.
Definition: listmatrix.c:35
CMR_ERROR CMRlistmat64Insert(CMR *cmr, ListMat64 *listmatrix, size_t row, size_t column, int64_t value, long special, ptrdiff_t *pmemoryShift)
Creates a new element and inserts it into the doubly-linked lists.
Definition: listmatrix.c:1614
CMR_ERROR CMRlistmat64InitializeFromIntMatrix(CMR *cmr, ListMat64 *listmatrix, CMR_INTMAT *matrix)
Copies matrix into listmatrix.
Definition: listmatrix.c:555
CMR_ERROR CMRlistmat8Delete(CMR *cmr, ListMat8 *listmatrix, ListMat8Nonzero *nz)
Delete a nonzero element.
Definition: listmatrix.c:1833
CMR_ERROR CMRlistmat8Insert(CMR *cmr, ListMat8 *listmatrix, size_t row, size_t column, int8_t value, long special, ptrdiff_t *pmemoryShift)
Creates a new element and inserts it into the doubly-linked lists.
Definition: listmatrix.c:1513
CMR_ERROR CMRlistmat8InitializeFromChrSubmatrix(CMR *cmr, ListMat8 *listmatrix, CMR_CHRMAT *matrix, CMR_SUBMAT *submatrix)
Copies submatrix of matrix into listmatrix.
Definition: listmatrix.c:937
CMR_ERROR CMRlistmat64InitializeZero(CMR *cmr, ListMat64 *listmatrix, size_t numRows, size_t numColumns)
Initializes a zero 64-bit list matrix.
Definition: listmatrix.c:261
Functionality for sparse matrices.
Row-wise representation of sparse char matrix.
Definition: matrix.h:220
Row-wise representation of sparse double matrix.
Definition: matrix.h:172
Definition: env_internal.h:45
Row-wise representation of sparse int matrix.
Definition: matrix.h:196
Row and column indices for a submatrix.
Definition: matrix.h:28
Row/column information of a ListMat64.
Definition: listmatrix.h:95
size_t numNonzeros
Number of nonzeros in that row/column.
Definition: listmatrix.h:97
ListMat64Nonzero head
Dummy nonzero in that row/column.
Definition: listmatrix.h:96
Linked-list representation of a matrix with 64-bit integer values.
Definition: listmatrix.h:112
size_t numRows
Number of rows.
Definition: listmatrix.h:114
size_t numColumns
Number of columns.
Definition: listmatrix.h:117
ListMat64Nonzero * firstFreeNonzero
Beginning of free list; uses right pointers.
Definition: listmatrix.h:124
ListMat64Element * columnElements
Column data.
Definition: listmatrix.h:118
ListMat64Nonzero * nonzeros
Raw nonzero data.
Definition: listmatrix.h:123
size_t memRows
Memory for rows.
Definition: listmatrix.h:113
size_t numNonzeros
Definition: listmatrix.h:120
ListMat64Nonzero anchor
Anchor for nonzeros.
Definition: listmatrix.h:121
size_t memNonzeros
Amount of memory for nonzeros.
Definition: listmatrix.h:122
size_t memColumns
Memory for columns.
Definition: listmatrix.h:116
ListMat64Element * rowElements
Row data.
Definition: listmatrix.h:115
Row/column information of a ListMat8.
Definition: listmatrix.h:41
size_t numNonzeros
Number of nonzeros in that row/column.
Definition: listmatrix.h:43
ListMat8Nonzero head
Dummy nonzero in that row/column.
Definition: listmatrix.h:42
Linked-list representation of a matrix with 8-bit integer values.
Definition: listmatrix.h:58
size_t memColumns
Memory for columns.
Definition: listmatrix.h:62
ListMat8Element * columnElements
Column data.
Definition: listmatrix.h:64
size_t memNonzeros
Amount of memory for nonzeros.
Definition: listmatrix.h:68
ListMat8Nonzero anchor
Anchor for nonzeros.
Definition: listmatrix.h:67
size_t memRows
Memory for rows.
Definition: listmatrix.h:59
size_t numColumns
Number of columns.
Definition: listmatrix.h:63
size_t numNonzeros
Definition: listmatrix.h:66
ListMat8Nonzero * firstFreeNonzero
Beginning of free list; uses right pointers.
Definition: listmatrix.h:70
ListMat8Nonzero * nonzeros
Raw nonzero data.
Definition: listmatrix.h:69
ListMat8Element * rowElements
Row data.
Definition: listmatrix.h:61
size_t numRows
Number of rows.
Definition: listmatrix.h:60
Nonzero of a ListMat64.
Definition: listmatrix.h:79
struct _ListMat64Nonzero * above
Pointer to previous nonzero in the same column.
Definition: listmatrix.h:82
int64_t value
Matrix entry.
Definition: listmatrix.h:86
struct _ListMat64Nonzero * below
Pointer to next nonzero in the same column.
Definition: listmatrix.h:83
long special
May be used for a special purpose.
Definition: listmatrix.h:87
size_t row
Row.
Definition: listmatrix.h:84
size_t column
Column.
Definition: listmatrix.h:85
struct _ListMat64Nonzero * right
Pointer to next nonzero in the same row.
Definition: listmatrix.h:81
struct _ListMat64Nonzero * left
Pointer to previous nonzero in the same row.
Definition: listmatrix.h:80
Nonzero of a ListMat8.
Definition: listmatrix.h:25
struct _ListMat8Nonzero * left
Pointer to previous nonzero in the same row.
Definition: listmatrix.h:26
struct _ListMat8Nonzero * above
Pointer to previous nonzero in the same column.
Definition: listmatrix.h:28
int64_t special
Remaining bits (on 64 bit) may be used for a special purpose.
Definition: listmatrix.h:33
size_t row
Row.
Definition: listmatrix.h:30
struct _ListMat8Nonzero * below
Pointer to next nonzero in the same column.
Definition: listmatrix.h:29
size_t column
Column.
Definition: listmatrix.h:31
int8_t value
Matrix entry.
Definition: listmatrix.h:32
struct _ListMat8Nonzero * right
Pointer to next nonzero in the same row.
Definition: listmatrix.h:27