Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to ignore specific dimensions in "shift to zero indexing" #236

Merged
merged 3 commits into from
Mar 25, 2024

Conversation

MichaelSt98
Copy link
Collaborator

allow to ignore specific dimensions ...

Copy link

github-actions bot commented Mar 4, 2024

Documentation for this branch can be viewed at https://sites.ecmwf.int/docs/loki/236/index.html

Copy link

codecov bot commented Mar 4, 2024

Codecov Report

Attention: Patch coverage is 93.59244% with 61 lines in your changes are missing coverage. Please review.

Project coverage is 92.71%. Comparing base (970e0b6) to head (1dc82a6).
Report is 53 commits behind head on main.

Files Patch % Lines
loki/bulk/item.py 92.44% 34 Missing ⚠️
loki/bulk/scheduler.py 95.48% 12 Missing ⚠️
loki/bulk/configure.py 90.52% 9 Missing ⚠️
loki/program_unit.py 81.81% 2 Missing ⚠️
loki/transform/build_system_transform.py 33.33% 2 Missing ⚠️
loki/sourcefile.py 83.33% 1 Missing ⚠️
transformations/transformations/data_offload.py 93.75% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #236      +/-   ##
==========================================
+ Coverage   92.47%   92.71%   +0.23%     
==========================================
  Files          95       95              
  Lines       17473    17828     +355     
==========================================
+ Hits        16159    16529     +370     
+ Misses       1314     1299      -15     
Flag Coverage Δ
lint_rules 96.22% <ø> (ø)
loki 92.71% <93.57%> (+0.27%) ⬆️
transformations 91.94% <94.44%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@reuterbal reuterbal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good. I've left two remarks about implementation and I think the docstring could be slightly improved maybe.

Comment on lines 57 to 60
shift = True
for var in FindVariables().visit(d):
if var in ignore:
shift = False
if shift:
new_dims += [d - sym.Literal(1)]
else:
new_dims += [d]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to propose a slightly streamlined alternative to avoid the explicit loop:

Suggested change
shift = True
for var in FindVariables().visit(d):
if var in ignore:
shift = False
if shift:
new_dims += [d - sym.Literal(1)]
else:
new_dims += [d]
if ignore and any(var in ignore for var in FindVariables().visit(d)):
new_dims += [d]
else:
new_dims += [d - sym.Literal(1)]

@@ -33,9 +33,16 @@
]


def shift_to_zero_indexing(routine):
def shift_to_zero_indexing(routine, ignore=()):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's generally preferred to assign None as default value for optional arguments, and then convert it to a tuple in the function body, e.g. ignore = as_tuple(ignore).
That also adds the benefit that you can do something like shift_to_zero_indexing(routine, ignore='myvar') and wouldn't get the unexpected behaviour that this is treated as ignore=('m', 'y', 'v', 'a', 'r').

routine : :any:`Subroutine`
The subroutine in which the array dimensions should be shifted
ignore : list of str
Dimensions (or rather variables being dimensions) to be ignored
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something like this would be more descriptive?

Suggested change
Dimensions (or rather variables being dimensions) to be ignored
List of variable names for which, if found in the dimension expression of an array subscript, that dimension is not shifted to zero.

Copy link
Collaborator

@reuterbal reuterbal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing the comments, all good now!

@reuterbal reuterbal added the ready for merge This PR has been approved and is ready to be merged label Mar 5, 2024
@reuterbal reuterbal force-pushed the nabr-the-new-scheduler branch 2 times, most recently from 5dbd1fb to 1e03830 Compare March 22, 2024 10:07
Base automatically changed from nabr-the-new-scheduler to main March 22, 2024 10:41
@reuterbal reuterbal added rebase required Rebase required for the PR branch to resolve conflicts and removed ready for merge This PR has been approved and is ready to be merged labels Mar 25, 2024
@mlange05 mlange05 force-pushed the nams_shift_to_zero_indexing branch from 1dc82a6 to 12aaeb0 Compare March 25, 2024 13:24
Copy link
Collaborator

@mlange05 mlange05 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Many thanks for you patience. GTG :shipit:

@mlange05 mlange05 added ready for merge This PR has been approved and is ready to be merged and removed rebase required Rebase required for the PR branch to resolve conflicts labels Mar 25, 2024
@reuterbal reuterbal changed the title more functionality for "shift to zero indexing" Allow to ignore specific dimensions in "shift to zero indexing" Mar 25, 2024
@reuterbal reuterbal merged commit bcdfec9 into main Mar 25, 2024
11 checks passed
@reuterbal reuterbal deleted the nams_shift_to_zero_indexing branch March 25, 2024 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready for merge This PR has been approved and is ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants