gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 04:05:29 24 4
gpt4 key购买 nike

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

@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 并将 type 更改为 mutable struct。接下来,我被告知在“new{...}”中指定的类型参数太少,所以我添加了FTR作为 new() 调用的类型参数和 where {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)

关于julia - 如何通过 0.7.0 将此类型定义升级到 Julia 1.x?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62564399/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com