`FlexibleFunctors.destructure`

— Method`destructure(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`

— Method`ffunctor(x::T)`

Returns a flexible functor based on the chosen `parameters`

.

`FlexibleFunctors.fieldmap`

— Method`fieldmap(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`

— Method`isleaf(x)`

Return true if `x`

has no children according to `parameters`

.

`FlexibleFunctors.parameters`

— Method`parameters(x)`

Returns a tuple of parameters, as marked by the user during construction

`FlexibleFunctors.parammap`

— Method`parammap(f, x)`

Maps `f`

to each parameter (as specified by `parameters`

) to the model `x`

. Evaluates calls to `ffunctor`

.

`FlexibleFunctors.restructure`

— Method`restructure(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])`

.