|
1 | 1 | # Backwards-compatibility shims for the pre-rewrite DataLayouts API. |
2 | 2 | # |
3 | | -# The PR replaces the per-layout struct hierarchy (AbstractData, IJFH, VIJFH, |
4 | | -# ...) with the single DataLayout type family. Downstream packages (ClimaAtmos, |
5 | | -# ClimaCoupler, user code) that haven't migrated yet can keep referring to the |
6 | | -# old names through the aliases below. |
7 | | -# |
8 | 3 | # These are not deprecated with warnings — they're plain aliases — so old code |
9 | 4 | # continues to type-check without noise. Remove this file when all downstream |
10 | 5 | # consumers have migrated to the new names. |
11 | | -# |
12 | | -# Old names whose semantics changed incompatibly (e.g. concrete layout types |
13 | | -# whose parent arrays gained a leading vertical axis, or the *Singleton |
14 | | -# dispatch tokens) are intentionally not aliased: resolving them to a subtly |
15 | | -# different meaning would be worse than an UndefVarError. |
16 | 6 |
|
17 | | -# Old: AbstractData{S} with S the element type. New: DataLayout{T, N, F, S, A} |
18 | | -# with T the element type, so parametrized uses like AbstractData{<:Real} |
19 | | -# still work through this alias. |
20 | | -const AbstractData{S} = DataLayout{S} |
| 7 | +export AbstractData, IJFH, IJHF |
21 | 8 |
|
22 | | -# Old: IJFH{S, Nij, A} and IJHF{S, Nij, A}, with 4-D parent arrays. New: 2D |
23 | | -# fields store their values in VIJFH/VIJHF layouts with Nv = 1 and 5-D parent |
24 | | -# arrays, so these aliases keep method signatures like |
25 | | -# `remap!(target::IJFH{S, Nq}, ...)` (ClimaCoreTempestRemap) dispatching |
26 | | -# correctly on 2D field values. Code that indexes into `parent(data)` with the |
27 | | -# old 4-D shape still needs to be updated for the new parent-array layout. |
28 | | -const IJFH{S, Nij} = VIJFH{S, 1, Nij, Nij, nothing} |
29 | | -const IJHF{S, Nij} = VIJHF{S, 1, Nij, Nij, nothing} |
| 9 | +# Old: AbstractData{T} |
| 10 | +# New: DataLayout{T, N, F, S, A} |
| 11 | +const AbstractData{T} = DataLayout{T} |
30 | 12 |
|
31 | | -# These were exported on main, and packages like ClimaCoreTempestRemap access |
32 | | -# them through `using ClimaCore.DataLayouts`. |
33 | | -export AbstractData, IJFH, IJHF |
| 13 | +# Old: IJFH/IJHF layouts with 4-D parent arrays |
| 14 | +# New: VIJFH/VIJHF layouts with Nv = 1 and 5-D parent arrays |
| 15 | +# Used by ClimaCoreTempestRemap's remap!(target::IJFH{T, Nq}, ...). |
| 16 | +const IJFH{T, Nij} = VIJFH{T, 1, Nij, Nij, nothing} |
| 17 | +const IJHF{T, Nij} = VIJHF{T, 1, Nij, Nij, nothing} |
34 | 18 |
|
35 | | -# Old: getindex/setindex! with a 5-D "universal index" CartesianIndex(i, j, f, |
36 | | -# v, h), whose f component was ignored because the entire value was read or |
37 | | -# written. New: Cartesian indices have one coordinate per array dimension, in |
38 | | -# the order (v, i, j, h). Packages like ClimaCoreTempestRemap still index full |
39 | | -# layouts, slabs, and columns with universal indices (e.g., |
40 | | -# `slab(data, h)[CartesianIndex(i, j, 1, 1, 1)]`), so the methods below |
41 | | -# translate 5-D indices from the old convention to the new one. They override |
42 | | -# the generic AbstractArray interpretation of a `CartesianIndex{5}` as a 4-D |
43 | | -# index with a trailing singleton coordinate, so new code must not add trailing |
44 | | -# coordinates when indexing into 4-dimensional layouts. Remove these methods |
45 | | -# together with the aliases above. |
46 | | -@inline universal_index_shim(I::CartesianIndex{5}) = |
47 | | - CartesianIndex(I[4], I[1], I[2], I[5]) |
| 19 | +# Old: getindex/setindex! with a 5-D CartesianIndex(i, j, _, v, h) |
| 20 | +# New: getindex/setindex! with a 4-D CartesianIndex(v, i, j, h) |
| 21 | +# Used by ClimaCoreTempestRemap in slab(data, h)[CartesianIndex(i, j, 1, 1, 1)] |
| 22 | +# and similar functions. This overrides the generic AbstractArray interpretation |
| 23 | +# of a CartesianIndex{5}; until it is removed, new code should not add a |
| 24 | +# trailing singleton coordinate when indexing into VIJFH/VIJHF layouts. |
48 | 25 | @propagate_inbounds Base.getindex(data::VIJHWithF, I::CartesianIndex{5}) = |
49 | | - getindex(data, universal_index_shim(I)) |
| 26 | + getindex(data, CartesianIndex(I[4], I[1], I[2], I[5])) |
50 | 27 | @propagate_inbounds Base.setindex!(data::VIJHWithF, value, I::CartesianIndex{5}) = |
51 | | - setindex!(data, value, universal_index_shim(I)) |
| 28 | + setindex!(data, value, CartesianIndex(I[4], I[1], I[2], I[5])) |
52 | 29 |
|
53 | | -# Old: every component of a universal index was ignored for 0-dimensional data. |
| 30 | +# Old: single-point layouts ignore every component of a 5-D CartesianIndex |
| 31 | +# New: single-point layouts without any index |
54 | 32 | @propagate_inbounds Base.getindex(data::DataF, I::CartesianIndex{5}) = data[] |
55 | 33 | @propagate_inbounds Base.setindex!(data::DataF, value, I::CartesianIndex{5}) = |
56 | 34 | setindex!(data, value) |
0 commit comments