ScaMaC  0.8.2
A Scalable Matrix Collection
scamac_sparserow.h
Go to the documentation of this file.
1 
8 #ifndef SCAMAC_SPARSEROW_H
9 #define SCAMAC_SPARSEROW_H
10 
11 #include <complex.h>
12 #include <stdbool.h>
13 
14 #include "scamac_error.h"
15 #include "scamac_inttypes.h"
16 
17 typedef struct {
18  ScamacIdx idx;
19  double val;
20 } scamac_idxreal_st;
21 
22 typedef struct {
23  int nalloc;
24  int nrow;
25  scamac_idxreal_st *row;
26 } scamac_sparserow_real_st;
27 
28 typedef struct {
29  ScamacIdx idx;
30  double complex val;
31 } scamac_idxcplx_st;
32 
33 typedef struct {
34  int nalloc;
35  int nrow;
36  scamac_idxcplx_st *row;
37 } scamac_sparserow_cplx_st;
38 
39 
40 /* sparse row routines */
41 
42 ScamacErrorCode scamac_sparserow_real_alloc(ScamacIdx n, scamac_sparserow_real_st ** srow);
43 ScamacErrorCode scamac_sparserow_cplx_alloc(ScamacIdx n, scamac_sparserow_cplx_st ** srow);
44 
45 ScamacErrorCode scamac_sparserow_real_free(scamac_sparserow_real_st *row);
46 ScamacErrorCode scamac_sparserow_cplx_free(scamac_sparserow_cplx_st *row);
47 
48 ScamacErrorCode scamac_sparserow_real_zero(scamac_sparserow_real_st *row);
49 ScamacErrorCode scamac_sparserow_cplx_zero(scamac_sparserow_cplx_st *row);
50 
51 /* if idx < 0, row is unchanged. This convention interacts nicely with scamac_multidx_upd() */
52 ScamacErrorCode scamac_sparserow_real_add(scamac_sparserow_real_st *row, double alpha, ScamacIdx idx);
53 ScamacErrorCode scamac_sparserow_cplx_add(scamac_sparserow_cplx_st *row, double complex alpha, ScamacIdx idx);
54 
55 /* Sort and compress sparse row */
56 ScamacErrorCode scamac_sparserow_real_normalize(scamac_sparserow_real_st *row, bool keep_zeros);
57 ScamacErrorCode scamac_sparserow_cplx_normalize(scamac_sparserow_cplx_st *row, bool keep_zeros);
58 
59 /* convert sparse row to idx/val pair of vectors. */
60 ScamacErrorCode scamac_sparserow_real_to_idxval(scamac_sparserow_real_st *row, ScamacIdx maxrowlength, ScamacIdx * nz, ScamacIdx *idx, double *val);
61 ScamacErrorCode scamac_sparserow_cplx_to_idxval(scamac_sparserow_cplx_st *row, ScamacIdx maxrowlength, ScamacIdx * nz, ScamacIdx *idx, double complex *val);
62 
63 
64 /* convert sparse row to idx [type:int]/val pair of vectors. */
65 ScamacErrorCode scamac_sparserow_real_to_idxval_int(scamac_sparserow_real_st *row, ScamacIdx maxrowlength, int * nz, int *idx, double *val);
66 ScamacErrorCode scamac_sparserow_cplx_to_idxval_int(scamac_sparserow_cplx_st *row, ScamacIdx maxrowlength, int * nz, int *idx, double complex *val);
67 
68 #endif /* SCAMAC_SPARSEROW_H */
ScaMaC index/integer types.
ScaMaC data structure and macro definitions.