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

Support for 4d Data #71

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
Open

Conversation

oelbert
Copy link
Collaborator

@oelbert oelbert commented Sep 5, 2024

Description
This PR adds support for 4D data structures in NDSL, especially the translate tests, and also fixes a bug where TranslateFortranData2Py would cast everything to Float instead of respecting types.

How Has This Been Tested?
The PBL and surface layer translate tests have been run with these updates

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules
  • New check tests, if applicable, are included

Comment on lines 160 to 162
elif n_dims == 4:

data = _make_storage_data_4d(data, shape, start, backend=backend)
Copy link

@bensonr bensonr Sep 5, 2024

Choose a reason for hiding this comment

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

Remove the empty line.

I may have missed it, but there is no test to ensure ndims <=4. I'm guessing the gt4py.storage.from_array function will crash at that point since data is undefined when ndims >4.

@@ -257,6 +262,25 @@ def _make_storage_data_3d(
return buffer


def _make_storage_data_4d(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we generalize this with something like

def _make_storage_data_Nd(
    data: Field,
    shape: Tuple[int, ...],
    start: Tuple[int, ...],
    *,
    backend: str,
) -> Field:
    buffer = zeros(shape, backend=backend)
    idx = tuple([slice(start, start + shape_dim) for shape_dim in data.shape])
    buffer[idx] = asarray(data, type(buffer))
    return buffer

and we just have to pass a default start if it doesn't exist (that can be build with something like tuple([0]*data.ndim)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants