如何通过0.7.0将此类型定义升级到Julia 1.x?

如何通过0.7.0将此类型定义升级到Julia 1.x?,julia,Julia,我是Julia的新手,我正在尝试通过0.7.0将软件包从Julia 0.4.7升级到1.x。包定义了一个新的类型实体,如下所示: @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{Ve

我是Julia的新手,我正在尝试通过0.7.0将软件包从Julia 0.4.7升级到1.x。包定义了一个新的类型
实体
,如下所示:

@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)
我首先做了一些明显的更改,包括删除两个
@compat
并将
类型更改为
可变结构。接下来,我被告知在“new{…}”中指定的类型参数太少,因此我将
FT
R
作为类型参数添加到
new()
调用中,并将
其中{FT,R}
添加到
end
之前一行的赋值左侧

类型定义现在如下所示:

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)
但是,我现在看到了一个我不理解的错误:

ERROR: LoadError: LoadError: MethodError: no method matching Entity{Any,Relation}(::Array{Float64,2}, ::Array{Relation,1}, ::Int64, ::String, ::Float64)
我重新阅读了关于类型的Julia文档,根据我的理解,有一个方法匹配给定的签名


这不正是最后一行代码定义的吗?

您调用的是内部构造函数,而不是结构构造函数,并且内部构造函数没有参数定义,所以只需要删除它

Entity(name::AbstractString; F=zeros(0,0), lambda_beta=1.0) = Entity(F, Relation[], 0, name, lambda_beta)
另外,可能是输入错误,但您在内部构造函数中遗漏了类型注释,应该是这样的(注意
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)