FlexibleFunctors.destructure
— Methoddestructure(s)
For a struct s
which has parameters given by parameters
, iterates through all non-leaf nodes and collects the marked fields into a flat vector. This is particularly useful for model training or optimization, or use with ForwardDiff
. A function which restructures s
according to a flat vector is returned as the second argument.
NOTE: The flat vector representation is a Vector{T}
. Julia will promote all entries to a common type if possible. This means [1, 2.0] == [1.0, 2.0] and both are Vector{Float64}.
FlexibleFunctors.ffunctor
— Methodffunctor(x::T)
Returns a flexible functor based on the chosen parameters
.
FlexibleFunctors.fieldmap
— Methodfieldmap(f, x; exlude = isleaf)
Maps the function f
over the fields of a FlexibleFunctor
(equivalently, the parameter fields of a struct s
given by parameters
).
FlexibleFunctors.isleaf
— Methodisleaf(x)
Return true if x
has no children according to parameters
.
FlexibleFunctors.parameters
— Methodparameters(x)
Returns a tuple of parameters, as marked by the user during construction
FlexibleFunctors.parammap
— Methodparammap(f, x)
Maps f
to each parameter (as specified by parameters
) to the model x
. Evaluates calls to ffunctor
.
FlexibleFunctors.restructure
— Methodrestructure(s, xs)
Given a struct s
with parameters given by parameters
, restructures s
according to the vector xs
. In particular, s == restructure(s, destructure(s)[1])
.