-
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]: Index builtin #1699
Conversation
@@ -31,9 +31,9 @@ | |||
INT_LITERAL: SIGNED_INT | |||
FLOAT_LITERAL: SIGNED_FLOAT | |||
OFFSET_LITERAL: ( INT_LITERAL | CNAME ) "ₒ" | |||
_literal: INT_LITERAL | FLOAT_LITERAL | OFFSET_LITERAL | |||
AXIS_LITERAL: CNAME ("ᵥ" | "ₕ") |
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.
Renamed for consistency.
@@ -31,9 +31,9 @@ | |||
INT_LITERAL: SIGNED_INT | |||
FLOAT_LITERAL: SIGNED_FLOAT | |||
OFFSET_LITERAL: ( INT_LITERAL | CNAME ) "ₒ" | |||
_literal: INT_LITERAL | FLOAT_LITERAL | OFFSET_LITERAL | |||
AXIS_LITERAL: CNAME ("ᵥ" | "ₕ") | |||
_literal: INT_LITERAL | FLOAT_LITERAL | OFFSET_LITERAL | AXIS_LITERAL |
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.
Otherwise index(OFFSET_LITERAL)
isn't parsed properly.
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.
Do you mean index(AXIS_LITERAL)
?
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.
Yes
@@ -611,7 +611,6 @@ def convert_el_to_sid(el_expr: Expr, el_type: ts.ScalarType | ts.FieldType) -> E | |||
tuple_constructor=lambda *elements: SidComposite(values=list(elements)), | |||
) | |||
|
|||
assert isinstance(lowered_input_as_sid, (SidComposite, SidFromScalar, SymRef)) |
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.
This check was superfluous from the beginning since the format is checked anyway when the SetAt
is constructed. We just removed it instead of allowing an index
FunCall.
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.
a few comments
src/gt4py/next/iterator/embedded.py
Outdated
@@ -1156,6 +1156,7 @@ def ndarray(self) -> core_defs.NDArrayObject: | |||
def asnumpy(self) -> np.ndarray: | |||
raise NotImplementedError() | |||
|
|||
# TODO(tehrengruber): Use a regular zero dimensional field instead. |
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 don't understand the comment.
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.
We moved the comment to a better place. With respect to the comment itself: The IndexField
class is rather strange. It has two modes of operation: Either it is a field with (conceptually) field(domain) == domain
or it is a zero-dimensional field. Both modes don't share any implementation similarities, but are mushed into the same class. The way the class behaves is then controlled using _cur_index
. It would be much simpler to just make field[index]
return a zero-dimensional field which is exactly what we want instead of re-implementing it here.
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 don't understand what you are saying...
@@ -31,9 +31,9 @@ | |||
INT_LITERAL: SIGNED_INT | |||
FLOAT_LITERAL: SIGNED_FLOAT | |||
OFFSET_LITERAL: ( INT_LITERAL | CNAME ) "ₒ" | |||
_literal: INT_LITERAL | FLOAT_LITERAL | OFFSET_LITERAL | |||
AXIS_LITERAL: CNAME ("ᵥ" | "ₕ") | |||
_literal: INT_LITERAL | FLOAT_LITERAL | OFFSET_LITERAL | AXIS_LITERAL |
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.
Do you mean index(AXIS_LITERAL)
?
assert all( | ||
isinstance(inp, SymRef) for inp in node.inputs | ||
) # backend only supports SymRef inputs, not `index` calls | ||
input_names = [str(inp.id) for inp in node.inputs] # type: ignore[union-attr] # backend only supports SymRef inputs, not `index` calls |
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.
input_names = [str(inp.id) for inp in node.inputs] # type: ignore[union-attr] # backend only supports SymRef inputs, not `index` calls | |
input_names = [str(inp.id) for inp in node.inputs] # type: ignore[union-attr] # `inp`s are only `SymRef`s |
or similar
@@ -260,6 +260,17 @@ def visit_Program(self, node: gtfn_ir.Program, **kwargs: Any) -> Union[str, Coll | |||
#include <gridtools/fn/${grid_type_str}.hpp> | |||
#include <gridtools/fn/sid_neighbor_table.hpp> | |||
#include <gridtools/stencil/global_parameter.hpp> | |||
#include <gridtools/stencil/positional.hpp> | |||
|
|||
// TODO(havogt): move to gtfn? |
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'd propose to wait until GridTools/gridtools#1806 is merged next week.
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.
Once #1720 is in, we can remove this.
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.
Thanks, I removed that code.
updates minimum gridtools_cpp version for #1699
#include <gridtools/stencil/positional.hpp> | ||
|
||
// TODO(havogt): move to gtfn? | ||
namespace gridtools{ | ||
namespace fn{ | ||
template <class T> | ||
auto index(T){ | ||
return stencil::positional<std::decay_t<T>>();} | ||
} | ||
} | ||
|
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.
#include <gridtools/stencil/positional.hpp> | |
// TODO(havogt): move to gtfn? | |
namespace gridtools{ | |
namespace fn{ | |
template <class T> | |
auto index(T){ | |
return stencil::positional<std::decay_t<T>>();} | |
} | |
} | |
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.
lgtm
Adds index builtin for embedded and gtfn backends.