jverzani / SymPyCore.jl

Package to help connect Julia with the SymPy library of Python
https://jverzani.github.io/SymPyCore.jl/
MIT License
5 stars 4 forks source link

Transpose of symbolic vector #42

Closed michakraus closed 6 months ago

michakraus commented 6 months ago

The result of transposing a symbolic vector is a transpose object with element type Any instead of Sym:

julia> T = SymPy.Sym{PyCall.PyObject};

julia> x = T.([1, 2])
2-element Vector{Sym{PyCall.PyObject}}:
 1
 2

julia> transpose(x)
1×2 transpose(::Vector{Sym{PyCall.PyObject}}) with eltype Any:
 1  2

For a matrix, on the other hand, the correct result is obtained:

julia> A = T.([1  2; 3  4])
2×2 Matrix{Sym{PyCall.PyObject}}:
 1  2
 3  4

julia> transpose(A)
2×2 Matrix{Sym{PyCall.PyObject}}:
 1  3
 2  4
jverzani commented 6 months ago

Thanks for the report!!

michakraus commented 6 months ago

Thanks a lot for fixing this so quickly. In Julia >1.8 everything works, but there seems to be an issue still with v1.6:

  Element type mismatch. Tried to create a `Transpose{SymPyCore.Sym}` from an object with eltype `SymPyCore.Sym`, but the element type of the transpose of an object with eltype `SymPyCore.Sym` must be `Any`.
  Stacktrace:
    [1] error(s::String)
      @ Base ./error.jl:33
    [2] checkeltype_transpose(#unused#::Type{SymPyCore.Sym}, #unused#::Type{SymPyCore.Sym})
      @ LinearAlgebra /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/LinearAlgebra/src/adjtrans.jl:86
    [3] LinearAlgebra.Transpose{SymPyCore.Sym, Vector{SymPyCore.Sym}}(A::Vector{SymPyCore.Sym})
      @ LinearAlgebra /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/LinearAlgebra/src/adjtrans.jl:69
    [4] transpose(A::Vector{SymPyCore.Sym})
      @ SymPyCore ~/.julia/packages/SymPyCore/PayoX/src/matrix.jl:24

This comes from a call like transpose(x) in the example above.

I am not married to Julia v1.6. I just saw this popping up in the CI workflows and thought you might want to know.

jverzani commented 6 months ago

Thanks! I had missed this