OSDN Git Service

Please enter the commit message for your changes. Lines starting
[eos/hostdependX86LINUX64.git] / util / X86LINUX64 / include / gsl / gsl_spmatrix_char.h
1 /* spmatrix/gsl_spmatrix_char.h
2  * 
3  * Copyright (C) 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Patrick Alken
4  * 
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or (at
8  * your option) any later version.
9  * 
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  * 
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19
20 #ifndef __GSL_SPMATRIX_CHAR_H__
21 #define __GSL_SPMATRIX_CHAR_H__
22
23 #include <stdlib.h>
24 #include <gsl/gsl_math.h>
25 #include <gsl/gsl_bst.h>
26 #include <gsl/gsl_vector_char.h>
27 #include <gsl/gsl_matrix_char.h>
28
29 #undef __BEGIN_DECLS
30 #undef __END_DECLS
31 #ifdef __cplusplus
32 # define __BEGIN_DECLS extern "C" {
33 # define __END_DECLS }
34 #else
35 # define __BEGIN_DECLS /* empty */
36 # define __END_DECLS /* empty */
37 #endif
38
39 __BEGIN_DECLS
40
41 /*
42  * COO format:
43  *
44  * If data[n] = A_{ij}, then:
45  *   i = A->i[n]
46  *   j = A->p[n]
47  *
48  * Compressed column format (CSC):
49  *
50  * If data[n] = A_{ij}, then:
51  *   i = A->i[n]
52  *   A->p[j] <= n < A->p[j+1]
53  * so that column j is stored in
54  * [ data[p[j]], data[p[j] + 1], ..., data[p[j+1] - 1] ]
55  *
56  * Compressed row format (CSR):
57  *
58  * If data[n] = A_{ij}, then:
59  *   j = A->i[n]
60  *   A->p[i] <= n < A->p[i+1]
61  * so that row i is stored in
62  * [ data[p[i]], data[p[i] + 1], ..., data[p[i+1] - 1] ]
63  */
64
65 typedef struct
66 {
67   size_t size1;               /* number of rows */
68   size_t size2;               /* number of columns */
69
70   /* i (size nzmax) contains:
71    *
72    * COO/CSC: row indices
73    * CSR: column indices
74    */
75   int *i;
76
77   char *data;               /* matrix elements of size nzmax */
78
79   /*
80    * COO: p[n] = column number of element data[n]
81    * CSC: p[j] = index in data of first non-zero element in column j
82    * CSR: p[i] = index in data of first non-zero element in row i
83    */
84   int *p;
85
86   size_t nzmax;              /* maximum number of matrix elements */
87   size_t nz;                 /* number of non-zero values in matrix */
88
89   gsl_bst_workspace *tree;   /* binary tree structure */
90   gsl_spmatrix_pool *pool;   /* memory pool for binary tree nodes */
91   size_t node_size;          /* size of individual tree node in bytes */
92
93   /*
94    * workspace of size MAX(size1,size2)*MAX(sizeof(char),sizeof(int))
95    * used in various routines
96    */
97   union
98     {
99       void *work_void;
100       int *work_int;
101       char *work_atomic;
102     } work;
103
104   int sptype;                /* sparse storage type */
105   size_t spflags;            /* GSL_SPMATRIX_FLG_xxx */
106 } gsl_spmatrix_char;
107
108 /*
109  * Prototypes
110  */
111
112 /* allocation / initialization */
113
114 gsl_spmatrix_char * gsl_spmatrix_char_alloc (const size_t n1, const size_t n2);
115 gsl_spmatrix_char * gsl_spmatrix_char_alloc_nzmax (const size_t n1, const size_t n2,
116                                                      const size_t nzmax, const int sptype);
117 void gsl_spmatrix_char_free (gsl_spmatrix_char * m);
118 int gsl_spmatrix_char_realloc (const size_t nzmax, gsl_spmatrix_char * m);
119 size_t gsl_spmatrix_char_nnz (const gsl_spmatrix_char * m);
120 const char * gsl_spmatrix_char_type (const gsl_spmatrix_char * m);
121 int gsl_spmatrix_char_set_zero (gsl_spmatrix_char * m);
122 int gsl_spmatrix_char_tree_rebuild (gsl_spmatrix_char * m);
123
124 /* compress */
125
126 int gsl_spmatrix_char_csc (gsl_spmatrix_char * dest, const gsl_spmatrix_char * src);
127 int gsl_spmatrix_char_csr (gsl_spmatrix_char * dest, const gsl_spmatrix_char * src);
128 gsl_spmatrix_char * gsl_spmatrix_char_compress (const gsl_spmatrix_char * src, const int sptype);
129 gsl_spmatrix_char * gsl_spmatrix_char_compcol (const gsl_spmatrix_char * src);
130 gsl_spmatrix_char * gsl_spmatrix_char_ccs (const gsl_spmatrix_char * src);
131 gsl_spmatrix_char * gsl_spmatrix_char_crs (const gsl_spmatrix_char * src);
132
133 /* copy */
134
135 int gsl_spmatrix_char_memcpy (gsl_spmatrix_char * dest, const gsl_spmatrix_char * src);
136
137 /* file I/O */
138
139 int gsl_spmatrix_char_fprintf (FILE * stream, const gsl_spmatrix_char * m, const char * format);
140 gsl_spmatrix_char * gsl_spmatrix_char_fscanf (FILE * stream);
141 int gsl_spmatrix_char_fwrite (FILE * stream, const gsl_spmatrix_char * m);
142 int gsl_spmatrix_char_fread (FILE * stream, gsl_spmatrix_char * m);
143
144 /* get/set */
145
146 char gsl_spmatrix_char_get (const gsl_spmatrix_char * m, const size_t i, const size_t j);
147 int gsl_spmatrix_char_set (gsl_spmatrix_char * m, const size_t i, const size_t j, const char x);
148 char * gsl_spmatrix_char_ptr (const gsl_spmatrix_char * m, const size_t i, const size_t j);
149
150 /* minmax */
151
152 int gsl_spmatrix_char_minmax (const gsl_spmatrix_char * m, char * min_out, char * max_out);
153 int gsl_spmatrix_char_min_index (const gsl_spmatrix_char * m, size_t * imin_out, size_t * jmin_out);
154
155 /* operations */
156
157 int gsl_spmatrix_char_scale (gsl_spmatrix_char * m, const char x);
158 int gsl_spmatrix_char_scale_columns (gsl_spmatrix_char * m, const gsl_vector_char * x);
159 int gsl_spmatrix_char_scale_rows (gsl_spmatrix_char * m, const gsl_vector_char * x);
160 int gsl_spmatrix_char_add (gsl_spmatrix_char * c, const gsl_spmatrix_char * a, const gsl_spmatrix_char * b);
161 int gsl_spmatrix_char_dense_add (gsl_matrix_char * a, const gsl_spmatrix_char * b);
162 int gsl_spmatrix_char_dense_sub (gsl_matrix_char * a, const gsl_spmatrix_char * b);
163 int gsl_spmatrix_char_d2sp (gsl_spmatrix_char * T, const gsl_matrix_char * A);
164 int gsl_spmatrix_char_sp2d (gsl_matrix_char * A, const gsl_spmatrix_char * S);
165
166 #ifndef GSL_DISABLE_DEPRECATED
167
168 int gsl_spmatrix_char_add_to_dense (gsl_matrix_char * a, const gsl_spmatrix_char * b);
169
170 #endif
171
172 /* properties */
173
174 int gsl_spmatrix_char_equal (const gsl_spmatrix_char * a, const gsl_spmatrix_char * b);
175 char gsl_spmatrix_char_norm1 (const gsl_spmatrix_char * a);
176
177 /* swap */
178
179 int gsl_spmatrix_char_transpose (gsl_spmatrix_char * m);
180 int gsl_spmatrix_char_transpose2 (gsl_spmatrix_char * m);
181 int gsl_spmatrix_char_transpose_memcpy (gsl_spmatrix_char * dest, const gsl_spmatrix_char * src);
182
183 __END_DECLS
184
185 #endif /* __GSL_SPMATRIX_CHAR_H__ */