-
Notifications
You must be signed in to change notification settings - Fork 44
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
Remove zero(::UnitQuaternion)
#159
Remove zero(::UnitQuaternion)
#159
Conversation
Codecov Report
@@ Coverage Diff @@
## master #159 +/- ##
==========================================
+ Coverage 85.40% 85.57% +0.17%
==========================================
Files 12 12
Lines 1261 1269 +8
==========================================
+ Hits 1077 1086 +9
+ Misses 184 183 -1
Continue to review full report at Codecov.
|
I've also added Before this PRjulia> zero(RotMatrix3{Float64})
3×3 RotMatrix3{Float64} with indices SOneTo(3)×SOneTo(3):
0.0 0.0 0.0
0.0 0.0 0.0
0.0 0.0 0.0 After this PRjulia> zero(RotMatrix3{Float64})
ERROR: ArgumentError: There is no additive identity for Rotation. Consider using the one(RotMatrix3{Float64}) method instead.
Stacktrace:
[1] zero(T::Type{RotMatrix3{Float64}})
@ Rotations ~/.julia/dev/Rotations/src/core_types.jl:14
[2] top-level scope
@ REPL[2]:1 |
src/core_types.jl
Outdated
@@ -11,6 +11,8 @@ Base.@pure StaticArrays.Size(::Type{Rotation{N,T}}) where {N,T} = Size(N,N) | |||
Base.@pure StaticArrays.Size(::Type{R}) where {R<:Rotation} = Size(supertype(R)) | |||
Base.adjoint(r::Rotation) = inv(r) | |||
Base.transpose(r::Rotation{N,T}) where {N,T<:Real} = inv(r) | |||
Base.zero(T::Type{<:Rotation}) = throw(ArgumentError("There is no additive identity for Rotation. Consider using the one($T) method instead.")) | |||
Base.zero(r::Rotation) = throw(ArgumentError("There is no additive identity for Rotation. Consider using the one($(typeof(r))($r)) method instead.")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment at #157 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's an updated error message:
"$T is a subtype of AbstractMatrix, but there is no additive identity for Rotation. To get a non-rotation instance, consider using the one($T) method instead."
Is there any problem with this? I'm not native English speaker, so there may be some mistakes. :)
Thanks @hyrodium. I'm a bit concerned about the argument error, though. Every rotation is meant to be a fully-functioning Currently we have: julia> r = one(RotMatrix3{Float64})
3×3 RotMatrix3{Float64} with indices SOneTo(3)×SOneTo(3):
1.0 0.0 0.0
0.0 1.0 0.0
0.0 0.0 1.0
julia> r + r
3×3 StaticArrays.SMatrix{3, 3, Float64, 9} with indices SOneTo(3)×SOneTo(3):
2.0 0.0 0.0
0.0 2.0 0.0
0.0 0.0 2.0
julia> zero(r)
3×3 RotMatrix3{Float64} with indices SOneTo(3)×SOneTo(3):
0.0 0.0 0.0
0.0 0.0 0.0
0.0 0.0 0.0 EDIT - we should fix up this last one We are extending the |
At first, I thought I'll fix it! |
I've updated the julia> zero(MRP)
3×3 StaticArrays.SMatrix{3, 3, Float64, 9} with indices SOneTo(3)×SOneTo(3):
0.0 0.0 0.0
0.0 0.0 0.0
0.0 0.0 0.0
julia> zero(RotMatrix{3})
3×3 StaticArrays.SMatrix{3, 3, Float64, 9} with indices SOneTo(3)×SOneTo(3):
0.0 0.0 0.0
0.0 0.0 0.0
0.0 0.0 0.0
julia> zero(RotMatrix{2})
2×2 StaticArrays.SMatrix{2, 2, Float64, 4} with indices SOneTo(2)×SOneTo(2):
0.0 0.0
0.0 0.0
julia> zero(Angle2d)
2×2 StaticArrays.SMatrix{2, 2, Float64, 4} with indices SOneTo(2)×SOneTo(2):
0.0 0.0
0.0 0.0 But, there sitll be some issues around julia> zeros(MRP,2)
2-element Vector{MRP}:
[1.0 0.0 0.0; 0.0 1.0 0.0; 0.0 0.0 1.0]
[1.0 0.0 0.0; 0.0 1.0 0.0; 0.0 0.0 1.0]
julia> zeros(RotMatrix{3},2)
2-element Vector{RotMatrix{3, T, L} where {T, L}}:
[0.0 0.0 0.0; 0.0 0.0 0.0; 0.0 0.0 0.0]
[0.0 0.0 0.0; 0.0 0.0 0.0; 0.0 0.0 0.0]
julia> zeros(RotMatrix{2},2)
2-element Vector{RotMatrix{2, T, L} where {T, L}}:
[0.0 0.0; 0.0 0.0]
[0.0 0.0; 0.0 0.0]
julia> zeros(Angle2d,2)
2-element Vector{Angle2d}:
Error showing value of type Vector{Angle2d}:
ERROR: MethodError: no method matching cos(::NTuple{4, Float64}) I'll fix them after tomorrow. |
Awesome.
There was an old discussion at julialang/julia about this once... here's a recent one quoting the docs: JuliaLang/julia#40796 (comment) Basically we want things like |
I've updated julia> zeros(MRP,2)
2-element Vector{StaticArrays.SMatrix{3, 3, Float64, 9}}:
[0.0 0.0 0.0; 0.0 0.0 0.0; 0.0 0.0 0.0]
[0.0 0.0 0.0; 0.0 0.0 0.0; 0.0 0.0 0.0]
julia> zeros(RotMatrix{3},2)
2-element Vector{StaticArrays.SMatrix{3, 3, Float64, 9}}:
[0.0 0.0 0.0; 0.0 0.0 0.0; 0.0 0.0 0.0]
[0.0 0.0 0.0; 0.0 0.0 0.0; 0.0 0.0 0.0]
julia> zeros(RotMatrix{2},2)
2-element Vector{StaticArrays.SMatrix{2, 2, Float64, 4}}:
[0.0 0.0; 0.0 0.0]
[0.0 0.0; 0.0 0.0]
julia> zeros(Angle2d,2)
2-element Vector{StaticArrays.SMatrix{2, 2, Float64, 4}}:
[0.0 0.0; 0.0 0.0]
[0.0 0.0; 0.0 0.0] Usually, |
Thanks for the information! |
bump :) |
This PR fixes #157.