Skip to content

Commit

Permalink
rename new utility to 'normalize_array_shape_and_access'
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelSt98 committed Dec 19, 2023
1 parent 1e88158 commit ff67104
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
5 changes: 2 additions & 3 deletions loki/transform/fortran_c_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from loki.transform.transform_array_indexing import (

Check failure on line 12 in loki/transform/fortran_c_transform.py

View workflow job for this annotation

GitHub Actions / code checks (3.11)

W0611: Unused normalize_range_indexing imported from loki.transform.transform_array_indexing (unused-import)
shift_to_zero_indexing, invert_array_indices,
resolve_vector_notation, normalize_range_indexing,
normalize_array_access, flatten_arrays
normalize_array_shape_and_access, flatten_arrays
)
from loki.transform.transform_associates import resolve_associates
from loki.transform.transform_utilities import (
Expand Down Expand Up @@ -368,8 +368,7 @@ def generate_c_kernel(self, routine, **kwargs):

# Clean up Fortran vector notation
resolve_vector_notation(kernel)
normalize_array_access(kernel)
normalize_range_indexing(kernel)
normalize_array_shape_and_access(kernel)

# Convert array indexing to C conventions
# TODO: Resolve reductions (eg. SUM(myvar(:)))
Expand Down
4 changes: 2 additions & 2 deletions loki/transform/transform_array_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
'resolve_vector_notation', 'normalize_range_indexing',
'promote_variables', 'promote_nonmatching_variables',
'promotion_dimensions_from_loop_nest', 'demote_variables',
'flatten_arrays', 'normalize_array_access'
'flatten_arrays', 'normalize_array_shape_and_access'
]


Expand Down Expand Up @@ -498,7 +498,7 @@ def demote_variables(routine, variable_names, dimensions):

info(f'[Loki::Transform] Demoted variables in {routine.name}: {", ".join(variable_names)}')

def normalize_array_access(routine):
def normalize_array_shape_and_access(routine):
"""
Shift all arrays to start counting at "1"
"""
Expand Down
18 changes: 7 additions & 11 deletions tests/test_transform_array_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from loki.transform import (
promote_variables, demote_variables, normalize_range_indexing,
invert_array_indices, flatten_arrays,
normalize_array_access
normalize_array_shape_and_access
)
from loki.transform import (
FortranCTransformation
Expand Down Expand Up @@ -328,14 +328,14 @@ def test_transform_demote_dimension_arguments(here, frontend):

@pytest.mark.parametrize('frontend', available_frontends())
@pytest.mark.parametrize('start_index', (0, 1, 5))
def test_transform_normalize_array_access(here, frontend, start_index):
def test_transform_normalize_array_shape_and_access(here, frontend, start_index):
"""
Test flattening or arrays, meaning converting multi-dimensional
arrays to one-dimensional arrays including corresponding
index arithmetic.
"""
fcode = f"""
subroutine transform_normalize_array_access(x1, x2, x3, x4, l1, l2, l3, l4)
subroutine transform_normalize_array_shape_and_access(x1, x2, x3, x4, l1, l2, l3, l4)
implicit none
integer :: i1, i2, i3, i4, c1, c2, c3, c4
integer, intent(in) :: l1, l2, l3, l4
Expand Down Expand Up @@ -369,7 +369,7 @@ def test_transform_normalize_array_access(here, frontend, start_index):
c1 = c1 + 1
end do
end subroutine transform_normalize_array_access
end subroutine transform_normalize_array_shape_and_access
"""
def init_arguments(l1, l2, l3, l4):
x1 = np.zeros(shape=(l1,), order='F', dtype=np.int32)
Expand All @@ -396,7 +396,7 @@ def validate_routine(routine):
clean_test(filepath)

routine = Subroutine.from_source(fcode, frontend=frontend)
normalize_array_access(routine)
normalize_array_shape_and_access(routine)
normalize_range_indexing(routine)
filepath = here/(f'{routine.name}_normalized_{frontend}.f90')
function = jit_compile(routine, filepath=filepath, objname=routine.name)
Expand Down Expand Up @@ -460,10 +460,6 @@ def init_arguments(l1, l2, l3, l4, flattened=False):
x2 = np.zeros(shape=(l2*l1) if flattened else (l2,l1,), order='F', dtype=np.int32)
x3 = np.zeros(shape=(l3*l2*l1) if flattened else (l3,l2,l1,), order='F', dtype=np.int32)
x4 = np.zeros(shape=(l4*l3*l2*l1) if flattened else (l4,l3,l2,l1,), order='F', dtype=np.int32)
#x1 = np.zeros(shape=(l1,), order='F', dtype=np.int32)
#x2 = np.zeros(shape=(l2*l1) if flattened else (l1,l2), order='F', dtype=np.int32)
#x3 = np.zeros(shape=(l3*l2*l1) if flattened else (l1,l2,l3), order='F', dtype=np.int32)
#x4 = np.zeros(shape=(l4*l3*l2*l1) if flattened else (l1,l2,l3,l4), order='F', dtype=np.int32)
return x1, x2, x3, x4

def validate_routine(routine):
Expand All @@ -486,7 +482,7 @@ def validate_routine(routine):

# Test flattening order='F'
f_routine = Subroutine.from_source(fcode, frontend=frontend)
normalize_array_access(f_routine)
normalize_array_shape_and_access(f_routine)
normalize_range_indexing(f_routine) # Fix OMNI nonsense
flatten_arrays(routine=f_routine, order='F', start_index=1)
filepath = here/(f'{f_routine.name}_{start_index}_flattened_F_{frontend}.f90')
Expand All @@ -503,7 +499,7 @@ def validate_routine(routine):

# Test flattening order='C'
c_routine = Subroutine.from_source(fcode, frontend=frontend)
normalize_array_access(c_routine)
normalize_array_shape_and_access(c_routine)
normalize_range_indexing(c_routine) # Fix OMNI nonsense
invert_array_indices(c_routine)
flatten_arrays(routine=c_routine, order='C', start_index=1)
Expand Down

0 comments on commit ff67104

Please sign in to comment.