Skip to content

Commit f647feb

Browse files
authored
Precompile methods for common types (#148)
1 parent 49627e2 commit f647feb

File tree

4 files changed

+35
-3
lines changed

4 files changed

+35
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Manifest.toml

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ os:
44
- osx
55
julia:
66
- 1.0
7-
- 1.1
7+
- 1.2
88
- nightly
99
notifications:
1010
email: false

src/FixedPointNumbers.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
VERSION < v"0.7.0-beta2.199" && __precompile__()
2-
31
module FixedPointNumbers
42

53
import Base: ==, <, <=, -, +, *, /, ~, isapprox,
@@ -199,4 +197,7 @@ end
199197
rand(::Type{T}) where {T <: FixedPoint} = reinterpret(T, rand(rawtype(T)))
200198
rand(::Type{T}, sz::Dims) where {T <: FixedPoint} = reinterpret(T, rand(rawtype(T), sz))
201199

200+
include("precompile.jl")
201+
_precompile_()
202+
202203
end # module

src/precompile.jl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
function _precompile_()
2+
ccall(:jl_generating_output, Cint, ()) == 1 || return nothing
3+
normedtypes = (N0f8, N0f16) # precompiled Normed types
4+
realtypes = (Float16, Float32, Float64, Int) # types for mixed Normed/Real operations
5+
for T in normedtypes
6+
for f in (+, -, abs, eps, rand) # unary operations
7+
@assert precompile(Tuple{typeof(f),T})
8+
end
9+
@assert precompile(Tuple{typeof(rand),T,Tuple{Int}})
10+
@assert precompile(Tuple{typeof(rand),T,Tuple{Int,Int}})
11+
for f in (trunc, floor, ceil, round) # rounding operations
12+
@assert precompile(Tuple{typeof(f),T})
13+
@assert precompile(Tuple{typeof(f),Type{Int},T})
14+
end
15+
for f in (+, -, *, /, <, <=, ==) # binary operations
16+
@assert precompile(Tuple{typeof(f),T,T})
17+
for S in realtypes
18+
@assert precompile(Tuple{typeof(f),T,S})
19+
@assert precompile(Tuple{typeof(f),S,T})
20+
end
21+
end
22+
# conversions
23+
for S in realtypes
24+
@assert precompile(Tuple{Type{T},S})
25+
@assert precompile(Tuple{Type{S},T})
26+
@assert precompile(Tuple{typeof(convert),Type{T},S})
27+
@assert precompile(Tuple{typeof(convert),Type{S},T})
28+
end
29+
end
30+
end

0 commit comments

Comments
 (0)