From: Matthew Fernandez Date: Sat, 12 Jun 2021 04:24:23 +0000 (-0700) Subject: remove function pointer argument to power_method X-Git-Tag: 2.48.0~46^2~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=40ca8873ed9e1a55dfad183d8bc0233edbc637bf;p=graphviz remove function pointer argument to power_method This function is only ever called with matvec_sparse, so we can simplify it by just calling this function directly. This is also a minor optimization. --- diff --git a/cmd/gvmap/country_graph_coloring.c b/cmd/gvmap/country_graph_coloring.c index dec42c234..e60bee50c 100644 --- a/cmd/gvmap/country_graph_coloring.c +++ b/cmd/gvmap/country_graph_coloring.c @@ -305,7 +305,7 @@ static void country_graph_coloring_internal(int seed, SparseMatrix A, int **p, r real tol = 0.00001; real eig, *eigv; eigv = &eig; - power_method(matvec_sparse, L, L->n, 1, seed, maxit, tol, &v, &eigv); + power_method(L, L->n, 1, seed, maxit, tol, &v, &eigv); } vector_ordering(n, v, p, TRUE); diff --git a/cmd/gvmap/power.c b/cmd/gvmap/power.c index c62681421..d14b83ff5 100644 --- a/cmd/gvmap/power.c +++ b/cmd/gvmap/power.c @@ -11,8 +11,8 @@ #include "power.h" #include -void power_method(void (*matvec)(void *, real*, real **, int, int*), - void *A, int n, int K, int random_seed, int maxit, real tol, real **eigv, real **eigs){ +void power_method(void *A, int n, int K, int random_seed, int maxit, real tol, + real **eigv, real **eigs){ /* find k-largest eigenvectors of a matrix A. Result in eigv. if eigv == NULL; memory will be allocated. maxium of maxit iterations will be done, and tol is the convergence criterion @@ -20,7 +20,6 @@ void power_method(void (*matvec)(void *, real*, real **, int, int*), next largest eigenvalues separate from the largest ones input: - matvec: a function point that takes a matrix M and a vector u, produce v = M.u A: the matrix n: dimension of matrix A K: number of eigenes to find @@ -90,7 +89,7 @@ void power_method(void (*matvec)(void *, real*, real **, int, int*), u[i] = u[i] - uij *v[j][i]; } } - matvec(A, u, &vv, FALSE, &flag); + matvec_sparse(A, u, &vv, FALSE, &flag); assert(!flag); unorm = vector_product(n, vv, vv);/* ||u||^2 */ diff --git a/cmd/gvmap/power.h b/cmd/gvmap/power.h index 28690fdb3..80ccd2e61 100644 --- a/cmd/gvmap/power.h +++ b/cmd/gvmap/power.h @@ -13,9 +13,8 @@ #include -/* if you have a standard sparse matrix, set matvec to matvec_sparse*/ -void power_method(void (*matvec)(void *M, real *u, real **v, int transposed, int *flag), - void *A, int n, int K, int random_seed, int maxit, real tol, real **eigv, real **eigs); +void power_method(void *A, int n, int K, int random_seed, int maxit, real tol, + real **eigv, real **eigs); void matvec_sparse(void *M, real *u, real **v, int transposed, int *flag);