1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
|
/* -*- mode: C -*- */
/*
IGraph library.
Copyright (C) 2009-2012 Gabor Csardi <csardi.gabor@gmail.com>
334 Harvard street, Cambridge, MA 02139 USA
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#ifndef IGRAPH_SPARSEMAT_H
#define IGRAPH_SPARSEMAT_H
#include "igraph_decls.h"
#include "igraph_error.h"
#include "igraph_types.h"
#include "igraph_vector.h"
#include "igraph_datatype.h"
#include "igraph_arpack.h"
#include <stdio.h>
__BEGIN_DECLS
/*
* These types are private to igraph, and customized to use igraph_integer_t.
* Do not attempt to access them using a separate copy of the CXSparse library.
* Use the public igraph_sparsemat_... types instead.
*/
struct cs_igraph_sparse;
struct cs_igraph_symbolic;
struct cs_igraph_numeric;
typedef struct {
struct cs_igraph_sparse *cs;
} igraph_sparsemat_t;
typedef struct {
struct cs_igraph_symbolic *symbolic;
} igraph_sparsemat_symbolic_t;
typedef struct {
struct cs_igraph_numeric *numeric;
} igraph_sparsemat_numeric_t;
typedef enum { IGRAPH_SPARSEMAT_TRIPLET,
IGRAPH_SPARSEMAT_CC
} igraph_sparsemat_type_t;
typedef struct {
const igraph_sparsemat_t *mat;
igraph_integer_t pos;
igraph_integer_t col;
} igraph_sparsemat_iterator_t;
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_init(
igraph_sparsemat_t *A, igraph_integer_t rows, igraph_integer_t cols,
igraph_integer_t nzmax
);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_init_copy(
igraph_sparsemat_t *to, const igraph_sparsemat_t *from);
IGRAPH_EXPORT void igraph_sparsemat_destroy(igraph_sparsemat_t *A);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_realloc(igraph_sparsemat_t *A, igraph_integer_t nzmax);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_init_eye(igraph_sparsemat_t *A,
igraph_integer_t n, igraph_integer_t nzmax,
igraph_real_t value, igraph_bool_t compress);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_init_diag(igraph_sparsemat_t *A,
igraph_integer_t nzmax, const igraph_vector_t *values,
igraph_bool_t compress);
IGRAPH_EXPORT igraph_integer_t igraph_sparsemat_nrow(const igraph_sparsemat_t *A);
IGRAPH_EXPORT igraph_integer_t igraph_sparsemat_ncol(const igraph_sparsemat_t *B);
IGRAPH_EXPORT igraph_sparsemat_type_t igraph_sparsemat_type(const igraph_sparsemat_t *A);
IGRAPH_EXPORT igraph_bool_t igraph_sparsemat_is_triplet(const igraph_sparsemat_t *A);
IGRAPH_EXPORT igraph_bool_t igraph_sparsemat_is_cc(const igraph_sparsemat_t *A);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_permute(const igraph_sparsemat_t *A,
const igraph_vector_int_t *p,
const igraph_vector_int_t *q,
igraph_sparsemat_t *res);
IGRAPH_EXPORT igraph_real_t igraph_sparsemat_get(
const igraph_sparsemat_t *A, igraph_integer_t row, igraph_integer_t col
);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_index(const igraph_sparsemat_t *A,
const igraph_vector_int_t *p,
const igraph_vector_int_t *q,
igraph_sparsemat_t *res,
igraph_real_t *constres);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_entry(igraph_sparsemat_t *A,
igraph_integer_t row, igraph_integer_t col, igraph_real_t elem);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_compress(const igraph_sparsemat_t *A,
igraph_sparsemat_t *res);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_transpose(
const igraph_sparsemat_t *A, igraph_sparsemat_t *res
);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_is_symmetric(const igraph_sparsemat_t *A, igraph_bool_t *result);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_dupl(igraph_sparsemat_t *A);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_fkeep(igraph_sparsemat_t *A,
igraph_integer_t (*fkeep)(igraph_integer_t, igraph_integer_t, igraph_real_t, void*),
void *other);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_dropzeros(igraph_sparsemat_t *A);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_droptol(igraph_sparsemat_t *A, igraph_real_t tol);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_multiply(const igraph_sparsemat_t *A,
const igraph_sparsemat_t *B,
igraph_sparsemat_t *res);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_add(const igraph_sparsemat_t *A,
const igraph_sparsemat_t *B,
igraph_real_t alpha,
igraph_real_t beta,
igraph_sparsemat_t *res);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_gaxpy(const igraph_sparsemat_t *A,
const igraph_vector_t *x,
igraph_vector_t *res);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_lsolve(const igraph_sparsemat_t *A,
const igraph_vector_t *b,
igraph_vector_t *res);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_ltsolve(const igraph_sparsemat_t *A,
const igraph_vector_t *b,
igraph_vector_t *res);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_usolve(const igraph_sparsemat_t *A,
const igraph_vector_t *b,
igraph_vector_t *res);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_utsolve(const igraph_sparsemat_t *A,
const igraph_vector_t *b,
igraph_vector_t *res);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_cholsol(const igraph_sparsemat_t *A,
const igraph_vector_t *b,
igraph_vector_t *res,
igraph_integer_t order);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_lusol(const igraph_sparsemat_t *A,
const igraph_vector_t *b,
igraph_vector_t *res,
igraph_integer_t order,
igraph_real_t tol);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_print(const igraph_sparsemat_t *A,
FILE *outstream);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat(igraph_t *graph, const igraph_sparsemat_t *A,
igraph_bool_t directed);
IGRAPH_EXPORT igraph_error_t igraph_weighted_sparsemat(igraph_t *graph, const igraph_sparsemat_t *A,
igraph_bool_t directed, const char *attr,
igraph_bool_t loops);
IGRAPH_EXPORT igraph_error_t igraph_matrix_as_sparsemat(igraph_sparsemat_t *res,
const igraph_matrix_t *mat,
igraph_real_t tol);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_as_matrix(igraph_matrix_t *res,
const igraph_sparsemat_t *spmat);
typedef enum { IGRAPH_SPARSEMAT_SOLVE_LU,
IGRAPH_SPARSEMAT_SOLVE_QR
} igraph_sparsemat_solve_t;
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_arpack_rssolve(const igraph_sparsemat_t *A,
igraph_arpack_options_t *options,
igraph_arpack_storage_t *storage,
igraph_vector_t *values,
igraph_matrix_t *vectors,
igraph_sparsemat_solve_t solvemethod);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_arpack_rnsolve(const igraph_sparsemat_t *A,
igraph_arpack_options_t *options,
igraph_arpack_storage_t *storage,
igraph_matrix_t *values,
igraph_matrix_t *vectors);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_lu(const igraph_sparsemat_t *A,
const igraph_sparsemat_symbolic_t *dis,
igraph_sparsemat_numeric_t *din, double tol);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_qr(const igraph_sparsemat_t *A,
const igraph_sparsemat_symbolic_t *dis,
igraph_sparsemat_numeric_t *din);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_luresol(const igraph_sparsemat_symbolic_t *dis,
const igraph_sparsemat_numeric_t *din,
const igraph_vector_t *b,
igraph_vector_t *res);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_qrresol(const igraph_sparsemat_symbolic_t *dis,
const igraph_sparsemat_numeric_t *din,
const igraph_vector_t *b,
igraph_vector_t *res);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_symbqr(igraph_integer_t order, const igraph_sparsemat_t *A,
igraph_sparsemat_symbolic_t *dis);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_symblu(igraph_integer_t order, const igraph_sparsemat_t *A,
igraph_sparsemat_symbolic_t *dis);
IGRAPH_EXPORT void igraph_sparsemat_symbolic_destroy(igraph_sparsemat_symbolic_t *dis);
IGRAPH_EXPORT void igraph_sparsemat_numeric_destroy(igraph_sparsemat_numeric_t *din);
IGRAPH_EXPORT igraph_real_t igraph_sparsemat_max(igraph_sparsemat_t *A);
IGRAPH_EXPORT igraph_real_t igraph_sparsemat_min(igraph_sparsemat_t *A);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_minmax(igraph_sparsemat_t *A,
igraph_real_t *min, igraph_real_t *max);
IGRAPH_EXPORT igraph_integer_t igraph_sparsemat_count_nonzero(igraph_sparsemat_t *A);
IGRAPH_EXPORT igraph_integer_t igraph_sparsemat_count_nonzerotol(igraph_sparsemat_t *A,
igraph_real_t tol);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_rowsums(const igraph_sparsemat_t *A,
igraph_vector_t *res);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_colsums(const igraph_sparsemat_t *A,
igraph_vector_t *res);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_rowmins(igraph_sparsemat_t *A,
igraph_vector_t *res);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_colmins(igraph_sparsemat_t *A,
igraph_vector_t *res);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_rowmaxs(igraph_sparsemat_t *A,
igraph_vector_t *res);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_colmaxs(igraph_sparsemat_t *A,
igraph_vector_t *res);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_which_min_rows(igraph_sparsemat_t *A,
igraph_vector_t *res,
igraph_vector_int_t *pos);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_which_min_cols(igraph_sparsemat_t *A,
igraph_vector_t *res,
igraph_vector_int_t *pos);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_scale(igraph_sparsemat_t *A, igraph_real_t by);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_add_rows(igraph_sparsemat_t *A, igraph_integer_t n);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_add_cols(igraph_sparsemat_t *A, igraph_integer_t n);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_resize(igraph_sparsemat_t *A,
igraph_integer_t nrow, igraph_integer_t ncol, igraph_integer_t nzmax);
IGRAPH_EXPORT igraph_integer_t igraph_sparsemat_nonzero_storage(const igraph_sparsemat_t *A);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_getelements(const igraph_sparsemat_t *A,
igraph_vector_int_t *i,
igraph_vector_int_t *j,
igraph_vector_t *x);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_getelements_sorted(const igraph_sparsemat_t *A,
igraph_vector_int_t *i,
igraph_vector_int_t *j,
igraph_vector_t *x);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_scale_rows(igraph_sparsemat_t *A,
const igraph_vector_t *fact);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_scale_cols(igraph_sparsemat_t *A,
const igraph_vector_t *fact);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_multiply_by_dense(const igraph_sparsemat_t *A,
const igraph_matrix_t *B,
igraph_matrix_t *res);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_dense_multiply(const igraph_matrix_t *A,
const igraph_sparsemat_t *B,
igraph_matrix_t *res);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_view(igraph_sparsemat_t *A, igraph_integer_t nzmax, igraph_integer_t m, igraph_integer_t n,
igraph_integer_t *p, igraph_integer_t *i, igraph_real_t *x, igraph_integer_t nz);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_sort(const igraph_sparsemat_t *A,
igraph_sparsemat_t *sorted);
IGRAPH_EXPORT igraph_integer_t igraph_sparsemat_nzmax(const igraph_sparsemat_t *A);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_neg(igraph_sparsemat_t *A);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_normalize_cols(igraph_sparsemat_t *sparsemat,
igraph_bool_t allow_zeros);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_normalize_rows(igraph_sparsemat_t *sparsemat,
igraph_bool_t allow_zeros);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_iterator_init(
igraph_sparsemat_iterator_t *it, const igraph_sparsemat_t *sparsemat
);
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_iterator_reset(igraph_sparsemat_iterator_t *it);
IGRAPH_EXPORT igraph_bool_t igraph_sparsemat_iterator_end(const igraph_sparsemat_iterator_t *it);
IGRAPH_EXPORT igraph_integer_t igraph_sparsemat_iterator_row(const igraph_sparsemat_iterator_t *it);
IGRAPH_EXPORT igraph_integer_t igraph_sparsemat_iterator_col(const igraph_sparsemat_iterator_t *it);
IGRAPH_EXPORT igraph_integer_t igraph_sparsemat_iterator_idx(const igraph_sparsemat_iterator_t *it);
IGRAPH_EXPORT igraph_real_t igraph_sparsemat_iterator_get(const igraph_sparsemat_iterator_t *it);
IGRAPH_EXPORT igraph_integer_t igraph_sparsemat_iterator_next(igraph_sparsemat_iterator_t *it);
IGRAPH_EXPORT IGRAPH_DEPRECATED igraph_error_t igraph_sparsemat_copy(
igraph_sparsemat_t *to, const igraph_sparsemat_t *from);
IGRAPH_EXPORT IGRAPH_DEPRECATED igraph_error_t igraph_sparsemat_diag(
igraph_sparsemat_t *A, igraph_integer_t nzmax, const igraph_vector_t *values,
igraph_bool_t compress);
IGRAPH_EXPORT IGRAPH_DEPRECATED igraph_error_t igraph_sparsemat_eye(
igraph_sparsemat_t *A, igraph_integer_t n, igraph_integer_t nzmax,
igraph_real_t value, igraph_bool_t compress);
__END_DECLS
#endif
|