Skip to content

Commit

Permalink
Try with vector properties
Browse files Browse the repository at this point in the history
  • Loading branch information
charleskawczynski committed Oct 30, 2024
1 parent 868a69b commit e85d503
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/cache/precomputed_quantities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import Thermodynamics as TD
import ClimaCore: Spaces, Fields

struct UniformNamedTuple{K, T, N}
k::NTuple{N, K}
v::NTuple{N, T}
struct UniformNamedTuple{K, T}
k::Vector{K}
v::Vector{T}
end
# @inline Base.getproperty(nt::UniformNamedTuple, sym::Symbol) =
# getproperty(nt, Val(sym))
Expand All @@ -17,18 +17,17 @@ to_named_tuple(nt::UniformNamedTuple) = (; zip(nt.k, nt.v)...)
if isnothing(i)
error("No property $sym found in $(to_named_tuple(nt))")
else
@inbounds getproperty(getfield(nt, :v), i)
@inbounds getindex(getfield(nt, :v), i)
end
end
Base.eltype(::UniformNamedTuple{K, T, N}) where {K, T, N} = K
Base.length(::UniformNamedTuple{K, T, N}) where {K, T, N} = N
Base.eltype(::UniformNamedTuple{K, T}) where {K, T} = K
Base.length(nt::UniformNamedTuple{K, T}) where {K, T} = length(getfield(nt, :v))
function to_uniform_named_tuple(nt)
k = Tuple(keys(nt))
v = Tuple(values(nt))
k = collect(Tuple(keys(nt)))
v = collect(Tuple(values(nt)))
K = typeof(first(k))
T = typeof(first(v))
N = length(v)
return UniformNamedTuple{K, T, N}(k, v)
return UniformNamedTuple{K, T}(k, v)
end

struct TypeGroupedNamedTuple{M, C}
Expand Down

0 comments on commit e85d503

Please sign in to comment.