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);
#include "power.h"
#include <sparse/SparseMatrix.h>
-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
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
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 */
#include <sparse/general.h>
-/* 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);