1

I am having one function to be executed, it has been compiled but for the execution it shows me a MethodError, here is the function

For this function I'm using SymPy

function op_mat(op)
           op = op.as_poly(domain="C")
           op_a = op.x.gens
           nab = op.length()
           op_ab = ones(SymPy.Sym, nab)
           coef = zeros(Complex, nab)
           mat = zeros(Int64, length(op_a), nab)
           for (i, (ps, c)) in enumerate(op.as_dict())
               for (j, p) in enumerate(ps)
                   mat[j, i] = p
                   op_ab[i] = op_a[j]^p * op_ab[i]
               end
               coef[i] = c
           end

           return op_a, op_ab, mat, coef
       end

The error message that I'm having is this one:

  Complex(::T<:Number) where T<:Number at boot.jl:718
  Complex(::Real) at complex.jl:16
  Complex(::T<:Real, ::T<:Real) where T<:Real at complex.jl:12
  ...
Stacktrace:
 [1] convert(::Type{Complex}, ::Sym) at ./number.jl:7
 [2] setindex!(::Array{Complex,1}, ::Sym, ::Int64) at ./array.jl:766
 [3] op_mat(::Sym) at ./REPL[3]:13
 [4] top-level scope at REPL[7]:1
Word Rearranger
  • 1,306
  • 1
  • 16
  • 25
Marouane1994
  • 534
  • 3
  • 11

1 Answers1

1

since the type of c is Sym i should have only change the type to complex coef[i]=complex(c) or coef[i]=N(c)

Marouane1994
  • 534
  • 3
  • 11
  • You can also specify `coef` more explicitly, as in `coef = zeros(Complex{Float64}, nab)`, and this will allow the conversion to go through. – jverzani Oct 29 '19 at 17:29