From dd75309fe600b944db76d99676cc8a41dac6cdd1 Mon Sep 17 00:00:00 2001 From: Jutho Haegeman Date: Fri, 27 Oct 2017 16:28:53 +0200 Subject: [PATCH] Enable precompilation --- src/WignerSymbols.jl | 12 +++++++++++- src/primefactorization.jl | 4 ++-- test/runtests.jl | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/WignerSymbols.jl b/src/WignerSymbols.jl index b695e27..6ebc9d6 100644 --- a/src/WignerSymbols.jl +++ b/src/WignerSymbols.jl @@ -1,4 +1,4 @@ -__precompile__(false) +__precompile__(true) module WignerSymbols export δ, Δ, clebschgordan, wigner3j, wigner6j, racahV, racahW @@ -7,6 +7,16 @@ include("primefactorization.jl") const Wigner3j = Dict{Tuple{UInt,UInt,UInt,Int,Int},Tuple{Rational{BigInt},Rational{BigInt}}}() const Wigner6j = Dict{NTuple{6,UInt},Tuple{Rational{BigInt},Rational{BigInt}}}() +function __init__() + global bigone, bigprimetable, Wigner3j, Wigner6j + bigone[] = big(1) + bigprimetable[1][1] = big(2) + bigprimetable[2][1] = big(3) + bigprimetable[3][1] = big(5) + Base.rehash!(Wigner3j) + Base.rehash!(Wigner6j) +end + # check integerness and correctness of (j,m) angular momentum ϵ(j, m) = (abs(m) <= j && isinteger(j-m) && isinteger(j+m)) diff --git a/src/primefactorization.jl b/src/primefactorization.jl index e0145b5..c0891bf 100644 --- a/src/primefactorization.jl +++ b/src/primefactorization.jl @@ -13,6 +13,7 @@ const primetable = [2,3,5] const factortable = [UInt8[], UInt8[1], UInt8[0,1], UInt8[2], UInt8[0,0,1]] const factorialtable = [UInt32[], UInt32[], UInt32[1], UInt32[1,1], UInt32[3,1], UInt32[3,1,1]] const bigprimetable = [[big(2)], [big(3)], [big(5)]] +const bigone = Ref{BigInt}(big(1)) # Make a prime iterator struct PrimeIterator @@ -42,9 +43,8 @@ Base.next(::PrimeIterator, n) = prime(n), n+1 Base.done(::PrimeIterator, n) = false # get primes and their powers as `BigInt`, also cache all results -const bigone = big(1) function bigprime(n::Integer, e::Integer=1) - e == 0 && return bigone + e == 0 && return bigone[] p = prime(n) # triggers computation of prime(n) if necessary @inbounds l = length(bigprimetable[n]) @inbounds while l < e diff --git a/test/runtests.jl b/test/runtests.jl index 70ec8ca..f59b6d2 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -119,7 +119,7 @@ end J12range = max(abs(j1-j2),abs(J-j3)):min((j1+j2),(J+j3)) J23range = max(abs(j2-j3),abs(j1-J)):min((j2+j3),(j1+J)) for J12 in J12range, J23 in J23range - M = J # only test for J, should be independent + M = rand(-J:J) # only test for one instance of M in -J:J, should be independent of M anyway fill!(V1,0) fill!(V2,0) for (k1,m1) in enumerate(m1range)