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

feat[next]: Slicing field to 0d to return field not scalar #1427

Merged
merged 62 commits into from
Feb 9, 2024

Conversation

nfarabullini
Copy link
Contributor

@nfarabullini nfarabullini commented Jan 25, 2024

Extracting a single value from a field should return an empty field, not a scalar

Given the following example:

    @gtx.field_operator
    def testee_fo(a: cases.IKField) -> cases.IKField:
        return a

    @gtx.program
    def testee_prog(a: cases.IKField):
        testee_fo(a, out=a[1:2, 3:4])

The program return type should be:

     gtx.Field[[], int]

Additionally, a small fix was made in past_passes.type_deduction such that arg_types is used instead of nodes.args.type

@nfarabullini nfarabullini marked this pull request as draft January 25, 2024 18:00
@nfarabullini nfarabullini marked this pull request as ready for review January 30, 2024 08:49
@nfarabullini nfarabullini changed the title edit to return array from slicing instead of scalar refactor[next]: single array slicing to return array not scalar Jan 30, 2024
@nfarabullini nfarabullini changed the title refactor[next]: single array slicing to return array not scalar feat[next]: single array slicing to return array not scalar Jan 30, 2024
@nfarabullini nfarabullini requested a review from havogt February 6, 2024 12:44
Copy link
Contributor

@havogt havogt left a comment

Choose a reason for hiding this comment

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

I have to look at the details again tomorrow. We can talk in the morning...

src/gt4py/next/embedded/nd_array_field.py Outdated Show resolved Hide resolved
Comment on lines 305 to 310
def _scalar_to_field(self, value: core_defs.Scalar) -> np.ndarray:
if self.array_ns == cp:
return cp.asarray(value)
else:
return np.asarray(value)

Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be removed already?

src/gt4py/next/iterator/embedded.py Outdated Show resolved Hide resolved
Comment on lines 190 to 193
res = field[pos] if common.is_field(field) else field
res = res.item() if hasattr(res, "item") else res # extract scalar value from array
res = (
res.ndarray.item() if hasattr(res, "ndarray") else res # type: ignore[union-attr]
) # extract scalar value from array
Copy link
Contributor

Choose a reason for hiding this comment

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

yes

src/gt4py/next/common.py Outdated Show resolved Hide resolved
@havogt havogt changed the title feat[next]: single array slicing to return array not scalar feat[next]: Slicing field to 0d to return field not scalar Feb 8, 2024
@havogt havogt requested a review from egparedes February 8, 2024 15:54
Copy link
Contributor

@egparedes egparedes left a comment

Choose a reason for hiding this comment

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

ILGTM

@nfarabullini nfarabullini merged commit 1d305e1 into GridTools:main Feb 9, 2024
39 checks passed
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