Graphviz 12.0.1~dev.20240716.0800
Loading...
Searching...
No Matches
SparseMatrix.h
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (c) 2011 AT&T Intellectual Property
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors: Details at https://graphviz.org
9 *************************************************************************/
10
11#pragma once
12
13#include <sparse/general.h>
14#include <stdbool.h>
15#include <stddef.h>
16#include <stdio.h>
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22#define SYMMETRY_EPSILON 0.0000001
24enum {UNMASKED = -10, MASKED = 1};
27
28
30 int m; /* row dimension */
31 int n; /* column dimension */
32 int nz;/* The actual length used is nz, for CSR/CSC matrix this is the same as ia[n] */
33 int nzmax; /* the current length of ja and a (if exists) allocated.*/
34 int type; /* whether it is real/complex matrix, or pattern only */
35 int *ia; /* row pointer for CSR format, or row indices for coordinate format. 0-based */
36 int *ja; /* column indices. 0-based */
37 void *a; /* entry values. If NULL, pattern matrix */
38 int format;/* whether it is CSR, CSC, COORD. By default it is in CSR format */
39 int property; /* pattern_symmetric/symmetric/skew/hermitian*/
40 size_t size;/* size of each entry. This allows for general matrix where each entry is, say, a matrix itself */
41};
42
44
46
47/* SparseMatrix_general is more general and allow elements to be
48 any data structure, not just real/int/complex etc */
49SparseMatrix SparseMatrix_new(int m, int n, int nz, int type, int format);
50SparseMatrix SparseMatrix_general_new(int m, int n, int nz, int type, size_t sz, int format);
51
52/* this version sum repeated entries */
55
56SparseMatrix SparseMatrix_from_coordinate_arrays(int nz, int m, int n, int *irn, int *jcn, void *val, int type, size_t sz);
57SparseMatrix SparseMatrix_from_coordinate_arrays_not_compacted(int nz, int m, int n, int *irn, int *jcn, void *val, int type, size_t sz);
58
59void SparseMatrix_export(FILE *f, SparseMatrix A);/* export into MM format except the header */
60
62
66
70 int jcn, const void *val);
71bool SparseMatrix_is_symmetric(SparseMatrix A, bool test_pattern_symmetry_only);
74 bool pattern_symmetric_only);
75void SparseMatrix_multiply_vector(SparseMatrix A, double *v, double **res);/* if v = NULL, v is assumed to be {1,1,...,1}*/
77SparseMatrix SparseMatrix_remove_upper(SparseMatrix A);/* remove diag and upper diag */
79SparseMatrix SparseMatrix_get_real_adjacency_matrix_symmetrized(SparseMatrix A); /* symmetric, all entries to 1, diaginal removed */
80void SparseMatrix_multiply_dense(SparseMatrix A, const double *v, double *res,
81 int dim);
82SparseMatrix SparseMatrix_apply_fun(SparseMatrix A, double (*fun)(double x));/* for real only! */
85SparseMatrix SparseMatrix_make_undirected(SparseMatrix A);/* make it strictly low diag only, and set flag to undirected */
87 int **comps);
88void SparseMatrix_decompose_to_supervariables(SparseMatrix A, int *ncluster, int **cluster, int **clusterp);
89SparseMatrix SparseMatrix_get_submatrix(SparseMatrix A, int nrow, int ncol, int *rindices, int *cindices);
90
92
93/* bipartite_options:
94 BIPARTITE_RECT -- turn rectangular matrix into square),
95 BIPARTITE_PATTERN_UNSYM -- pattern unsummetric as bipartite
96 BIPARTITE_UNSYM -- unsymmetric as square
97 BIPARTITE_ALWAYS -- always as square
98*/
100
102
104
105void SparseMatrix_distance_matrix(SparseMatrix A, double **dist_matrix);
106
107SparseMatrix SparseMatrix_from_dense(int m, int n, double *x);
108
109#define SparseMatrix_set_undirected(A) set_flag((A)->property, MATRIX_UNDIRECTED)
110#define SparseMatrix_set_symmetric(A) set_flag((A)->property, MATRIX_SYMMETRIC)
111#define SparseMatrix_set_pattern_symmetric(A) set_flag((A)->property, MATRIX_PATTERN_SYMMETRIC)
112
113
114#define SparseMatrix_known_undirected(A) test_flag((A)->property, MATRIX_UNDIRECTED)
115#define SparseMatrix_known_symmetric(A) test_flag((A)->property, MATRIX_SYMMETRIC)
116#define SparseMatrix_known_strucural_symmetric(A) test_flag((A)->property, MATRIX_PATTERN_SYMMETRIC)
117
118#ifdef __cplusplus
119}
120#endif
SparseMatrix SparseMatrix_from_coordinate_arrays_not_compacted(int nz, int m, int n, int *irn, int *jcn, void *val, int type, size_t sz)
@ FORMAT_COORD
@ FORMAT_CSR
void SparseMatrix_distance_matrix(SparseMatrix A, double **dist_matrix)
void SparseMatrix_decompose_to_supervariables(SparseMatrix A, int *ncluster, int **cluster, int **clusterp)
SparseMatrix SparseMatrix_from_coordinate_format(SparseMatrix A)
SparseMatrix SparseMatrix_transpose(SparseMatrix A)
@ MATRIX_TYPE_REAL
@ MATRIX_TYPE_UNKNOWN
@ MATRIX_TYPE_PATTERN
@ MATRIX_TYPE_COMPLEX
@ MATRIX_TYPE_INTEGER
SparseMatrix SparseMatrix_remove_upper(SparseMatrix A)
SparseMatrix SparseMatrix_get_submatrix(SparseMatrix A, int nrow, int ncol, int *rindices, int *cindices)
SparseMatrix SparseMatrix_symmetrize(SparseMatrix A, bool pattern_symmetric_only)
SparseMatrix SparseMatrix_general_new(int m, int n, int nz, int type, size_t sz, int format)
SparseMatrix SparseMatrix_get_augmented(SparseMatrix A)
struct SparseMatrix_struct * SparseMatrix
void SparseMatrix_multiply_dense(SparseMatrix A, const double *v, double *res, int dim)
SparseMatrix SparseMatrix_coordinate_form_add_entry(SparseMatrix A, int irn, int jcn, const void *val)
bool SparseMatrix_is_symmetric(SparseMatrix A, bool test_pattern_symmetry_only)
SparseMatrix SparseMatrix_to_square_matrix(SparseMatrix A, int bipartite_options)
void SparseMatrix_multiply_vector(SparseMatrix A, double *v, double **res)
SparseMatrix SparseMatrix_multiply(SparseMatrix A, SparseMatrix B)
SparseMatrix SparseMatrix_divide_row_by_degree(SparseMatrix A)
void SparseMatrix_export(FILE *f, SparseMatrix A)
void SparseMatrix_delete(SparseMatrix A)
@ MATRIX_PATTERN_SYMMETRIC
@ MATRIX_UNDIRECTED
@ MATRIX_SYMMETRIC
SparseMatrix SparseMatrix_make_undirected(SparseMatrix A)
SparseMatrix SparseMatrix_copy(SparseMatrix A)
SparseMatrix SparseMatrix_set_entries_to_real_one(SparseMatrix A)
SparseMatrix SparseMatrix_get_real_adjacency_matrix_symmetrized(SparseMatrix A)
SparseMatrix SparseMatrix_sort(SparseMatrix A)
SparseMatrix SparseMatrix_sum_repeat_entries(SparseMatrix A)
SparseMatrix SparseMatrix_add(SparseMatrix A, SparseMatrix B)
SparseMatrix SparseMatrix_from_coordinate_arrays(int nz, int m, int n, int *irn, int *jcn, void *val, int type, size_t sz)
SparseMatrix SparseMatrix_multiply3(SparseMatrix A, SparseMatrix B, SparseMatrix C)
SparseMatrix SparseMatrix_apply_fun(SparseMatrix A, double(*fun)(double x))
bool SparseMatrix_has_diagonal(SparseMatrix A)
int * SparseMatrix_weakly_connected_components(SparseMatrix A0, int *ncomp, int **comps)
SparseMatrix SparseMatrix_from_coordinate_format_not_compacted(SparseMatrix A)
@ UNMASKED
@ MASKED
SparseMatrix SparseMatrix_remove_diagonal(SparseMatrix A)
SparseMatrix SparseMatrix_new(int m, int n, int nz, int type, int format)
@ SUM_REPEATED_ALL
@ SUM_REPEATED_NONE
SparseMatrix SparseMatrix_from_dense(int m, int n, double *x)
@ BIPARTITE_PATTERN_UNSYM
@ BIPARTITE_UNSYM
@ BIPARTITE_RECT
@ BIPARTITE_ALWAYS
expr procedure type
Definition exparse.y:211
#define A(n, t)
Definition expr.h:76
GVIO_API const char * format
Definition gvio.h:51
#define B
Definition hierarchy.c:117
#define C
Definition pack.c:30