Skip to content

Commit

Permalink
Add more tests for Fortran sum over 2D arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
mcopik committed Oct 12, 2023
1 parent 6544673 commit bd21926
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion tests/fortran/sum_to_loop_offset.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,51 @@ def test_fortran_frontend_arr2loop_2d():
assert res[2] == 21
assert res[3] == 45

def test_fortran_frontend_arr2loop_2d_offset():
"""
Tests that the generated array map correctly handles offsets.
"""
test_string = """
PROGRAM index_offset_test
implicit none
double precision, dimension(2:6,7:10) :: d
double precision, dimension(3) :: res
CALL index_test_function(d,res)
end
SUBROUTINE index_test_function(d, res)
double precision, dimension(2:6,7:10) :: d
double precision, dimension(3) :: res
res(1) = SUM(d)
res(2) = SUM(d(:,:))
res(3) = SUM(d(3:5, 8:9))
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, 4]
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([3], 42, order="F", dtype=np.float64)
sdfg(d=d, res=res)
assert res[0] == 190
assert res[1] == 190
assert res[2] == 57

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_2d_offset()

0 comments on commit bd21926

Please sign in to comment.