1 /* spmatrix/gsl_spmatrix_char.h
3 * Copyright (C) 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Patrick Alken
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.
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.
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.
20 #ifndef __GSL_SPMATRIX_CHAR_H__
21 #define __GSL_SPMATRIX_CHAR_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>
32 # define __BEGIN_DECLS extern "C" {
33 # define __END_DECLS }
35 # define __BEGIN_DECLS /* empty */
36 # define __END_DECLS /* empty */
44 * If data[n] = A_{ij}, then:
48 * Compressed column format (CSC):
50 * If data[n] = A_{ij}, then:
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] ]
56 * Compressed row format (CSR):
58 * If data[n] = A_{ij}, then:
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] ]
67 size_t size1; /* number of rows */
68 size_t size2; /* number of columns */
70 /* i (size nzmax) contains:
72 * COO/CSC: row indices
77 char *data; /* matrix elements of size nzmax */
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
86 size_t nzmax; /* maximum number of matrix elements */
87 size_t nz; /* number of non-zero values in matrix */
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 */
94 * workspace of size MAX(size1,size2)*MAX(sizeof(char),sizeof(int))
95 * used in various routines
104 int sptype; /* sparse storage type */
105 size_t spflags; /* GSL_SPMATRIX_FLG_xxx */
112 /* allocation / initialization */
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);
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);
135 int gsl_spmatrix_char_memcpy (gsl_spmatrix_char * dest, const gsl_spmatrix_char * src);
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);
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);
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);
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);
166 #ifndef GSL_DISABLE_DEPRECATED
168 int gsl_spmatrix_char_add_to_dense (gsl_matrix_char * a, const gsl_spmatrix_char * b);
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);
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);
185 #endif /* __GSL_SPMATRIX_CHAR_H__ */