首页 > 解决方案 > Julia: "Method error" while calling a parametric function

问题描述

In a file named "func.jl", I defined the following function:

function testXYZ(xi::Array{T, 1}, yi::Array{T, 1}) where {T<:Float64}
    println("Success")
end

In "main.jl" I did build a minimum example:

include("func.jl");
xs = [0.0, 1.2, 2.0, 5.0, 10.0, 11.0]
ys = [2.0, 2.1, 1.0, 0.0, 0.0, 3.0]
testXYZ(xs, ys)

Checking with the console the types of xs and ys, I obtain as expected:

julia> ys = [2.0, 2.1, 1.0, 0.0, 0.0, 3.0];
julia> typeof(ys)
Array{Float64,1}

While exectuting the minimum example in main I obtain a method error:

ERROR: LoadError: MethodError: no method matching +(::Array{Float64,1}, ::String)

In Julia manual, I found lots of similar errors, but no one solved my problem.

标签: julia

解决方案


从@tamasgal 评论中,正确答案是:“错误与上面的代码无关。它说它不能用两个浮点数组执行+,这很好,但是在你的例子中没有调用+。”


推荐阅读