Skip to content

Commit

Permalink
[WIP] Fix diagonalize test
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas Bock <[email protected]>
  • Loading branch information
nicolasbock committed Aug 22, 2019
1 parent 5787e74 commit 954745b
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions tests/C-tests/diagonalize_matrix_typed.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,43 +38,44 @@ int TYPED_FUNC(
LOG_DEBUG("rel. tolerance = %e\n", REL_TOL);

A = bml_random_matrix(matrix_type, matrix_precision, N, M, sequential);
printf("A:\n");
bml_print_bml_matrix(A, 0, N, 0, N);

A_t = bml_transpose_new(A);
bml_add(A, A_t, 0.5, 0.5, 0.0);
bml_print_bml_matrix(A, 0, N, 0, N);

switch (matrix_precision)
{
case single_real:
eigenvalues = calloc(N, sizeof(float));
break;
case double_real:
eigenvalues = calloc(N, sizeof(double));
break;
case single_complex:
eigenvalues = calloc(N, sizeof(float complex));
break;
case double_complex:
eigenvalues = calloc(N, sizeof(double complex));
break;
default:
LOG_DEBUG("matrix_precision is not set");
break;
}
printf("A (symmetric):\n");
bml_print_bml_matrix(A, 0, N, 0, N);

eigenvalues = bml_allocate_memory(N * sizeof(REAL_T));
eigenvectors = bml_zero_matrix(matrix_type, matrix_precision,
N, M, sequential);

aux1 = bml_zero_matrix(matrix_type, matrix_precision, N, M, sequential);
aux2 = bml_zero_matrix(matrix_type, matrix_precision, N, M, sequential);

bml_print_bml_matrix(eigenvectors, 0, N, 0, N);

bml_diagonalize(A, eigenvalues, eigenvectors);

printf("%s\n", "eigenvectors");
printf("eigenvectors:\n");
bml_print_bml_matrix(eigenvectors, 0, N, 0, N);

printf("eigenvalues:\n");
for (int i = 0; i < N; i++)
{
#if defined(SINGLE_REAL)
printf(" % 1.3f", eigenvalues[i]);
#elif defined(SINGLE_COMPLEX)
printf(" % 1.3f%+1.3fi", REAL_PART(eigenvalues[i]),
IMAGINARY_PART(eigenvalues[i]));
#if defined(DOUBLE_REAL)
printf(" % 1.3e", eigenvalues[i]);
#elif defined(DOUBLE_COMPLEX)
printf(" % 1.3e%+1.3ei", REAL_PART(eigenvalues[i]),
IMAGINARY_PART(eigenvalues[i]));
#endif
}
printf("\n");

aux = bml_transpose_new(eigenvectors);

bml_set_diagonal(aux1, eigenvalues, 0.0);
Expand Down

0 comments on commit 954745b

Please sign in to comment.