functionjulianosuchmethoderror

Error in Julia: LoadError: MethodError: no method matching isless(::Vector{Int64}, ::Int64)


I am writing a code in julia but I am getting this error: LoadError: MethodError: no method matching isless(::Vector{Int64}, ::Int64). The part of mu code is:

X = []
function form(;a, b, c, d,e)
if a == 1 && b == 0
        @assert c <= 1000 "error."
    else
        @error failed"
end
.....
push!(x, form(a=2, b=5, c=[0,0], d=[0,1], e=[0,0]))







Solution

  • The error is telling you that there is no method for checking if a vector is less than an integer. You can write .<= to broadcast the less-than comparison, which will perform the comparison element by element, but then you will want any or all or some other logic to transform that comparison output into a single true/false.

    julia> [0, 0] <= 1000
    ERROR: MethodError: no method matching isless(::Vector{Int64}, ::Int64)
    Closest candidates are:
      isless(::AbstractVector, ::AbstractVector) at abstractarray.jl:2612
      isless(::AbstractFloat, ::Real) at operators.jl:186
      isless(::Real, ::Real) at operators.jl:434
      ...
    Stacktrace:
     [1] <(x::Vector{Int64}, y::Int64)
       @ Base .\operators.jl:356
     [2] <=(x::Vector{Int64}, y::Int64)
       @ Base .\operators.jl:405
     [3] top-level scope
       @ REPL[1]:1
    
    julia> [0, 0] .<= 1000
    2-element BitVector:
     1
     1
    
    julia> any([0, 1003] .<= 1000)
    true
    
    julia> all([0, 0] .<= 1000)
    true