Skip to content

Commit 65d0e30

Browse files
Merge pull request #2004 from CliMA/ck/type_stability
Fix type instability in slab_index and vindex
2 parents 9cb8366 + 2df6cf4 commit 65d0e30

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

lib/ClimaCorePlots/src/ClimaCorePlots.jl

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import TriplotBase
55

66
import ClimaComms
77
# Keep in sync with definition(s) in ClimaCore.DataLayouts.
8-
@inline slab_index(i, j) = CartesianIndex(i, j, 1, 1, 1)
9-
@inline slab_index(i) = CartesianIndex(i, 1, 1, 1, 1)
8+
@inline slab_index(i::T, j::T) where {T} =
9+
CartesianIndex(i, j, T(1), T(1), T(1))
10+
@inline slab_index(i::T) where {T} = CartesianIndex(i, T(1), T(1), T(1), T(1))
11+
1012
import ClimaCore:
1113
ClimaCore,
1214
DataLayouts,

lib/ClimaCoreTempestRemap/src/ClimaCoreTempestRemap.jl

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ export write_exodus, rll_mesh, overlap_mesh, remap_weights, apply_remap
44
export def_time_coord, def_space_coord
55

66
# Keep in sync with definition in DataLayouts.
7-
@inline slab_index(i, j) = CartesianIndex(i, j, 1, 1, 1)
8-
@inline slab_index(i) = CartesianIndex(i, 1, 1, 1, 1)
9-
@inline vindex(v) = CartesianIndex(1, 1, 1, v, 1)
7+
@inline slab_index(i::T, j::T) where {T} =
8+
CartesianIndex(i, j, T(1), T(1), T(1))
9+
@inline slab_index(i::T) where {T} = CartesianIndex(i, T(1), T(1), T(1), T(1))
10+
@inline vindex(v::T) where {T} = CartesianIndex(T(1), T(1), T(1), v, T(1))
1011

1112
using ClimaComms
1213
import ClimaCore

src/DataLayouts/DataLayouts.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -1107,9 +1107,9 @@ type parameters.
11071107
@inline farray_size(data::VIFH{S, Nv, Ni, Nh}) where {S, Nv, Ni, Nh} = (Nv, Ni, ncomponents(data), Nh)
11081108

11091109
# Keep in sync with definition(s) in libs.
1110-
@inline slab_index(i, j) = CartesianIndex(i, j, 1, 1, 1)
1111-
@inline slab_index(i) = CartesianIndex(i, 1, 1, 1, 1)
1112-
@inline vindex(v) = CartesianIndex(1, 1, 1, v, 1)
1110+
@inline slab_index(i::T, j::T) where {T} = CartesianIndex(i, j, T(1), T(1), T(1))
1111+
@inline slab_index(i::T) where {T} = CartesianIndex(i, T(1), T(1), T(1), T(1))
1112+
@inline vindex(v::T) where {T} = CartesianIndex(T(1), T(1), T(1), v, T(1))
11131113

11141114
"""
11151115
parent_array_type(data::AbstractData)

0 commit comments

Comments
 (0)