Document how to interpolate when indexing into tuple fields
- Dominant language
- Julia
- Stars
- 117
- Forks
- 19
- Avg merge
- 3d 4h
- Merged PRs (30d)
- 41
Description
**Is your feature request related to a problem? Please describe.**
It's unclear what the rules are for indexing into a Field of Tuples. For example,
```
using ClimaCore
zlim = (1,2)
nelements = 10
FT = Float32
boundary_tags = (:bottom, :top)
column = ClimaCore.Domains.IntervalDomain(
ClimaCore.Geometry.ZPoint{FT}(zlim[1]),
ClimaCore.Geometry.ZPoint{FT}(zlim[2]);
boundary_tags = boundary_tags,
)
mesh = ClimaCore.Meshes.IntervalMesh(column; nelems = nelements)
center_space = ClimaCore.Spaces.CenterFiniteDifferenceSpace(mesh)
coords = ClimaCore.Fields.coordinate_field(center_space)
types = (NTuple{10, FT},)
fields = map(types) do (T)
zero_instance = ClimaCore.RecursiveApply.rzero(T)
map(_ -> zero_instance, coords)
end
field = fields[1]
f(x) = x+x
## Indexing outside of loops
field.:1 .= FT(1) # runs
id = 2+3
field.:($id) .= FT(3) # runs
field.:($(2+3)) # does not run
field.:($(2+3)) .= FT(0) # runs
@. field.:($(2+3)) = FT(0) # does not run
field.:($$(2+3)) # does not run
@. field.:($$(2+3)) = FT(0) # runs
@. field.:1 = f(field.:1) # runs
@. field.:($$(2+3)) = f(field.:1) # runs
@. field.:($$(2+3)) = f(field.:($$(2+3))) # does not run
```
The rules are slightly different in loops:
This all runs
```
for i in 1:9
ip1 = i+1
field.:($i) .= field.:($ip1)
@. field.:($$i) = FT(0)
@. field.:($$ip1) = FT(0)
@. field.:($$ip1) = field.:($$ip1)
@. field.:($$(i+1)) = field.:($$ip1)
end
```
This does not
```
for i in 1:9
@. field.:($$(i+1)) = field.:($$(i+1))
end
```
**Describe the solution you'd like**
Documentation and explanation in a central repository, since this type of indexing is done in multiple repos.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reviewing the indexing examples in the issue and locating the central repository documentation referenced in the request. Document the interpolation rules for tuple-field indexing inside and outside loops, including the shown working and non-working forms; done means users can understand which syntax to use across the affected repositories.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100