1 /* spmatrix/gsl_spmatrix_int.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_INT_H__
21 #define __GSL_SPMATRIX_INT_H__
24 #include <gsl/gsl_math.h>
25 #include <gsl/gsl_bst.h>
26 #include <gsl/gsl_vector_int.h>
27 #include <gsl/gsl_matrix_int.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 int *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(int),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_int * gsl_spmatrix_int_alloc (const size_t n1, const size_t n2);
115 gsl_spmatrix_int * gsl_spmatrix_int_alloc_nzmax (const size_t n1, const size_t n2,
116 const size_t nzmax, const int sptype);
117 void gsl_spmatrix_int_free (gsl_spmatrix_int * m);
118 int gsl_spmatrix_int_realloc (const size_t nzmax, gsl_spmatrix_int * m);
119 size_t gsl_spmatrix_int_nnz (const gsl_spmatrix_int * m);
120 const char * gsl_spmatrix_int_type (const gsl_spmatrix_int * m);
121 int gsl_spmatrix_int_set_zero (gsl_spmatrix_int * m);
122 int gsl_spmatrix_int_tree_rebuild (gsl_spmatrix_int * m);
126 int gsl_spmatrix_int_csc (gsl_spmatrix_int * dest, const gsl_spmatrix_int * src);
127 int gsl_spmatrix_int_csr (gsl_spmatrix_int * dest, const gsl_spmatrix_int * src);
128 gsl_spmatrix_int * gsl_spmatrix_int_compress (const gsl_spmatrix_int * src, const int sptype);
129 gsl_spmatrix_int * gsl_spmatrix_int_compcol (const gsl_spmatrix_int * src);
130 gsl_spmatrix_int * gsl_spmatrix_int_ccs (const gsl_spmatrix_int * src);
131 gsl_spmatrix_int * gsl_spmatrix_int_crs (const gsl_spmatrix_int * src);
135 int gsl_spmatrix_int_memcpy (gsl_spmatrix_int * dest, const gsl_spmatrix_int * src);
139 int gsl_spmatrix_int_fprintf (FILE * stream, const gsl_spmatrix_int * m, const char * format);
140 gsl_spmatrix_int * gsl_spmatrix_int_fscanf (FILE * stream);
141 int gsl_spmatrix_int_fwrite (FILE * stream, const gsl_spmatrix_int * m);
142 int gsl_spmatrix_int_fread (FILE * stream, gsl_spmatrix_int * m);
146 int gsl_spmatrix_int_get (const gsl_spmatrix_int * m, const size_t i, const size_t j);
147 int gsl_spmatrix_int_set (gsl_spmatrix_int * m, const size_t i, const size_t j, const int x);
148 int * gsl_spmatrix_int_ptr (const gsl_spmatrix_int * m, const size_t i, const size_t j);
152 int gsl_spmatrix_int_minmax (const gsl_spmatrix_int * m, int * min_out, int * max_out);
153 int gsl_spmatrix_int_min_index (const gsl_spmatrix_int * m, size_t * imin_out, size_t * jmin_out);
157 int gsl_spmatrix_int_scale (gsl_spmatrix_int * m, const int x);
158 int gsl_spmatrix_int_scale_columns (gsl_spmatrix_int * m, const gsl_vector_int * x);
159 int gsl_spmatrix_int_scale_rows (gsl_spmatrix_int * m, const gsl_vector_int * x);
160 int gsl_spmatrix_int_add (gsl_spmatrix_int * c, const gsl_spmatrix_int * a, const gsl_spmatrix_int * b);
161 int gsl_spmatrix_int_dense_add (gsl_matrix_int * a, const gsl_spmatrix_int * b);
162 int gsl_spmatrix_int_dense_sub (gsl_matrix_int * a, const gsl_spmatrix_int * b);
163 int gsl_spmatrix_int_d2sp (gsl_spmatrix_int * T, const gsl_matrix_int * A);
164 int gsl_spmatrix_int_sp2d (gsl_matrix_int * A, const gsl_spmatrix_int * S);
166 #ifndef GSL_DISABLE_DEPRECATED
168 int gsl_spmatrix_int_add_to_dense (gsl_matrix_int * a, const gsl_spmatrix_int * b);
174 int gsl_spmatrix_int_equal (const gsl_spmatrix_int * a, const gsl_spmatrix_int * b);
175 int gsl_spmatrix_int_norm1 (const gsl_spmatrix_int * a);
179 int gsl_spmatrix_int_transpose (gsl_spmatrix_int * m);
180 int gsl_spmatrix_int_transpose2 (gsl_spmatrix_int * m);
181 int gsl_spmatrix_int_transpose_memcpy (gsl_spmatrix_int * dest, const gsl_spmatrix_int * src);
185 #endif /* __GSL_SPMATRIX_INT_H__ */