-
Notifications
You must be signed in to change notification settings - Fork 21
/
precompile.jl
109 lines (106 loc) · 4.15 KB
/
precompile.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
macro warnpcfail(ex::Expr)
modl = __module__
file = __source__.file === nothing ? "?" : String(__source__.file)
line = __source__.line
quote
$(esc(ex)) || @warn """precompile directive
$($(Expr(:quote, ex)))
failed. Please report an issue in $($modl) (after checking for duplicates) or remove this directive.""" _file=$file _line=$line
end
end
function pcarray(f::F, ::Type{A}, sz) where {F,A}
a = f(A(undef, sz))
fill!(a, zero(eltype(a)))
return first(a)
end
function pcm(a1, a2; fillvalue = zero(eltype(a1)))
v = mosaic(a1, a2; fillvalue=fillvalue)
return first(v)
end
function pcmv(a; fillvalue = zero(eltype(a)))
v = mosaicview(a; fillvalue=fillvalue)
return first(v)
end
function _precompile_()
ccall(:jl_generating_output, Cint, ()) == 1 || return nothing
eltypes = (N0f8, N0f16, Float32, Float64) # eltypes of parametric colors
pctypes = (Gray, RGB, AGray, GrayA, ARGB, RGBA) # parametric colors
cctypes = (Gray24, AGray32, RGB24, ARGB32) # non-parametric colors
dims = (1, 2, 3, 4)
szs = ((2,), (2, 2), (2, 2, 2), (2, 2, 2, 2))
for T in eltypes
@warnpcfail precompile(clamp01, (T,))
@warnpcfail precompile(clamp01nan, (T,))
@warnpcfail precompile(scaleminmax, (T, T))
@warnpcfail precompile(scalesigned, (T,))
@warnpcfail precompile(scalesigned, (T,T,T))
for C in pctypes
@warnpcfail precompile(clamp01, (C{T},))
@warnpcfail precompile(clamp01nan, (C{T},))
@warnpcfail precompile(colorsigned, (C{T},C{T}))
end
end
for C in cctypes
@warnpcfail precompile(clamp01, (C,))
@warnpcfail precompile(clamp01nan, (C,))
@warnpcfail precompile(colorsigned, (C,C))
end
# For the arrays, it's better to make them and exercise them so we get the getindex/setindex!
# methods precompiled too.
for sz in szs
for T in eltypes
T <: FixedPoint || continue
pcarray(rawview, Array{T,length(sz)}, sz)
end
pcarray(normedview, Array{UInt8,length(sz)}, sz)
pcarray(a->normedview(N0f8, a), Array{UInt8, length(sz)}, sz)
pcarray(a->normedview(N0f16, a), Array{UInt16,length(sz)}, sz)
end
for sz in szs
for T in eltypes
for C in pctypes
nc = sizeof(C{T}) ÷ sizeof(T)
if nc == 1
pcarray(a->colorview(C, a), Array{T,length(sz)}, sz)
pcarray(a->colorview(C{T}, a), Array{T,length(sz)}, sz)
else
pcarray(a->colorview(C, a), Array{T,length(sz)+1}, (nc, sz...))
pcarray(a->colorview(C{T}, a), Array{T,length(sz)+1}, (nc, sz...))
end
pcarray(channelview, Array{C{T},length(sz)}, sz)
if T<:FixedPoint
R = FixedPointNumbers.rawtype(T)
if nc == 1
pcarray(a->colorview(C, normedview(T, a)), Array{R,length(sz)}, sz)
pcarray(a->colorview(C{T}, normedview(T, a)), Array{R,length(sz)}, sz)
else
pcarray(a->colorview(C, normedview(T, a)), Array{R,length(sz)+1}, (nc, sz...))
pcarray(a->colorview(C{T}, normedview(T, a)), Array{R,length(sz)+1}, (nc, sz...))
end
end
end
end
T, C = Bool, Gray
pcarray(a->colorview(C, a), Array{T,length(sz)}, sz)
pcarray(a->colorview(C{T}, a), Array{T,length(sz)}, sz)
pcarray(channelview, Array{C{T},length(sz)}, sz)
end
for T in eltypes
a = zeros(T, (2, 2))
a3 = zeros(T, (2, 2, 2))
pcm(a, a)
pcmv(a3)
for C in (Gray, RGB, GrayA, RGBA)
a = zeros(C{T}, (2, 2))
a3 = zeros(C{T}, (2, 2, 3))
pcm(a, a)
pcmv(a3)
if C === RGB
pcm(a, a; fillvalue=zero(Gray{T}))
elseif C === RGBA
pcm(a, a; fillvalue=zero(GrayA{T}))
end
end
end
pcm(zeros(Float32, 2, 2), zeros(Float64, 2, 2)) # heterogeneous
end