Skip to content

Commit

Permalink
Make random matrices more complex
Browse files Browse the repository at this point in the history
Previously random matrices were random but real valued even for the
complex matrix types. This change makes the random complex matrices
also random for the complex part of the matrix elements.

Signed-off-by: Nicolas Bock <[email protected]>
  • Loading branch information
nicolasbock committed Aug 22, 2019
1 parent 4f3416b commit 6a75f78
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
12 changes: 10 additions & 2 deletions src/C-interface/dense/bml_allocate_dense_typed.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#include "magma_v2.h"
#endif

#define __USE_MISC
#include <math.h>

#include <complex.h>
#include <string.h>
#include <stdio.h>
Expand Down Expand Up @@ -158,11 +161,16 @@ bml_matrix_dense_t *TYPED_FUNC(
{
for (int j = 0; j < N; j++)
{
double angle = rand() / (double) RAND_MAX * 2 * M_PI;
#ifdef BML_USE_MAGMA
A_dense[ROWMAJOR(i, j, N, N)] =
MAGMACOMPLEX(MAKE) (rand() / (double) RAND_MAX, 0.);
MAGMACOMPLEX(MAKE) (cos(angle), sin(angle));
#else
A_dense[ROWMAJOR(i, j, N, N)] = rand() / (double) RAND_MAX;
#if defined(BML_COMPLEX) && (defined(SINGLE_COMPLEX) || defined(DOUBLE_COMPLEX))
A_dense[ROWMAJOR(i, j, N, N)] = cos(angle) + sin(angle) * I;
#else
A_dense[ROWMAJOR(i, j, N, N)] = cos(angle);
#endif
#endif
}
}
Expand Down
12 changes: 10 additions & 2 deletions src/C-interface/ellblock/bml_allocate_ellblock_typed.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
#include "bml_allocate_ellblock.h"
#include "bml_types_ellblock.h"

#include <complex.h>
#define __USE_MISC
#include <math.h>

#include <complex.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
Expand Down Expand Up @@ -179,8 +181,14 @@ bml_matrix_ellblock_t *TYPED_FUNC(
for (int ii = 0; ii < bsize[ib]; ii++)
for (int jj = 0; jj < bsize[jb]; jj++)
{
double angle = rand() / (double) RAND_MAX * 2 * M_PI;
#if defined(BML_COMPLEX) && (defined(SINGLE_COMPLEX) || defined(DOUBLE_COMPLEX))
A_value[ROWMAJOR(ii, jj, bsize[ib], bsize[jb])] =
rand() / (REAL_T) RAND_MAX;
cos(angle) + sin(angle) * I;
#else
A_value[ROWMAJOR(ii, jj, bsize[ib], bsize[jb])] =
cos(angle);
#endif
}
}
A_nnzb[ib] = MB;
Expand Down
11 changes: 9 additions & 2 deletions src/C-interface/ellpack/bml_allocate_ellpack_typed.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
#include "bml_allocate_ellpack.h"
#include "bml_types_ellpack.h"

#include <complex.h>
#define __USE_MISC
#include <math.h>

#include <complex.h>
#include <stdlib.h>
#include <string.h>

Expand Down Expand Up @@ -183,7 +185,12 @@ bml_matrix_ellpack_t *TYPED_FUNC(
int jind = 0;
for (int j = 0; j < M; j++)
{
A_value[ROWMAJOR(i, jind, N, M)] = rand() / (REAL_T) RAND_MAX;
double angle = rand() / (double) RAND_MAX * 2 * M_PI;
#if defined(BML_COMPLEX) && (defined(SINGLE_COMPLEX) || defined(DOUBLE_COMPLEX))
A_value[ROWMAJOR(i, jind, N, M)] = cos(angle) + sin(angle) * I;
#else
A_value[ROWMAJOR(i, jind, N, M)] = cos(angle);
#endif
A_index[ROWMAJOR(i, jind, N, M)] = j;
jind++;
}
Expand Down
11 changes: 9 additions & 2 deletions src/C-interface/ellsort/bml_allocate_ellsort_typed.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
#include "bml_allocate_ellsort.h"
#include "bml_types_ellsort.h"

#include <complex.h>
#define __USE_MISC
#include <math.h>

#include <complex.h>
#include <stdlib.h>
#include <string.h>

Expand Down Expand Up @@ -138,7 +140,12 @@ bml_matrix_ellsort_t *TYPED_FUNC(
for (int j = (i - M / 2 >= 0 ? i - M / 2 : 0);
j < (i - M / 2 + M <= N ? i - M / 2 + M : N); j++)
{
A_value[ROWMAJOR(i, jind, N, M)] = rand() / (REAL_T) RAND_MAX;
double angle = rand() / (double) RAND_MAX * 2 * M_PI;
#if defined(BML_COMPLEX) && (defined(SINGLE_COMPLEX) || defined(DOUBLE_COMPLEX))
A_value[ROWMAJOR(i, jind, N, M)] = cos(angle) + sin(angle) * I;
#else
A_value[ROWMAJOR(i, jind, N, M)] = cos(angle);
#endif
A_index[ROWMAJOR(i, jind, N, M)] = j;
jind++;
}
Expand Down

0 comments on commit 6a75f78

Please sign in to comment.