Skip to content

evalpoly is broken for matrices #1161

Open
@LilithHafner

Description

@LilithHafner
help?> evalpoly
evalpoly(x, p)

Evaluate the polynomial \sum_k x^{k-1} p[k] ...

julia> _evalpoly(x, p) = sum(x^(k-1)*p[k] for k in eachindex(p))
_evalpoly (generic function with 1 method)

julia> x = 10*one(zeros(2,2))
2×2 Matrix{Float64}:
 10.0   0.0
  0.0  10.0

julia> p = [1,2,3]
3-element Vector{Int64}:
 1
 2
 3

julia> _evalpoly(x, p)
2×2 Matrix{Float64}:
 321.0    0.0
   0.0  321.0

julia> evalpoly(x, p)
ERROR: MethodError: no method matching +(::Matrix{Float64}, ::Int64)
For element-wise addition, use broadcasting with dot syntax: array .+ scalar
The function `+` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  +(::Any, ::Any, ::Any, ::Any...)
   @ Base operators.jl:596
  +(::BigFloat, ::Union{Int16, Int32, Int64, Int8})
   @ Base mpfr.jl:506
  +(::Base.CoreLogging.LogLevel, ::Integer)
   @ Base logging/logging.jl:132
  ...

Stacktrace:
 [1] muladd(x::Matrix{Float64}, y::Int64, z::Int64)
   @ Base.Math ./math.jl:1470
 [2] _evalpoly
   @ ./math.jl:114 [inlined]
 [3] evalpoly(x::Matrix{Float64}, p::Vector{Int64})
   @ Base.Math ./math.jl:107
 [4] top-level scope
   @ REPL[27]:1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions