Julia语言中结构中的数组问题

Julia语言中结构中的数组问题,julia,Julia,我对以下结构有问题: struct OdeSol{typ, rng, n} t::rng x::Array{typ} v::Array{typ} end OdeSol(typ, rng, n) = OdeSol(rng, Array{typ}(undef, n, length(rng)), Array{typ}(undef, n, length(rng))) 其中t\u range=tlim[1]:Δt:tlim[2],typeof(x0[1])是Float64,si

我对以下结构有问题:

struct OdeSol{typ, rng, n}
    t::rng
    x::Array{typ}
    v::Array{typ}
end

OdeSol(typ, rng, n) = OdeSol(rng, Array{typ}(undef, n, length(rng)), Array{typ}(undef, n, length(rng)))
其中
t\u range=tlim[1]:Δt:tlim[2]
typeof(x0[1])
Float64
size(x0)[1]
是一个整数(
size(x0)[1]
=
2

当我启动
sol=OdeSol(typeof(x0[1])、t_范围、大小(x0[1])
时,我得到了以下错误:

MethodError: no method matching Array{0.0:0.01:10.0,N} where N(::UndefInitializer, ::Array{Float64,2}, ::Int64)
Closest candidates are:
  Array{0.0:0.01:10.0,N} where N(::UndefInitializer, !Matched::Int64, ::Int64) where T at boot.jl:421
  Array{0.0:0.01:10.0,N} where N(::UndefInitializer, !Matched::Int64, ::Int64, !Matched::Int64) where T at boot.jl:422
  Array{0.0:0.01:10.0,N} where N(::UndefInitializer, !Matched::Integer, ::Integer) where T at baseext.jl:17
  ...

Stacktrace:
 [1] OdeSol(::StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}, ::Array{Float64,2}, ::Array{Float64,2}) at ./In[10]:8 (repeats 2 times)
 [2] top-level scope at In[11]:1
 [3] include_string(::Function, ::Module, ::String, ::String) at ./loading.jl:1091

有人能帮我吗?

您似乎在将参数类型与
结构中的字段值混合在一起。
除此之外,使用大写字母作为类型名称也是值得的。
从参数上看,您似乎也在寻找矩阵(即二维数组)/

也许你的意思是:

struct OdeSol{T, R}
    t::R
    x::Matrix{T}
    v::Matrix{T}
end

OdeSol{T,R}(rng::R, n) where {T,R} = OdeSol{T,R}(rng, Matrix{T}(undef, n, length(rng)), Matrix{T}(undef, n, length(rng)))
现在是示例用法:

julia> OdeSol{Int, Vector{Int}}([1,2,3],4)
OdeSol{Int64,Array{Int64,1}}([1, 2, 3], [0 0 0; 0 0 0; 0 0 0; 0 0 0], [0 0 0; 0 0 0; 0 0 0; 0 0 0])

您的错误与您声称已运行的错误不匹配。您传入的范围为
top
,矩阵为
rng
,矩阵为
n
。这些类型中没有一个与您声称的名称相匹配。这与
struct
定义毫无关系;退一步,确保您知道每个参数是什么。您也确实希望这些数组类型注释是向量,否则字段类型是抽象的,因为没有指定维度数。