【问题标题】:ERROR: LoadError: MethodError: no method matching Array(::Type{Int8}, ::Int64, ::Int64, ::Int64)错误:LoadError:MethodError:没有方法匹配 Array(::Type{Int8}, ::Int64, ::Int64, ::Int64)
【发布时间】:2022-01-24 01:57:06
【问题描述】:

我正在使用 Julia v0.7.0 升级为 Julia v0.5.0 编写的软件包。我遇到以下错误:

ERROR: LoadError: MethodError: no method matching Array(::Type{Int8}, ::Int64, ::Int64, ::Int64)
Closest candidates are:
  Array(!Matched::LinearAlgebra.UniformScaling, ::Integer, ::Integer) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v0.7/LinearAlgebra/src/uniformscaling.jl:329
  Array(::Any) where T<:AbstractArray at abstractarray.jl:22
Stacktrace:
 [1] CellularAutomata.CA2d(::Array{Int64,1}, ::Array{Int64,1}, ::Array{Int64,2}, ::Int64, ::Int64, ::Int64) at /home/jafar_isbarov/.julia/dev/CellularAutomata/src/2dim.jl:22
 [2] CellularAutomata.CA2d(::Array{Int64,1}, ::Array{Int64,1}, ::Array{Int64,2}, ::Int64) at /home/jafar_isbarov/.julia/dev/CellularAutomata/src/2dim.jl:21
 [3] turbine_test() at /home/jafar_isbarov/Documents/projects/CellularAutomata.jl/test/conway_test.jl:57
 [4] top-level scope at none:0
 [5] include at ./boot.jl:317 [inlined]
 [6] include_relative(::Module, ::String) at ./loading.jl:1038
 [7] include(::Module, ::String) at ./sysimg.jl:29
 [8] exec_options(::Base.JLOptions) at ./client.jl:239
 [9] _start() at ./client.jl:432
in expression starting at /home/jafar_isbarov/Documents/projects/CellularAutomata.jl/test/runtests.jl:3

这是导致它的行:

cells = Array{Int8}(h, w, gen)

这是整个区块:

mutable struct CA2d

    #User given values
    k::Int #Number of states
    r::Int #r-nearest neigbors

    #Internal values
    cells::Array{Int8, 3}

    function CA2d(B::Array{Int,1},
                  S::Array{Int,1},
                  init::Array{Int,2},
                  gen::Int,
                  k::Int=2,
                  r::Int=1)

        h, w = size(init)
        cells = Array{Int8}(h, w, gen) #Syntax A(T, dims) is deprecated
        cells[:, :, 1] = Array{Int8}(init[:, :])

        for g = 2:gen
            for i = 1:h, j = 1:w
                cc = -cells[i, j, g-1]
                for p = (i-r):(i+r), q = (j-r):(j+r)

                    #Cyclic boundary conditions
                    if p < 1; p = h-p; end
                    if p > h; p = p-h; end
                    if q < 1; q = w-q; end
                    if q > w; q = q-w; end

                    cc += cells[p, q, g-1]
                end
                cells[i, j, g] = eval_rule(cc, cells[i, j, g-1], B, S)
            end #hw ij
        end #gen

        new(k, r, cells)
    end
end

我查过,知道hwgen确实是整数。

你可以找到整个仓库here

编辑: 当我将cells = Array{Int8}(h, w, gen) 替换为cells = Array{Int8}(undef, h, w, gen) 时,出现以下错误:

ERROR: LoadError: MethodError: no method matching Array(::Type{Int8}, ::Int64, ::Int64, ::Int64)
Closest candidates are:
  Array(!Matched::LinearAlgebra.UniformScaling, ::Integer, ::Integer) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v0.7/LinearAlgebra/src/uniformscaling.jl:329
  Array(::Any) where T<:AbstractArray at abstractarray.jl:22
Stacktrace:
 [1] CellularAutomata.CA2d(::Array{Int64,1}, ::Array{Int64,1}, ::Array{Int64,2}, ::Int64, ::Int64, ::Int64) at /home/jafar_isbarov/.julia/dev/CellularAutomata/src/2dim.jl:22
 [2] CellularAutomata.CA2d(::Array{Int64,1}, ::Array{Int64,1}, ::Array{Int64,2}, ::Int64) at /home/jafar_isbarov/.julia/dev/CellularAutomata/src/2dim.jl:21
 [3] turbine_test() at /home/jafar_isbarov/Documents/projects/CellularAutomata.jl/test/conway_test.jl:57
 [4] top-level scope at none:0
 [5] include at ./boot.jl:317 [inlined]
 [6] include_relative(::Module, ::String) at ./loading.jl:1038
 [7] include(::Module, ::String) at ./sysimg.jl:29
 [8] exec_options(::Base.JLOptions) at ./client.jl:239
 [9] _start() at ./client.jl:432
in expression starting at /home/jafar_isbarov/Documents/projects/CellularAutomata.jl/test/runtests.jl:3

【问题讨论】:

    标签: arrays multidimensional-array julia


    【解决方案1】:

    制作一个未初始化的eltype Int8数组:

    Array{Int8}(undef, h, w, gen)
    

    【讨论】:

    • 感谢您的回复,但我仍然收到同样的错误。
    • github.com/ceferisbarov/CellularAutomata.jl/blob/… 您需要更改此行对吗?您是否重新启动了会话?
    • 是的,就是那条线。我直接从终端运行julia07 test/runtests.jl。我还需要重新启动一些东西吗?
    • 那不可能是完全相同的错误吧?因为你真的没有Array(Int8, h, w, gen)
    • 奇怪,如果在那里发生 MethodError,我希望 Array{Int8} 中的 Int8 参数有一些指示,或者 undef 被列为参数。也许这个 undef 调用是在 0.7 中编写的,用于调用旧的 Array(Int8, dims...) 方法,但我无法找到源代码(也许 undef 和这个用于 Array 的方法是核心的东西?)。
    猜你喜欢
    • 2020-07-05
    • 2016-06-04
    • 1970-01-01
    • 2023-03-27
    • 2021-09-21
    • 1970-01-01
    • 2016-12-30
    • 2019-07-27
    • 1970-01-01
    相关资源
    最近更新 更多