-
Notifications
You must be signed in to change notification settings - Fork 34
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
Optimizing Fixed
--> Float
conversions
#171
Comments
(::Type{Tf})(x::Fixed{T,f}) where {Tf <: AbstractFloat, T, f} = Tf(Tf(x.i) * Tf(@exp2(-f)))
Base.Float16(x::Fixed{T,f}) where {T, f} = Float16(Float32(x))
Base.Float32(x::Fixed{T,f}) where {T, f} = Float32(x.i) * Float32(@exp2(-f))
Base.Float64(x::Fixed{T,f}) where {T, f} = Float64(x.i) * @exp2(-f) |
BenchmarkThere seems to be no significant difference between Julia versions or between operating systems. Scriptusing BenchmarkTools
using FixedPointNumbers
struct Vec3{T <: Real}
x::T; y::T; z::T
end
struct Vec4{T <: Real}
x::T; y::T; z::T; w::T
end
Vec3{T}(v::Vec3{T}) where {T} = v
Vec3{T}(v::Vec3{U}) where {T, U} = Vec3{T}(v.x, v.y, v.z)
Vec4{T}(v::Vec4{T}) where {T} = v
Vec4{T}(v::Vec4{U}) where {T, U} = Vec4{T}(v.x, v.y, v.z, v.w)
Base.rand(::Type{Vec3{T}}) where {T} = Vec3{T}(rand(T), rand(T), rand(T))
Base.rand(::Type{Vec4{T}}) where {T} = Vec4{T}(rand(T), rand(T), rand(T), rand(T))
function Base.rand(::Type{T}, sz::Dims) where {T <: Union{Vec3, Vec4}}
A = Array{T}(undef, sz)
for i in eachindex(A); A[i] = rand(T); end
return A
end
Ts = (Q0f7, Q4f3, Q0f15, Q12f3, Q0f31, Q28f3, Q0f63, Q60f3)
mat3s = [rand(Vec3{T}, 64, 64) for T in Ts];
mat4s = [rand(Vec4{T}, 64, 64) for T in Ts];
for mat in mat3s
println(eltype(mat), "-> Float32")
@btime Vec3{Float32}.(view($mat,:,:))
end
for mat in mat3s
println(eltype(mat), "-> Float64")
@btime Vec3{Float64}.(view($mat,:,:))
end
for mat in mat4s
println(eltype(mat), "-> Float32")
@btime Vec4{Float32}.(view($mat,:,:))
end
for mat in mat4s
println(eltype(mat), "-> Float64")
@btime Vec4{Float64}.(view($mat,:,:))
end Julia v1.3.1 x86_64-w64-mingw32julia> versioninfo()
Julia Version 1.3.1
Commit 2d5741174c (2019-12-30 21:36 UTC)
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-6.0.1 (ORCJIT, skylake) Matrix of Vec3 (unit: μs)
Matrix of Vec4 (unit: μs)
Julia v1.0.5 x86_64-pc-linux-gnu on WSLjulia> versioninfo()
Julia Version 1.0.5
Commit 3af96bcefc (2019-09-09 19:06 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-6.0.0 (ORCJIT, skylake) Matrix of Vec3 (unit: μs)
Matrix of Vec4 (unit: μs)
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See: #129 (comment)
Although this has been postponed, this is a issue on conversion, not arithmetic. So, it might be better to include this in the next release (v0.8.0).
The text was updated successfully, but these errors were encountered: