What does this struct mean in Julia?

Viewed 119

I am trying to lean deep learning using Julia. In one of the tutorials, which is about MLP, use the below structure for modeling multiple layers in ANN. What does this code mean?

struct Chain
    layers
    Chain(layers...) = new(layers)
end
2 Answers

This definition in isolation doesn't really "mean" anything; it is just a user defined struct with one field (called layers) and one inner constructor. Usually custom structs like this is used for collecting some data and/or used to define operations on, e.g. you could define a function f operating on this struct like this:

function f(c::Chain)
    # do something with the layers in the chain
end

but in order to understand what it is used for in this specific case you probably need to consult the documentation and/or the rest of the code.

One peculiarity in this example: The inner constructor takes multiple arguments (layers...) and creates a tuple out of them, which is assigned to the property layers.

julia> c = Chain(1, 2, "foo")
Chain((1, 2, "foo"))
Related