Skip to content

Commit

Permalink
slides 3+4
Browse files Browse the repository at this point in the history
  • Loading branch information
havogt committed Nov 22, 2023
1 parent 74f7ac5 commit 2590b68
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions docs/user/next/slides/slides_3.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ from gt4py.next import neighbor_sum, where
```{code-cell} ipython3
Cell = gtx.Dimension("Cell")
K = gtx.Dimension("K", kind=gtx.DimensionKind.VERTICAL)
grid_shape = (5, 6)
```

## Using conditionals on fields
Expand All @@ -43,10 +42,12 @@ This function takes 3 input arguments:

```{code-cell} ipython3
mask = gtx.as_field([Cell], np.asarray([True, False, True, True, False]))
result = gtx.as_field([Cell], np.zeros(shape=grid_shape[0]))
true_field = gtx.as_field([Cell], np.asarray([11.0, 12.0, 13.0, 14.0, 15.0]))
false_field = gtx.as_field([Cell], np.asarray([21.0, 22.0, 23.0, 24.0, 25.0]))
result = gtx.zeros(gtx.domain({Cell:5}))
@gtx.field_operator
def conditional(mask: gtx.Field[[Cell], bool], true_field: gtx.Field[[Cell], gtx.float64], false_field: gtx.Field[[Cell], gtx.float64]
) -> gtx.Field[[Cell], gtx.float64]:
Expand Down Expand Up @@ -77,9 +78,11 @@ def run_add_domain(a : gtx.Field[[Cell, K], gtx.float64],
```

```{code-cell} ipython3
a = gtx.as_field([Cell, K], np.full(shape=grid_shape, fill_value=2.0, dtype=np.float64))
b = gtx.as_field([Cell, K], np.full(shape=grid_shape, fill_value=3.0, dtype=np.float64))
result = gtx.as_field([Cell, K], np.zeros(shape=grid_shape))
domain = gtx.domain({Cell: 5, K: 6})
a = gtx.full(domain, fill_value=2.0, dtype=np.float64)
b = gtx.full(domain, fill_value=3.0, dtype=np.float64)
result = gtx.zeros(domain)
run_add_domain(a, b, result, offset_provider={})
print("result array: \n {}".format(result.asnumpy()))
Expand Down
2 changes: 1 addition & 1 deletion docs/user/next/slides/slides_4.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def add_scan(state: float, k_field: float) -> float:

```{code-cell} ipython3
k_field = gtx.as_field([K], np.asarray([1.0, 2.0, 4.0, 6.0, 0.0, 2.0, 5.0]))
result = gtx.as_field([K], np.zeros(shape=(7,)))
result = gtx.zeros(domain=gtx.domain({K:7}))
add_scan(k_field, out=result, offset_provider={})
Expand Down

0 comments on commit 2590b68

Please sign in to comment.