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

Overparameterized constructors #1904

Open
Deduction42 opened this issue Sep 23, 2024 · 0 comments
Open

Overparameterized constructors #1904

Deduction42 opened this issue Sep 23, 2024 · 0 comments

Comments

@Deduction42
Copy link

Normally, if I type in something like

Normal{Float32}(0,1) 

based on the default behaviour of constructors, I would expect a response similar to

Normal{Float32}(μ=0.0f0, σ=1.0f0)

where the parameters get converted to the appropriate type. However, instead, I get the following error:

ERROR: MethodError: no method matching Normal{Float32}(::Float64, ::Float64)

When looking at the source code, I see that the default constructor is overwritten:

struct Normal{T<:Real} <: ContinuousUnivariateDistribution
    μ::T
    σ::T
    Normal{T}(µ::T, σ::T) where {T<:Real} = new{T}(µ, σ)
end

Is there any reason why the default constructor is so specific that the input values MUST be the same type as the constructor's parameter?

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

1 participant