-
Notifications
You must be signed in to change notification settings - Fork 5
/
eigs_lapack.c
35 lines (30 loc) · 929 Bytes
/
eigs_lapack.c
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
#include <cblas.h>
#include <arpack.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <lapacke.h>
#include "eigs.h"
#include "util.h"
static void all_eigenvalues(double *A, int n, double *ret_eigenvalues) {
int lda = n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < i-1; j++) {
A[i*n + j] = A[j*n + i];
}
}
for (int i = 0; i < n; i++) {
A[i*n + i] *= 2;
}
lapack_int info = LAPACKE_dsyev(LAPACK_ROW_MAJOR, 'V', 'U', n, A, lda, ret_eigenvalues);
/* Check for convergence */
if (info > 0) {
fprintf(stderr, "\033[31mWARNING: The algorithm failed to compute eigenvalues.\033[0m\n");
exit(1);
}
}
void smallest_eigenvalues(double *A, int n, int k, double *ret_eigenvalues, double *ret_eigenvectors) {
all_eigenvalues(A, n, ret_eigenvalues);
copy_submatrix(A, n, n, k, ret_eigenvectors);
}