Skip to content

Commit

Permalink
Add more tests covering 2D sum in Fortran
Browse files Browse the repository at this point in the history
  • Loading branch information
mcopik committed Oct 12, 2023
1 parent 0fcbce5 commit 81786a8
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion tests/fortran/sum_to_loop_offset.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,52 @@ def test_fortran_frontend_sum2loop_1d_offset():
assert res[1] == (1 + size) * size / 2
assert res[2] == (2 + size - 1) * (size - 2) / 2

def test_fortran_frontend_arr2loop_2d():
"""
Tests that the generated array map correctly handles offsets.
"""
test_string = """
PROGRAM index_offset_test
implicit none
double precision, dimension(5,3) :: d
double precision, dimension(4) :: res
CALL index_test_function(d,res)
end
SUBROUTINE index_test_function(d, res)
double precision, dimension(5,3) :: d
double precision, dimension(4) :: res
!res(1) = SUM(d)
res(2) = SUM(d(:,:))
res(3) = SUM(d(2:4, 2))
res(4) = SUM(d(2:4, 2:3))
END SUBROUTINE index_test_function
"""

# Now test to verify it executes correctly with no offset normalization

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

sizes = [5, 3]
d = np.full(sizes, 42, order="F", dtype=np.float64)
cnt = 0
for i in range(sizes[0]):
for j in range(sizes[1]):
d[i, j] = cnt
cnt += 1
res = np.full([4], 42, order="F", dtype=np.float64)
sdfg(d=d, res=res)
assert res[1] == 105
assert res[2] == 21
assert res[3] == 45

if __name__ == "__main__":

test_fortran_frontend_sum2loop_1d_without_offset()
test_fortran_frontend_sum2loop_1d_offset()
test_fortran_frontend_arr2loop_2d()
#test_fortran_frontend_arr2loop_2d_offset()
#test_fortran_frontend_arr2loop_without_offset()

0 comments on commit 81786a8

Please sign in to comment.