Parameter

Parameter

struct Parameter{T, F, InPlace}

Represents a 'placeholder' for data; a value that may be filled in later.

Parameters can be evaluated by simply calling them with no arguments.

Parameters 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
source
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.

Warning

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.

source
Parameter(model; val)

Create a new 'in-place' Parameter that always returns val. This constructor may be used to create Parameters that use val as a work buffer that is manually/externally updated.

Warning

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.

source
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.

source
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.

source