@@ -1970,3 +1970,64 @@ def test_source_sanitize_fp_module(preprocess):
19701970
19711971
19721972# TODO: Add tests for source sanitizer with other frontends
1973+
1974+
1975+ @pytest .mark .parametrize ('frontend' , available_frontends (xfail = [(OMNI , 'OMNI does not like Loki pragmas, yet!' )]))
1976+ def test_frontend_routine_variables_dimension_pragmas (frontend ):
1977+ """
1978+ Test that `!$loki dimension` pragmas can be used to verride the
1979+ conceptual `.shape` of local and argument variables.
1980+ """
1981+ fcode = """
1982+ subroutine routine_variables_dimensions(x, y, v0, v1, v2, v3, v4)
1983+ integer, parameter :: jprb = selected_real_kind(13,300)
1984+ integer, intent(in) :: x, y
1985+
1986+ !$loki dimension(10)
1987+ real(kind=jprb), intent(inout) :: v0(:)
1988+ !$loki dimension(x)
1989+ real(kind=jprb), intent(inout) :: v1(:)
1990+ !$loki dimension(x,y,:)
1991+ real(kind=jprb), dimension(:,:,:), intent(inout) :: v2, v3
1992+ !$loki dimension(x,y)
1993+ real(kind=jprb), pointer, intent(inout) :: v4(:,:)
1994+ !$loki dimension(x+y,2*x)
1995+ real(kind=jprb), allocatable :: v5(:,:)
1996+ !$loki dimension(x/2, x**2, (x+y)/x)
1997+ real(kind=jprb), dimension(:, :, :), pointer :: v6
1998+
1999+ end subroutine routine_variables_dimensions
2000+ """
2001+ def to_str (expr ):
2002+ return str (expr ).lower ().replace (' ' , '' )
2003+
2004+ routine = Subroutine .from_source (fcode , frontend = frontend )
2005+ assert routine .variable_map ['v0' ].shape [0 ] == 10
2006+ assert isinstance (routine .variable_map ['v0' ].shape [0 ], sym .IntLiteral )
2007+ assert isinstance (routine .variable_map ['v1' ].shape [0 ], sym .Scalar )
2008+ assert routine .variable_map ['v2' ].shape [0 ] == 'x'
2009+ assert routine .variable_map ['v2' ].shape [1 ] == 'y'
2010+ assert routine .variable_map ['v2' ].shape [2 ] == ':'
2011+ assert isinstance (routine .variable_map ['v2' ].shape [0 ], sym .Scalar )
2012+ assert isinstance (routine .variable_map ['v2' ].shape [1 ], sym .Scalar )
2013+ assert isinstance (routine .variable_map ['v2' ].shape [2 ], sym .RangeIndex )
2014+ assert routine .variable_map ['v3' ].shape [0 ] == 'x'
2015+ assert routine .variable_map ['v3' ].shape [1 ] == 'y'
2016+ assert routine .variable_map ['v3' ].shape [2 ] == ':'
2017+ assert isinstance (routine .variable_map ['v3' ].shape [0 ], sym .Scalar )
2018+ assert isinstance (routine .variable_map ['v3' ].shape [1 ], sym .Scalar )
2019+ assert isinstance (routine .variable_map ['v3' ].shape [2 ], sym .RangeIndex )
2020+ assert routine .variable_map ['v4' ].shape [0 ] == 'x'
2021+ assert routine .variable_map ['v4' ].shape [1 ] == 'y'
2022+ assert isinstance (routine .variable_map ['v4' ].shape [0 ], sym .Scalar )
2023+ assert isinstance (routine .variable_map ['v4' ].shape [1 ], sym .Scalar )
2024+ assert to_str (routine .variable_map ['v5' ].shape [0 ]) == 'x+y'
2025+ assert to_str (routine .variable_map ['v5' ].shape [1 ]) == '2*x'
2026+ assert isinstance (routine .variable_map ['v5' ].shape [0 ], sym .Sum )
2027+ assert isinstance (routine .variable_map ['v5' ].shape [1 ], sym .Product )
2028+ assert to_str (routine .variable_map ['v6' ].shape [0 ]) == 'x/2'
2029+ assert to_str (routine .variable_map ['v6' ].shape [1 ]) == 'x**2'
2030+ assert to_str (routine .variable_map ['v6' ].shape [2 ]) == '(x+y)/x'
2031+ assert isinstance (routine .variable_map ['v6' ].shape [0 ], sym .Quotient )
2032+ assert isinstance (routine .variable_map ['v6' ].shape [1 ], sym .Power )
2033+ assert isinstance (routine .variable_map ['v6' ].shape [2 ], sym .Quotient )
0 commit comments