Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coefficient type determination for an empty polynomial matrix #309

Open
andreasvarga opened this issue Feb 6, 2021 · 5 comments
Open

Coefficient type determination for an empty polynomial matrix #309

andreasvarga opened this issue Feb 6, 2021 · 5 comments

Comments

@andreasvarga
Copy link

This is possibly a silly question, but is related to the previous issue #308 .

Admitedly we have an empty polynomial matrix, created for example with the command:

julia> a=Polynomial.(rand(0,0))
0×0 Array{Polynomial{Float64},2}

julia> eltype(a)
Polynomial{Float64}

how it is possible to determine the type of coefficients (in the above case Float64).
For a nonempty matrix, this is easy

julia> a=Polynomial.(rand(1,1))
1×1 Array{Polynomial{Float64},2}:
 Polynomial(0.8736304322844237)

julia> eltype(a[1])
Float64
@andreasvarga andreasvarga changed the title Element type determination for an empty polynomial matrix Coefficient type determination for an empty polynomial matrix Feb 6, 2021
@jverzani
Copy link
Member

jverzani commented Feb 6, 2021

I think I'd suggest eltype(eltype(a)). But I'm not getting the same thing as you (though I'm on a new branch where the symbol is part of the type):

julia> a = Polynomial.(rand(0,0))
0×0 Array{Any,2}

julia> eltype(a)
Any

Whereas:

julia> p = Polynomial([1,2,3])
Polynomial(1 + 2*x + 3*x^2)

julia> a = [p p^2; -p^2 1]
2×2 Array{Polynomial{Int64,:x},2}:
 Polynomial(1 + 2*x + 3*x^2)                     …  Polynomial(1 + 4*x + 10*x^2 + 12*x^3 + 9*x^4)
 Polynomial(-1 - 4*x - 10*x^2 - 12*x^3 - 9*x^4)     Polynomial(1)

julia> eltype(eltype(a))
Int64

@andreasvarga
Copy link
Author

andreasvarga commented Feb 6, 2021 via email

@jverzani
Copy link
Member

jverzani commented Feb 7, 2021

I'm not certain I am answering the question you are getting at, but that construct is just applying the function eltype twice (once to get that eltype of the array and again to get that of the polynomial).

@andreasvarga
Copy link
Author

I think this issue can be closed. However, I wonder if the following is in the current version correct:

a=Polynomial.(rand(0,0))
0×0 Matrix{Any}

In an earlier version (see my first entry) it was

a=Polynomial.(rand(0,0))
0×0 Array{Polynomial{Float64},2}

@jverzani
Copy link
Member

Yeah, I'm not sure why this changed. I thought maybe a change to broadcasting, but the behaviour is there under v1.0 too. Must be a change to the constructor. I was about to type you just need to specify the type, as in Polynomial{Float64}.(rand(0,0)), but even that failed. You need to put in the symbol too: Polynomial{Float64,:x}.(rand(0,0)).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants