Skip to content

Commit

Permalink
Add test verifying that Fortran offset normalizer works for 1D and 2D…
Browse files Browse the repository at this point in the history
… arrays
  • Loading branch information
mcopik committed Sep 8, 2023
1 parent c5ce575 commit 2436051
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions tests/fortran/offset_normalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,62 @@ def test_fortran_frontend_offset_normalizer_2d():
for j in range(0,3):
assert a[i, j] == (50+i) * 2 + 3 * (7 + j)

def test_fortran_frontend_offset_normalizer_2d_arr2loop():
"""
Tests that the Fortran frontend can parse array accesses and that the accessed indices are correct.
"""
test_string = """
PROGRAM index_offset_test
implicit none
double precision, dimension(50:54,7:9) :: d
CALL index_test_function(d)
end
SUBROUTINE index_test_function(d)
double precision, dimension(50:54,7:9) :: d
do i=50,54
d(i, :) = i * 2.0
end do
END SUBROUTINE index_test_function
"""

# Test to verify that offset is normalized correctly
ast, own_ast = fortran_parser.create_ast_from_string(test_string, "index_offset_test", True, True)

for subroutine in ast.subroutine_definitions:

loop = subroutine.execution_part.execution[1]
nested_loop = loop.body.execution[1]

idx = nested_loop.body.execution[1]
assert idx.lval.name == 'tmp_index_0'
assert idx.rval.rval.value == "50"

idx2 = nested_loop.body.execution[3]
assert idx2.lval.name == 'tmp_index_1'
assert idx2.rval.rval.value == "7"

# Now test to verify it executes correctly with no normalization

sdfg = fortran_parser.create_sdfg_from_string(test_string, "index_offset_test", True)
sdfg.save('test.sdfg')
sdfg.simplify(verbose=True)
sdfg.compile()

assert len(sdfg.data('d').shape) == 2
assert sdfg.data('d').shape[0] == 5
assert sdfg.data('d').shape[1] == 3

a = np.full([5,3], 42, order="F", dtype=np.float64)
sdfg(d=a)
for i in range(0,5):
for j in range(0,3):
assert a[i, j] == (50 + i) * 2

if __name__ == "__main__":

test_fortran_frontend_offset_normalizer_1d()
test_fortran_frontend_offset_normalizer_2d()
test_fortran_frontend_offset_normalizer_2d_arr2loop()

0 comments on commit 2436051

Please sign in to comment.