Polynomials.jl icon indicating copy to clipboard operation
Polynomials.jl copied to clipboard

A bug?

Open andreasvarga opened this issue 4 years ago • 6 comments

I started some cleaning of my tests for rational transfer functions. The following fails and was commented out for RationalTransferFunctions. It seems however, it doesn't work for RationalFunctions too.

julia> using LinearAlgebra

julia> using Polynomials

julia> s = RationalFunction(Polynomial([0,1],:s))
(s) // (1)

julia> [s^2 s/(s+1); I]
ERROR: ArgumentError: number of columns of each array must match (got (2, 1))
Stacktrace:
 [1] _typed_vcat(#unused#::Type{Any}, A::Tuple{Matrix{Any}, Matrix{Any}})
   @ Base .\abstractarray.jl:1553
 [2] typed_vcat(::Type{Any}, ::Matrix{Any}, ::Matrix{Any})
   @ Base .\abstractarray.jl:1567
 [3] typed_hvcat(::Type{Any}, ::Tuple{Int64, Int64}, ::RationalFunction{Int64, :s, Polynomial{Int64, :s}}, ::Vararg{Any, N} where N)
   @ Base .\abstractarray.jl:1957
 [4] hvcat(::Tuple{Int64, Int64}, ::RationalFunction{Int64, :s, Polynomial{Int64, :s}}, ::Vararg{Any, N} where N)
   @ Base .\abstractarray.jl:1932
 [5] top-level scope
   @ REPL[4]:1

andreasvarga avatar Nov 07 '21 11:11 andreasvarga

I'm thinking I really wants to be a square matrix:

julia> using LinearAlgebra

julia> [1 2; I]
ERROR: ArgumentError: number of columns of each array must match (got (2, 1))

This works, but ends up with an odd type:

julia> [s^2 s/(s+1); 0  I]
2×2 Matrix{Any}:
  (s^2) // (1)  (s) // (1 + s)
 0              UniformScaling{Bool}(true)

but the same is true if s is just a number.

jverzani avatar Nov 07 '21 12:11 jverzani

Interesting. Thus, this is an error in LinearAlgebra. Should I make an issue for this?

Recently I fighted with type piracy in DescriptorSystems. I was not able to get rid of it, but enhanced my handling of such cases (e.g., by internally converting the above to [[1] [2]; I], which works). Now I realize, this was not entirely my fault!

andreasvarga avatar Nov 07 '21 13:11 andreasvarga

I'd say it is a design choice, where I is always square. What are you expecting the output to be?

On Sun, Nov 7, 2021 at 8:02 AM Andreas Varga @.***> wrote:

Interesting. Thus, this is an error in LinearAlgebra. Should I make an issue for this?

Recently I fighted with type piracy in DescriptorSystems. I was not able to get rid of it, but enhanced my handling of such cases (e.g., by internally converting the above to [[1] [2]; I], which works). Now I realize, this was not entirely my fault!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/JuliaMath/Polynomials.jl/issues/365#issuecomment-962606854, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADG6TD6GBZA4LERGDYB7CLUKZ2F5ANCNFSM5HQWLEWQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

-- John Verzani Department of Mathematics College of Staten Island, CUNY

jverzani avatar Nov 07 '21 13:11 jverzani

Only the square case is implemented in LinearAlgebra.UniformScaling at line #394: promote_to_arrays_(n::Int, ::Type{Matrix}, J::UniformScaling{T}) where {T} = copyto!(Matrix{T}(undef, n,n), J)

With my handling of type piracy I get:

julia> using DescriptorSystems
[ Info: Precompiling DescriptorSystems [a81e2ce2-54d1-11eb-2c75-db236b00f339]


julia> [1 2; I]
3×2 Matrix{Int64}:
 1  2
 1  0
 0  1

I would be happy to get the same with LinearAlgebra too.

andreasvarga avatar Nov 07 '21 13:11 andreasvarga

I see. That makes some sense at first glance.

On Sun, Nov 7, 2021 at 8:35 AM Andreas Varga @.***> wrote:

Only the square case is implemented in LinearAlgebra.UniformScaling at line #394: promote_to_arrays_(n::Int, ::Type{Matrix}, J::UniformScaling{T}) where {T} = copyto!(Matrix{T}(undef, n,n), J)

With my handling of type piracy I get:

julia> using DescriptorSystems

[ Info: Precompiling DescriptorSystems [a81e2ce2-54d1-11eb-2c75-db236b00f339]

julia> [1 2; I]

3×2 Matrix{Int64}:

1 2

1 0

0 1

I would be happy to get the same with LinearAlgebra too.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/JuliaMath/Polynomials.jl/issues/365#issuecomment-962611779, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADG6TDIFFKF6ZCSSDMLSRTUKZ6DHANCNFSM5HQWLEWQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

-- John Verzani Department of Mathematics College of Staten Island, CUNY

jverzani avatar Nov 07 '21 17:11 jverzani

Apparently we have to wait for Julia 1.8 to be fixed in LinearAlgebra. Should we close this issue?

andreasvarga avatar Nov 08 '21 10:11 andreasvarga