Skip to content

Commit

Permalink
Enable precompilation
Browse files Browse the repository at this point in the history
  • Loading branch information
Jutho committed Oct 27, 2017
1 parent a05b93d commit dd75309
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
12 changes: 11 additions & 1 deletion src/WignerSymbols.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__precompile__(false)
__precompile__(true)
module WignerSymbols
export δ, Δ, clebschgordan, wigner3j, wigner6j, racahV, racahW

Expand All @@ -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))

Expand Down
4 changes: 2 additions & 2 deletions src/primefactorization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit dd75309

Please sign in to comment.