Skip to content

feat[next]: runtime init for the scan builtin - #3066

Draft
havogt wants to merge 3 commits into
havogt/scan-callfrom
havogt/scan-init
Draft

havogt wants to merge 3 commits into
havogt/scan-callfrom
havogt/scan-init

Conversation

@havogt

@havogt havogt commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Description

Stacked on #3065.

init of the scan builtin may be a runtime value, and is now required:

@gtx.field_operator
def foo(a: gtx.Field[[IDim, KDim], float], init: gtx.Field[[IDim], float]) -> gtx.Field[[IDim, KDim], float]:
    return scan(add, axis=KDim, init=init)(a)
  • init may be a literal, a scalar, or a field without the scan dimension holding the initial carry of each column. For tuple carries each element may be any of these. A field over the scan dimension is rejected, and so are fields whose dimensions are not a subset of the result's.
  • init has no default any more. 0.0 only matched float64 carries. @scan_operator keeps its default.
  • forward stays a compile-time constant.

Changes:

  • Type deduction: only forward must be a literal. The carry check compares against the dtype of field leaves of init, and a call-site check validates the dimensions of field inits.
  • Lowering: a literal init seeds the scan as before. A stencil may not reference outer symbols, so a non-literal init is passed as an extra argument to the scan's as_fieldop and read on the first level: the carry becomes (is_initialized, state), seeded with False and a typed zero.
  • Embedded: ScanOperator reads init per column.

Requirements

  • All fixes and/or new features come with corresponding tests.
  • Important design decisions have been documented in the appropriate ADR inside the docs/development/ADRs/ folder.

'init' of 'scan' may be a runtime scalar or a field without the scan
dimension, giving the initial carry per column. A non-literal init is
passed to the scan as an extra argument and selected on the first level
via a flag in the carry, seeded with a typed zero.
A default 0.0 only matches float64 carries and has no meaning for a
runtime init. 'scan_operator' keeps its default.
@havogt

havogt commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

🤖 Written by an agent on behalf of @havogt

# Conflicts:
#	src/gt4py/next/embedded/operators.py
#	src/gt4py/next/ffront/foast_to_gtir.py
#	tests/next_tests/integration_tests/feature_tests/ffront_tests/test_scan.py
@havogt
havogt added this pull request to stack #3069 December 2, 2026 08:36

This branch has not been deployed

No deployments
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.

1 participant