Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

display fieldnames in show of a container #2543

Open
CarloLucibello opened this issue Dec 7, 2024 · 2 comments
Open

display fieldnames in show of a container #2543

CarloLucibello opened this issue Dec 7, 2024 · 2 comments

Comments

@CarloLucibello
Copy link
Member

CarloLucibello commented Dec 7, 2024

I think it would be helpfuld to display the fieldnames in our bigshow.
For example, we currently have

julia> rnn = RNN(4 => 6)
RNN(
  RNNCell(4 => 6, tanh),                # 66 parameters
)     

that could become

julia> rnn = RNN(4 => 6)
RNN(
  cell = RNNCell(4 => 6, tanh),                # 66 parameters
)     
@CarloLucibello CarloLucibello changed the title display fieldname in show of a container display fieldnames in show of a container Dec 7, 2024
@mcabbott
Copy link
Member

mcabbott commented Dec 7, 2024

The present recursion roughly assumes the existence of the default constructor. This instead assumes the existence of a keyword constructor, which is much less common:

julia> RNN(
         cell = RNNCell(4 => 6, tanh),                # 66 parameters
       )
ERROR: MethodError: no method matching RNN(; cell::RNNCell{typeof(tanh), Matrix{Float32}, Matrix{Float32}, Vector{Float32}})
The type `RNN` exists, but no method is defined for this combination of argument types when trying to construct it.

Closest candidates are:
...
  RNN(::M) where M got unsupported keyword argument "cell"
   @ Flux ~/.julia/packages/Flux/5vIRy/src/layers/recurrent.jl:171

You could put field names in the comment without breaking anything, # .cell, 66 parameters.

It does show names for some where a keyword constructor is known to exist. That mechanism could surely be made more generalisable it someone wants it enough:

julia> Chain(one=RNN(4 => 6, tanh), two=identity)
Chain(
  one = RNN(
    RNNCell(4 => 6, tanh),              # 66 parameters
  ),
  two = identity,
)                   # Total: 3 arrays, 66 parameters, 424 bytes.

@CarloLucibello
Copy link
Member Author

This is because you want the output to be a valid constructor when copy-pasted, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants