How do I upgrade this type definition to Julia 1.x via 0.7.0?

Viewed 48

I'm new to Julia and I am trying to upgrade the package BayesianDataFusion.jl from Julia 0.4.7 to 1.x via 0.7.0. The package defines a new type Entity as follows:

@compat type Entity{FT,R}
  F::FT
  FF
  use_FF::Bool
  Frefs::Vector{Future}
  relations::Vector{R}
  count::Int64
  name::AbstractString

  modes::Vector{Int}
  modes_other::Vector{Vector{Int}}

  lambda_beta::Float64
  lambda_beta_sample::Bool
  mu::Float64   ## Hyper-prior for lambda_beta
  nu::Float64   ## Hyper-prior for lambda_beta

  model::EntityModel
  @compat Entity(F, relations::Vector{R}, count::Int64, name::AbstractString, lb::Float64=1.0, lb_sample::Bool=true, mu=1.0, nu=1e-3) = new(F, zeros(0,0), false, Future[], relations, count, name, Int[], Vector{Int}[], lb, lb_sample, mu, nu)
end

Entity(name::AbstractString; F=zeros(0,0), lambda_beta=1.0) = Entity{Any,Relation}(F::Any, Relation[], 0, name, lambda_beta)

I began by making the obvious changes, including removing the two @compats and changing type to mutable struct. Next, I was notified that there were too few type parameters specified in "new{...}" and so I added FT and R as type parameters to the new() call and where {FT,R} to the left-hand side of the assignment on the line before end.

The type definition now looks like this:

mutable struct Entity{FT,R}
  F::FT
  FF
  use_FF::Bool
  Frefs::Vector{Future}
  relations::Vector{R}
  count::Int64
  name::AbstractString

  modes::Vector{Int}
  modes_other::Vector{Vector{Int}}

  lambda_beta::Float64
  lambda_beta_sample::Bool
  mu::Float64   ## Hyper-prior for lambda_beta
  nu::Float64   ## Hyper-prior for lambda_beta

  model::EntityModel
  Entity(F, relations::Vector{R}, count::Int64, name::AbstractString, lb::Float64=1.0, lb_sample::Bool=true, mu=1.0, nu=1e-3) where {FT,R} = new{FT,R}(F, zeros(0,0), false, Future[], relations, count, name, Int[], Vector{Int}[], lb, lb_sample, mu, nu)
end

Entity(name::AbstractString; F=zeros(0,0), lambda_beta=1.0) = Entity{Any,Relation}(F::Any, Relation[], 0, name, lambda_beta)

However, I am now seeing an error I do not understand:

ERROR: LoadError: LoadError: MethodError: no method matching Entity{Any,Relation}(::Array{Float64,2}, ::Array{Relation,1}, ::Int64, ::String, ::Float64)

I reread the Julia documentation on types, and based on my understanding, there is a method matching the given signature.

Isn't that exactly what the code on the last line defines?

1 Answers

You are calling inner constructor, not struct constructor, and inner constructor do not have a parametric definition, so you just need to remove it

Entity(name::AbstractString; F=zeros(0,0), lambda_beta=1.0) = Entity(F, Relation[], 0, name, lambda_beta)

Also, may be it's a typo, but you've missed type annotation in inner constructor, it should be (notice F::FT)

Entity(F::FT, relations::Vector{R}, count::Int64, name::AbstractString, lb::Float64=1.0, lb_sample::Bool=true, mu=1.0, nu=1e-3) where {FT,R} = new{FT,R}(F, zeros(0,0), false, Future[], relations, count, name, Int[], Vector{Int}[], lb, lb_sample, mu, nu)
Related