Limited amount of fields in mutable struct with macros

Hello,

First thanks for this community to be so active, it’s the first out of many problems I could not find a solution to!

I am trying to create mutable structs with a rather large amount of fields ( ~30 ). These structs are very similar so int order to avoid code repetition I created multiple macros and saved the fields in them.
Now my problem is that my constructor does not find some of the fields.
After investigation, the missing fields are the ones which replaced by “⋮” when “calling fieldnames(name of struct)”

I tried to make a similar case (many fields) without the macros, but there everything works…
Any suggestion on this, I am using v0.6 by the way.

Thanks for you help. Théo

Code looks like

@def gaussianparametersfields begin
    μ::Array{Float64,1}
    η_1::Array{Float64,1}
    ζ::Array{Float64,2}
    η_2::Array{Float64,2}
end

mutable struct A
@commonfields
@gaussianparametersfields
@otherfields
*Some constructor*
end
1 Like

Please provide enough information for the code to be run. What is @def? What should I do to generate the error? Examples that can be copy pasted into the REPL are nice.

1 Like

@def is as defined in the documentation :

macro def(name, definition)
    return quote
        macro $(esc(name))()
            esc($(Expr(:quote, definition)))
        end
    end
end

My assumption on the error was wrong. It’s only a few fields that are not recognized. Here is the code that does not work

@def commonfields begin
    #Data
    X #Feature vectors
    y #Labels (-1,1)
    nSamples::Int64 # Number of data points
    nFeatures::Int64 # Number of features
    γ::Float64
    nEpochs::Int64
    µ_init::Array{Float64,1}
    VerboseLevel::Int64
    Stochastic::Bool
    Autotuning::Bool
    ρ_Θ::Array{Float64,1}
    κ_Θ::Float64
    τ_Θ::Int64
    AutotuningFrequency::Int64
    Trained::Bool
    TopMatrixForPrediction
    DownMatrixForPrediction
    MatricesPrecomputed::Bool
end

mutable struct A
@commonfields
end

in(:ρ_Θ, fieldnames(A))

Return false for ρ_Θ, κ_Θ and τ_Θ
Thanks for your quick reply

What documentation? It is not a Base macro.

Anyway, I get:

julia> in(:ρ_Θ, fieldnames(A))
true

julia> in(:κ_Θ, fieldnames(A))
true

julia> in(:τ_Θ, fieldnames(A))
true

On julia v0.6.

What documentation? It is not a Base macro.

It is indeed not in the Base macro, I misexplained myself, it is simply that I have seen many times suggested and thought it was somehow an “official” method.
Anyway, running this exact code still gives me a false statement.
But I just found the cause and this is very vicious:
ρ_Θ and ρ_Θ are not the same according to Julia. Although I wrote them everytime with \thetaerror on theta

(I am running Julia from Ubuntu btw)
Well thanks for your help, I will just change the names to something different

One Greek symbol is uppercase, and one is lowercase?

The thetas there seems to be the same to me? If you enter them in the REPL as a char, e.g:

julia> 'Θ'
'Θ': Unicode U+0398 (category Lu: Letter, uppercase)

what does it say for the two thetas?

From \theta :

'θ': Unicode U+03b8 (category Ll: Letter, lowercase)

From fieldnames

'Θ': Unicode U+0398 (category Lu: Letter, uppercase)

My guess is that the macro interpretated the lowercase θ as an uppercase Θ while in the rest of the code the lowercase is used (without passing by a macro)

Ah, like Petr says, this is just capital theta vs lowercase theta.