Parameter
Parametron.Parameter
— Type.struct Parameter{T, F, InPlace}
Represents a 'placeholder' for data; a value that may be filled in later.
Parameter
s can be evaluated by simply calling them with no arguments.
Parameter
s keep track of whether they've already been evaluated using dirty
flag. To reevalute a parameter, the dirty flag must first be set using setdirty!(parameter)
. The update function will then be called when the parameter itself is called.
Examples
julia> value = Ref(1)
Base.RefValue{Int64}(1)
julia> p = Parameter{Int}(() -> value[], model)
Parameter{Int64, …}(…)
julia> p()
1
julia> value[] = 2
2
julia> p()
1
julia> Parametron.setdirty!(p); p()
2
Parametron.Parameter
— Method.Parameter(f, model)
Create a new 'out-of-place' Parameter
with an update function f
that takes no arguments. The type of the output is determined upon construction by calling the update function.
Explicitly specifying the return value type using the Parameter{T}(f, model)
constructor is preferred, as using this constructor can lead to type inference issues.
Parametron.Parameter
— Method.Parameter(model; val)
Create a new 'in-place' Parameter
that always returns val
. This constructor may be used to create Parameter
s that use val
as a work buffer that is manually/externally updated.
By using this constructor, the automated mechanism for lazily updating a Parameter
's value when necessary is essentially circumvented, and the user is responsible for ensuring that the Parameter
's value is updated at the appropriate time.
Parametron.Parameter
— Method.Parameter(f, model)
Parameter(model; val)
Create a new 'out-of-place' Parameter
with an update function f
that takes no arguments and returns a value of type T
.
Parametron.Parameter
— Method.Parameter(f, val, model)
Parameter(model; val)
Create a new 'in-place' Parameter
with an update function f
that takes val
as its argument and updates it in place.