-
Notifications
You must be signed in to change notification settings - Fork 49
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] Embedded field remove __array__ #1366
Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
faca090
feat[next] Enable embedded field view in ffront_tests
havogt 7931cfd
broadcast for scalars
havogt 4734c84
implement astype
havogt e1463d0
support binary builtins for scalars
havogt f1047dc
support domain
havogt 9ac0ddd
add __ne__, __eq__
havogt f8682ed
fix typo
havogt 42805f7
this is the typo, the other was improve alloc
havogt ec0a0d5
cleanup import in fbuiltin
havogt ac28ea0
fix test case
havogt 89e05ea
fix/ignore typing
havogt cdbaf0b
remove __array__ from field
havogt 43cb189
some more...
havogt 520da0d
fix some iterator tests
havogt 1e7b0ed
added asnumpy where needed
nfarabullini 8234894
Merge remote-tracking branch 'upstream/main' into remove_array2
havogt 5fbf826
remove test exclusion
havogt 0742650
undo unintendend change
havogt 3b9e35d
undo unrelated change
havogt 8a6e6c2
undo change
havogt 5f52a6c
fix column stencil test
havogt d2e840b
fix ndarray test
havogt c394ed0
fix 2 more
havogt 894e41d
astype tuple
havogt 89c429d
2 more
havogt 27999c1
fix fvm nabla
havogt fb76d11
refactor asnumpy
havogt 753417e
address review comments
havogt 117e2c9
Update src/gt4py/next/utils.py
havogt 9671c54
fix formatting
havogt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -371,8 +371,8 @@ def cast_nested_tuple( | |
|
||
a = cases.allocate(cartesian_case, cast_tuple, "a")() | ||
b = cases.allocate(cartesian_case, cast_tuple, "b")() | ||
a_asint = cartesian_case.as_field([IDim], np.asarray(a).astype(int32)) | ||
b_asint = cartesian_case.as_field([IDim], np.asarray(b).astype(int32)) | ||
a_asint = cartesian_case.as_field([IDim], a.asnumpy().astype(int32)) | ||
b_asint = cartesian_case.as_field([IDim], b.asnumpy().astype(int32)) | ||
out_tuple = cases.allocate(cartesian_case, cast_tuple, cases.RETURN)() | ||
out_nested_tuple = cases.allocate(cartesian_case, cast_nested_tuple, cases.RETURN)() | ||
|
||
|
@@ -384,7 +384,10 @@ def cast_nested_tuple( | |
a_asint, | ||
b_asint, | ||
out=out_tuple, | ||
ref=(np.full_like(a, True, dtype=bool), np.full_like(b, True, dtype=bool)), | ||
ref=( | ||
np.full_like(a.asnumpy(), True, dtype=bool), | ||
np.full_like(b.asnumpy(), True, dtype=bool), | ||
), | ||
) | ||
|
||
cases.verify( | ||
|
@@ -396,9 +399,9 @@ def cast_nested_tuple( | |
b_asint, | ||
out=out_nested_tuple, | ||
ref=( | ||
np.full_like(a, True, dtype=bool), | ||
np.full_like(a, True, dtype=bool), | ||
np.full_like(b, True, dtype=bool), | ||
np.full_like(a.asnumpy(), True, dtype=bool), | ||
np.full_like(a.asnumpy(), True, dtype=bool), | ||
np.full_like(b.asnumpy(), True, dtype=bool), | ||
), | ||
) | ||
|
||
|
@@ -473,7 +476,7 @@ def testee(a: cases.IKField, offset_field: cases.IKField) -> gtx.Field[[IDim, KD | |
comparison=lambda out, ref: np.all(out == ref), | ||
) | ||
|
||
assert np.allclose(out, ref) | ||
assert np.allclose(out.asnumpy(), ref) | ||
|
||
|
||
def test_nested_tuple_return(cartesian_case): | ||
|
@@ -846,8 +849,8 @@ def program_domain(a: cases.IField, out: cases.IField): | |
a = cases.allocate(cartesian_case, program_domain, "a")() | ||
out = cases.allocate(cartesian_case, program_domain, "out")() | ||
|
||
ref = np.asarray(out).copy() # ensure we are not overwriting `out` outside of the domain | ||
ref[1:9] = a[1:9] * 2 | ||
ref = out.asnumpy().copy() # ensure we are not overwriting out outside of the domain | ||
ref[1:9] = a.asnumpy()[1:9] * 2 | ||
|
||
cases.verify(cartesian_case, program_domain, a, out, inout=out, ref=ref) | ||
|
||
|
@@ -881,8 +884,8 @@ def program_domain( | |
inp = cases.allocate(cartesian_case, program_domain, "inp")() | ||
out = cases.allocate(cartesian_case, fieldop_domain, cases.RETURN)() | ||
|
||
ref = np.asarray(out).copy() | ||
ref[lower_i : int(upper_i / 2)] = inp[lower_i : int(upper_i / 2)] * 2 | ||
ref = out.asnumpy().copy() | ||
ref[lower_i : int(upper_i / 2)] = inp.asnumpy()[lower_i : int(upper_i / 2)] * 2 | ||
|
||
cases.verify( | ||
cartesian_case, | ||
|
@@ -924,9 +927,9 @@ def program_domain( | |
a = cases.allocate(cartesian_case, program_domain, "a")() | ||
out = cases.allocate(cartesian_case, program_domain, "out")() | ||
|
||
ref = np.asarray(out).copy() | ||
ref = out.asnumpy().copy() | ||
ref[1 * lower_i : upper_i + 0, lower_j - 0 : upper_j] = ( | ||
a[1 * lower_i : upper_i + 0, lower_j - 0 : upper_j] * 2 | ||
a.asnumpy()[1 * lower_i : upper_i + 0, lower_j - 0 : upper_j] * 2 | ||
) | ||
|
||
cases.verify( | ||
|
@@ -964,10 +967,10 @@ def program_domain_tuple( | |
out0 = cases.allocate(cartesian_case, program_domain_tuple, "out0")() | ||
out1 = cases.allocate(cartesian_case, program_domain_tuple, "out1")() | ||
|
||
ref0 = np.asarray(out0).copy() | ||
ref0[1:9, 4:6] = inp0[1:9, 4:6] + inp1[1:9, 4:6] | ||
ref1 = np.asarray(out1).copy() | ||
ref1[1:9, 4:6] = inp1[1:9, 4:6] | ||
ref0 = out0.asnumpy().copy() | ||
ref0[1:9, 4:6] = inp0.asnumpy()[1:9, 4:6] + inp1.asnumpy()[1:9, 4:6] | ||
ref1 = out1.asnumpy().copy() | ||
ref1[1:9, 4:6] = inp1.asnumpy()[1:9, 4:6] | ||
|
||
cases.verify( | ||
cartesian_case, | ||
|
@@ -995,7 +998,7 @@ def fieldop_where_k_offset( | |
)() | ||
out = cases.allocate(cartesian_case, fieldop_where_k_offset, "inp")() | ||
|
||
ref = np.where(np.asarray(k_index) > 0, np.roll(inp, 1, axis=1), 2) | ||
ref = np.where(k_index.asnumpy() > 0, np.roll(inp.asnumpy(), 1, axis=1), 2) | ||
|
||
cases.verify(cartesian_case, fieldop_where_k_offset, inp, k_index, out=out, ref=ref) | ||
|
||
|
@@ -1119,13 +1122,6 @@ def _invalid_unpack() -> tuple[int32, float64, int32]: | |
|
||
|
||
def test_constant_closure_vars(cartesian_case): | ||
if cartesian_case.backend is None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is why we are doing the PR |
||
# >>> field = gtx.zeros(domain) | ||
# >>> np.int32(1)*field # steals the buffer from the field | ||
# array([0.]) | ||
|
||
# TODO(havogt): remove `__array__`` from `NdArrayField` | ||
pytest.xfail("Bug: Binary operation between np datatype and Field returns ndarray.") | ||
from gt4py.eve.utils import FrozenNamespace | ||
|
||
constants = FrozenNamespace( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am introducing this in #1365