Skip to content

Commit

Permalink
More fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasbock committed Aug 10, 2017
1 parent 351986c commit 7e935de
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/Fortran-interface/bml_c_interface_m.F90
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ function bml_get_row_C(a, i) bind(C, name="bml_get_row")
import :: C_PTR, C_INT, C_double
type(C_PTR), value, intent(in) :: a
integer(C_INT), value, intent(in) :: i
real(C_DOUBLE) :: bml_get_row_C(*)
type(C_PTR) :: bml_get_row_C
end function bml_get_row_C

subroutine bml_get_diagonal_C(a, diagonal) bind(C, name="bml_get_diagonal")
Expand Down
31 changes: 23 additions & 8 deletions src/Fortran-interface/bml_getters_m.F90
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,15 @@ end subroutine bml_get_diagonal_double_complex
!! \param row The row that is extracted
subroutine bml_get_row_single_real(a, i, row)

use bml_introspection_m

type(bml_matrix_t), intent(in) :: a
integer(C_INT), intent(in) :: i
real(C_FLOAT), target, intent(out) :: row(*)
real(C_FLOAT), target, intent(out) :: row(:)
real(C_FLOAT), pointer :: row_ptr(:)

!call bml_get_row_C(a%ptr, i-1, c_loc(row))
call c_f_pointer(bml_get_row_C(a%ptr, i-1), row_ptr, [bml_get_N(a)])
row = row_ptr

end subroutine bml_get_row_single_real

Expand All @@ -96,12 +100,15 @@ end subroutine bml_get_row_single_real
!! \param row The row that is extracted
subroutine bml_get_row_double_real(a, i, row)

use bml_introspection_m

type(bml_matrix_t), intent(in) :: a
integer(C_INT), intent(in) :: i
real(C_DOUBLE), target, intent(inout) :: row(:)
real(C_DOUBLE), pointer :: row_ptr
real(C_DOUBLE), pointer :: row_ptr(:)

row_ptr => bml_get_row_C(a%ptr, i-1)
call c_f_pointer(bml_get_row_C(a%ptr, i-1), row_ptr, [bml_get_N(a)])
row = row_ptr

end subroutine bml_get_row_double_real

Expand All @@ -111,11 +118,15 @@ end subroutine bml_get_row_double_real
!! \param row The row that is extracted
subroutine bml_get_row_single_complex(a, i, row)

use bml_introspection_m

type(bml_matrix_t), intent(in) :: a
integer(C_INT), intent(in) :: i
complex(C_FLOAT_COMPLEX), target, intent(out) :: row(*)
complex(C_FLOAT_COMPLEX), target, intent(out) :: row(:)
complex(C_FLOAT_COMPLEX), pointer :: row_ptr(:)

!call bml_get_row_C(a%ptr, i-1, c_loc(row))
call c_f_pointer(bml_get_row_C(a%ptr, i-1), row_ptr, [bml_get_N(a)])
row = row_ptr

end subroutine bml_get_row_single_complex

Expand All @@ -125,11 +136,15 @@ end subroutine bml_get_row_single_complex
!! \param row The row that is extracted
subroutine bml_get_row_double_complex(a, i, row)

use bml_introspection_m

type(bml_matrix_t), intent(in) :: a
integer(C_INT), intent(in) :: i
complex(C_DOUBLE_COMPLEX), target, intent(out) :: row(*)
complex(C_DOUBLE_COMPLEX), target, intent(out) :: row(:)
complex(C_DOUBLE_COMPLEX), pointer :: row_ptr(:)

!call bml_get_row_C(a%ptr, i-1, c_loc(row))
call c_f_pointer(bml_get_row_C(a%ptr, i-1), row_ptr, [bml_get_N(a)])
row = row_ptr

end subroutine bml_get_row_double_complex

Expand Down
1 change: 1 addition & 0 deletions temp/test_getters.F90
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ program test_getters

do i = 1, N
call bml_get_row(A, i, row)
call print_dense_vector(row)
do j = 1, N
rel_diff = abs((A_dense(i, j) - row(j)) / A_dense(i, j))
if (rel_diff > REL_TOL) then
Expand Down
39 changes: 31 additions & 8 deletions temp/test_getters.c
Original file line number Diff line number Diff line change
@@ -1,35 +1,58 @@
#include "macros.h"
#include "../macros.h"

#include <bml.h>
#include <math.h>
#include <stdlib.h>

//#define SINGLE_REAL
//#define DOUBLE_REAL
//#define SINGLE_COMPLEX
#define DOUBLE_COMPLEX

#ifdef SINGLE_REAL
#define REAL_T float
#define BML_T single_real
#define ABS fabsf
#elif defined(DOUBLE_REAL)
#define REAL_T double
#define BML_T double_real
#define ABS fabs
#elif defined(SINGLE_COMPLEX)
#define REAL_T complex float
#define BML_T single_complex
#define ABS cabsf
#elif defined(DOUBLE_COMPLEX)
#define REAL_T complex double
#define BML_T double_complex
#define ABS cabs
#endif

#define REL_TOL 1e-12
#define N 11
#define M 11

int main(int argc, char **argv)
{
bml_matrix_t *A = NULL;
double *A_dense = NULL;
REAL_T *A_dense = NULL;

A_dense = calloc(N * N, sizeof(double));
A_dense = calloc(N * N, sizeof(REAL_T));

for (int i = 0; i < N * N; i++)
{
A_dense[i] = (double) (rand() / (double) RAND_MAX);
A_dense[i] = (REAL_T) (rand() / (REAL_T) RAND_MAX);
}

A = bml_import_from_dense(dense, double_real, dense_row_major,
A = bml_import_from_dense(dense, BML_T, dense_row_major,
N, M, A_dense, 0.0, sequential);

for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
double *Aij = bml_get(A, i, j);
double expected = A_dense[ROWMAJOR(i, j, N, N)];
double rel_diff = fabs((expected - *Aij) / expected);
REAL_T *Aij = bml_get(A, i, j);
REAL_T expected = A_dense[ROWMAJOR(i, j, N, N)];
double rel_diff = ABS((expected - *Aij) / expected);
if (rel_diff > REL_TOL)
{
LOG_ERROR
Expand Down
1 change: 1 addition & 0 deletions tests/trace_matrix_typed.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "bml.h"
#include "../macros.h"
#include "../typed.h"

#include <complex.h>
Expand Down
Empty file modified update_tags.sh
100644 → 100755
Empty file.

0 comments on commit 7e935de

Please sign in to comment.