You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-`array[idx]`: The array and current index from which to find neighbors.
34
-
-`distance`: An integer specifying the extent of the neighborhood (e.g., `1` for a 3x3 neighborhood in 2D).
34
+
-`distance`: An integer or `Tuple` of integers specifying the extent of the neighborhood (e.g., `1` for a 3x3 neighborhood in 2D).
35
35
-`boundary_condition`: Defines how to handle accesses beyond the array boundaries. Available conditions are:
36
-
-`Wrap()`: Wraps around to the other side of the array.
36
+
-`Wrap()`: Wraps around to the other side of the array (periodic boundaries).
37
37
-`Pad(value)`: Pads with a specified `value`.
38
38
-`Reflect(symmetric)`: Reflects values back into the array at boundaries. The `symmetric` boolean controls whether the edge element is included in the reflection:
39
39
-`Reflect(true)` (symmetric): Edge element IS repeated. For array `[a,b,c,d]`, extends as `[...,c,b,a,a,b,c,d,d,c,b,...]`.
40
40
-`Reflect(false)` (mirror): Edge element NOT repeated. For array `[a,b,c,d]`, extends as `[...,d,c,b,a,b,c,d,c,b,a,...]`.
41
+
-`Clamp()`: Clamps to the boundary value (repeats edge elements). For array `[a,b,c,d]`, extends as `[...,a,a,a,a,b,c,d,d,d,d,...]`.
42
+
-`LinearExtrapolate()`: Linearly extrapolates using the slope at the boundary. Only works with `Real` element types. For array `[2,4,6,8]`, the slope at the low boundary is `4-2=2`, so index 0 would be `2-2=0`.
43
+
-**Mixed BCs (Tuple)**: You can specify different boundary conditions per dimension using a tuple. For example, `(Wrap(), Pad(0))` uses `Wrap` for dimension 1 and `Pad(0)` for dimension 2.
41
44
42
45
### Example: Averaging Neighbors with `Wrap`
43
46
@@ -149,6 +152,80 @@ end
149
152
@assertcollect(B) == [5, 6, 9, 10]
150
153
```
151
154
155
+
### Example: Edge Detection with `Clamp`
156
+
157
+
The `Clamp` boundary condition repeats edge values, which is useful when you want boundary elements to have a neutral effect:
You can specify different boundary conditions for each dimension using a tuple. This is useful when different boundaries have different physical meanings:
208
+
209
+
```julia
210
+
import Dagger: Wrap, Pad
211
+
212
+
# 2D array with Wrap in dimension 1 (rows) and Pad(0) in dimension 2 (columns)
# - Column neighbors are padded with 0 (zero-flux at column boundaries)
225
+
```
226
+
227
+
This is particularly useful for physical simulations where, for example, you might have periodic boundaries in one direction and fixed boundaries in another.
228
+
152
229
## Sequential Semantics
153
230
154
231
Expressions within a `@stencil` block are executed sequentially in terms of their effect on the data. This means that the result of one statement is visible to the subsequent statements, as if they were applied "all at once" across all indices before the next statement begins.
0 commit comments