From cd557bd70c0bf8016e0194463673844c5de154b7 Mon Sep 17 00:00:00 2001 From: Nicolas Bock Date: Thu, 13 Feb 2020 06:39:04 -0700 Subject: [PATCH] Introduce complex conjugate for dense Signed-off-by: Nicolas Bock --- src/C-interface/bml_transpose.c | 22 +++++++++++++ src/C-interface/bml_transpose.h | 3 +- src/C-interface/dense/bml_transpose_dense.c | 31 +++++++++++++++++++ src/C-interface/dense/bml_transpose_dense.h | 15 +++++++++ .../dense/bml_transpose_dense_typed.c | 29 +++++++++++++++++ 5 files changed, 99 insertions(+), 1 deletion(-) diff --git a/src/C-interface/bml_transpose.c b/src/C-interface/bml_transpose.c index b2265b817..e684e7eea 100644 --- a/src/C-interface/bml_transpose.c +++ b/src/C-interface/bml_transpose.c @@ -70,3 +70,25 @@ bml_transpose( break; } } + +/** Complex conjugate of a matrix. + * + * \ingroup transpose_group_C + * + * \param A Matrix to be complex conjugated + * \return Complex conjugate of A + */ +void +bml_complex_conjugate( + bml_matrix_t * A) +{ + switch (bml_get_type(A)) + { + case dense: + bml_complex_conjugate_dense(A); + break; + default: + LOG_ERROR("unknown matrix type\n"); + break; + } +} diff --git a/src/C-interface/bml_transpose.h b/src/C-interface/bml_transpose.h index 19ac962c1..d52b5907d 100644 --- a/src/C-interface/bml_transpose.h +++ b/src/C-interface/bml_transpose.h @@ -5,11 +5,12 @@ #include "bml_types.h" -// Transpose A - B = A^T bml_matrix_t *bml_transpose_new( bml_matrix_t * A); void bml_transpose( bml_matrix_t * A); +void bml_complex_conjugate(bml_matrix_t * A); + #endif diff --git a/src/C-interface/dense/bml_transpose_dense.c b/src/C-interface/dense/bml_transpose_dense.c index 8668591a9..2c8e3465c 100644 --- a/src/C-interface/dense/bml_transpose_dense.c +++ b/src/C-interface/dense/bml_transpose_dense.c @@ -73,3 +73,34 @@ bml_transpose_dense( break; } } + +/** Complex conjugate a matrix in place. + * + * \ingroup transpose_group + * + * \param A The matrix to be complex conjugated + * \return Complex conjugate of A + */ +void +bml_complex_conjugate_dense( + bml_matrix_dense_t * A) +{ + switch (A->matrix_precision) + { + case single_real: + bml_complex_conjugate_dense_single_real(A); + break; + case double_real: + bml_complex_conjugate_dense_double_real(A); + break; + case single_complex: + bml_complex_conjugate_dense_single_complex(A); + break; + case double_complex: + bml_complex_conjugate_dense_double_complex(A); + break; + default: + LOG_ERROR("unknown precision\n"); + break; + } +} diff --git a/src/C-interface/dense/bml_transpose_dense.h b/src/C-interface/dense/bml_transpose_dense.h index a3b897df0..d4ee08200 100644 --- a/src/C-interface/dense/bml_transpose_dense.h +++ b/src/C-interface/dense/bml_transpose_dense.h @@ -33,4 +33,19 @@ void bml_transpose_dense_single_complex( void bml_transpose_dense_double_complex( bml_matrix_dense_t * A); +void bml_complex_conjugate_dense( + bml_matrix_dense_t * A); + +void bml_complex_conjugate_dense_single_real( + bml_matrix_dense_t * A); + +void bml_complex_conjugate_dense_double_real( + bml_matrix_dense_t * A); + +void bml_complex_conjugate_dense_single_complex( + bml_matrix_dense_t * A); + +void bml_complex_conjugate_dense_double_complex( + bml_matrix_dense_t * A); + #endif diff --git a/src/C-interface/dense/bml_transpose_dense_typed.c b/src/C-interface/dense/bml_transpose_dense_typed.c index 04e7753b6..06908b4cc 100644 --- a/src/C-interface/dense/bml_transpose_dense_typed.c +++ b/src/C-interface/dense/bml_transpose_dense_typed.c @@ -105,3 +105,32 @@ void TYPED_FUNC( } #endif } + +/** Complex conjugate of a matrix. + * + * \ingroup transpose_group_C + * + * \param A Matrix to be complex conjugated + * \return Complex conjugate of A + */ +void TYPED_FUNC( + bml_complex_conjugate_dense) ( + bml_matrix_dense_t * A) +{ + int N = A->N; + + REAL_T *A_matrix = A->matrix; + REAL_T tmp; + +#if defined(SINGLE_REAL) || defined(DOUBLE_REAL) + return; +#else +#pragma omp parallel for \ + private(tmp) \ + shared(N, A_matrix) + for (int i = 0; i < N * N; i++) + { + A_matrix[i] = COMPLEX_CONJUGATE(A_matrix[i]); + } +#endif +}