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

Error returning eltype of SMatrix #423

Closed
getzze opened this issue May 30, 2018 · 6 comments
Closed

Error returning eltype of SMatrix #423

getzze opened this issue May 30, 2018 · 6 comments

Comments

@getzze
Copy link

getzze commented May 30, 2018

Testing package GLVisualize.jl, I got an error in GLAbstarction.jl (https://github.com/JuliaGL/GLAbstraction.jl/blob/master/src/GLMatrixMath.jl). The error is:

LoadError: TypeError: UnionAll: expected Type, got Int64

It points to this function in GLMatrixMath.jl:

function (::Type{M})(q::Quaternions.Quaternion) where M <: Mat{3}
    T = eltype(M)
    sx, sy, sz = 2q.s*q.v1, 2q.s*q.v2,  2q.s*q.v3
    xx, xy, xz = 2q.v1^2,   2q.v1*q.v2, 2q.v1*q.v3
    yy, yz, zz = 2q.v2^2,   2q.v2*q.v3, 2q.v3^2
    T0, T1 = zero(T), one(T)
    Mat{3}(
        T1-(yy+zz), xy+sz,      xz-sy,
        xy-sz,      T1-(xx+zz), yz+sx,
        xz+sy,      yz-sx,      T1-(xx+yy)
    )
end

I figured out that checking the element type of some SMatrix gives me the same error:

eltype(Mat{3,3,Int, 9})  # Int64
eltype(Mat{3,3,Int})  # TypeError: UnionAll: expected Type, got Int64
eltype(Mat{3,Int})  # TypeError: UnionAll: expected Type, got Int64
eltype(Mat{Int})  # Any
eltype(Mat{3})  # TypeError: UnionAll: expected Type, got Int64

Is it related to the error in GLAbstarction.jl?

@tkoolen
Copy link
Contributor

tkoolen commented May 30, 2018

I can't reproduce with Julia 0.6.2 (or master) and StaticArrays master:

julia> using StaticArrays.FixedSizeArrays

julia> eltype(Mat{3,3,Int, 9})  # Int64
Int64

julia> eltype(Mat{3,3,Int})  # TypeError: UnionAll: expected Type, got Int64
Int64

julia> eltype(Mat{3,Int})  # TypeError: UnionAll: expected Type, got Int64
Any

julia> eltype(Mat{Int})  # Any
Any

julia> eltype(Mat{3})  # TypeError: UnionAll: expected Type, got Int64
Any

@getzze
Copy link
Author

getzze commented Jun 4, 2018

I'm using Julia 0.6.3 on ArchLinux. With a fresh start of julia (without loading any module), I get:

julia> using StaticArrays.FixedSizeArrays

julia> eltype(Mat{3,3,Int, 9})  # Int64
Int64

julia> eltype(Mat{3,3,Int})  # TypeError: UnionAll: expected Type, got Int64
Int64

julia> eltype(Mat{3,Int})  # TypeError: UnionAll: expected Type, got Int64
ERROR: TypeError: UnionAll: expected Type, got Int64

julia> eltype(Mat{Int})  # Any
ERROR: TypeError: UnionAll: expected Type, got Int64

julia> eltype(Mat{3})  # TypeError: UnionAll: expected Type, got Int64
Any

julia> eltype(Mat{3,3})
Any

I don't remember which modules were loaded last time, so I cannot reproduce. I still cannot load GLAbstraction.js though.

@tkoolen
Copy link
Contributor

tkoolen commented Jun 4, 2018

On 0.6.3 with StaticArrays master I can now reproduce the behavior in #423 (comment). Mat{3,Int} and Mat{Int} don't really make sense though (the first two type parameters should be integer values). The other ones produce the correct results, so I'm not sure if this is actionable.

I guess a better error message would be nice, but Julia currently has no way of expressing the constraint that a type parameter should be an integer value (e.g. 3), so in order to provide a better error message when methods are called on StaticArrays Types with 'nonsensical' type parameters, a check would need to be added to every such method.

By the way, the method in the issue description is technically type piracy. But in general, if you want to be able to write Mat{3}(q), you should probably define something like

function Mat{3}(q::Quaternions.Quaternion{T}) where {T}
    sx, sy, sz = 2q.s*q.v1, 2q.s*q.v2,  2q.s*q.v3
    xx, xy, xz = 2q.v1^2,   2q.v1*q.v2, 2q.v1*q.v3
    yy, yz, zz = 2q.v2^2,   2q.v2*q.v3, 2q.v3^2
    T0, T1 = zero(T), one(T)
    Mat{3}(
        T1-(yy+zz), xy+sz,      xz-sy,
        xy-sz,      T1-(xx+zz), yz+sx,
        xz+sy,      yz-sx,      T1-(xx+yy)
    )
end

Also note that Rotations.jl exists, is built on top of StaticArrays, and already has this functionality and a lot more.

@KristofferC
Copy link
Contributor

Probably fixed by JuliaLang/julia#27404.

@getzze
Copy link
Author

getzze commented Jun 4, 2018

Ok, thanks a lot! I will report to the GLAbstraction.jl package maintainer.
Edit: JuliaGL/GLAbstraction.jl#91

@c42f
Copy link
Member

c42f commented Jul 31, 2019

This has long since been sorted out elsewhere I think.

@c42f c42f closed this as completed Jul 31, 2019
@c42f c42f mentioned this issue Oct 22, 2019
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

4 participants