Variable Templates
Types
ClimateMachine.VariableTemplates.Grad
— TypeGrad{S,A,offset}(array::A)
Defines property overloading along slices of the second dimension of array
using the type S
as a template. offset
is used to shift the starting element of the array.
ClimateMachine.VariableTemplates.Vars
— TypeVars{S,A,offset}(array::A)
Defines property overloading for array
using the type S
as a template. offset
is used to shift the starting element of the array.
Index methods
ClimateMachine.VariableTemplates.@vars
— Macro@vars(var1::Type1, var2::Type2)
A convenient syntax for describing a NamedTuple
type.
Example
julia> @vars(a::Float64, b::Float64)
NamedTuple{(:a, :b),Tuple{Float64,Float64}}
ClimateMachine.VariableTemplates.vuntuple
— Functionvuntuple(f::F, N::Int)
Val-Unroll ntuple: wrap ntuple
arguments in Val
for unrolling.
ClimateMachine.VariableTemplates.unroll_map
— Function@unroll_map(f::F, N::Int, args...) where {F}
unroll_map(f::F, N::Int, args...) where {F}
Unroll N-expressions and wrap arguments in Val
.
ClimateMachine.VariableTemplates.flattened_tup_chain
— Functionflattened_tup_chain(::Type{T}) where {T <: Union{NamedTuple,NTuple}}
An array of tuples, containing symbols and integers for every combination of each field in the Vars
array.
ClimateMachine.VariableTemplates.flattened_named_tuple
— Functionflattened_named_tuple
A flattened NamedTuple, given a Vars
or nested NamedTuple
instance.
Example:
using Test
using ClimateMachine.VariableTemplates
nt = (x = 1, a = (y = 2, z = 3, b = ((a = 1,), (a = 2,), (a = 3,))));
fnt = flattened_named_tuple(nt);
@test keys(fnt) == (:x, :a_y, :a_z, :a_b_1_a, :a_b_2_a, :a_b_3_a)
@test length(fnt) == 6
@test fnt.x == 1
@test fnt.a_y == 2
@test fnt.a_z == 3
@test fnt.a_b_1_a == 1
@test fnt.a_b_2_a == 2
@test fnt.a_b_3_a == 3
ClimateMachine.VariableTemplates.FlattenArr
— TypeFlattenArr
Flatten arrays in flattened_tup_chain
and flattened_named_tuple
.
ClimateMachine.VariableTemplates.RetainArr
— TypeRetainArr
Do not flatten arrays in flattened_tup_chain
and flattened_named_tuple
.
ClimateMachine.VariableTemplates.varsize
— Functionvarsize(S)
The number of elements specified by the template type S
.
ClimateMachine.VariableTemplates.varsindices
— Functionvarsindices(S, ps::Tuple)
varsindices(S, ps...)
Return a tuple of indices corresponding to the properties specified by ps
based on the template type S
. Properties can be specified using either symbols or strings.
Examples
julia> S = @vars(x::Float64, y::Float64, z::Float64)
julia> varsindices(S, (:x, :z))
(1, 3)
julia> S = @vars(x::Float64, y::@vars(α::Float64, β::SVector{3, Float64}))
julia> varsindices(S, "x", "y.β")
(1, 3, 4, 5)
ClimateMachine.VariableTemplates.varsindex
— Functionvarsindex(S, p::Symbol, [sp::Symbol...])
Return a range of indices corresponding to the property p
and (optionally) its subproperties sp
based on the template type S
.
Examples
julia> S = @vars(x::Float64, y::Float64)
julia> varsindex(S, :y)
2:2
julia> S = @vars(x::Float64, y::@vars(α::Float64, β::SVector{3, Float64}))
julia> varsindex(S, :y, :β)
3:5