From 954745ba40877c07f5a19d7a654ba6432f573a1f Mon Sep 17 00:00:00 2001 From: Nicolas Bock Date: Thu, 22 Aug 2019 06:07:09 -0600 Subject: [PATCH] [WIP] Fix diagonalize test Signed-off-by: Nicolas Bock --- tests/C-tests/diagonalize_matrix_typed.c | 45 ++++++++++++------------ 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/tests/C-tests/diagonalize_matrix_typed.c b/tests/C-tests/diagonalize_matrix_typed.c index 22901810b..d25926272 100644 --- a/tests/C-tests/diagonalize_matrix_typed.c +++ b/tests/C-tests/diagonalize_matrix_typed.c @@ -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);