Skip to content

Commit

Permalink
first attempt to (exclusive) v0.7 compatibility
Browse files Browse the repository at this point in the history
first attempt to (exclusive) v0.7 compatibility
  • Loading branch information
Jutho authored Jun 21, 2018
2 parents 0b8be07 + dd208b4 commit cf7c940
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 147 deletions.
3 changes: 1 addition & 2 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
julia 0.6
julia 0.7.0-alpha
Primes
Compat
17 changes: 5 additions & 12 deletions src/WignerSymbols.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@ __precompile__(true)
module WignerSymbols
export δ, Δ, clebschgordan, wigner3j, wigner6j, racahV, racahW

if VERSION <= v"0.7.0-DEV.262"
include("mpz.jl")
using .MPZ
else
using Base.GMP.MPZ
end

using Compat
using Base.GMP.MPZ

include("halfinteger.jl")
include("primefactorization.jl")
Expand Down Expand Up @@ -293,8 +286,8 @@ function compute3jseries(β₁, β₂, β₃, α₁, α₂)
krange = max(α₁, α₂, zero(α₁)):min(β₁, β₂, β₃)
T = PrimeFactorization{eltype(eltype(factorialtable))}

nums = Vector{T}(uninitialized, length(krange))
dens = Vector{T}(uninitialized, length(krange))
nums = Vector{T}(undef, length(krange))
dens = Vector{T}(undef, length(krange))
for (i, k) in enumerate(krange)
num = iseven(k) ? one(T) : -one(T)
den = primefactorial(k)*primefactorial(k-α₁)*primefactorial(k-α₂)*
Expand All @@ -312,8 +305,8 @@ function compute6jseries(β₁, β₂, β₃, α₁, α₂, α₃, α₄)
krange = max(α₁, α₂, α₃, α₄):min(β₁, β₂, β₃)
T = PrimeFactorization{eltype(eltype(factorialtable))}

nums = Vector{T}(uninitialized, length(krange))
dens = Vector{T}(uninitialized, length(krange))
nums = Vector{T}(undef, length(krange))
dens = Vector{T}(undef, length(krange))
for (i, k) in enumerate(krange)
num = iseven(k) ? primefactorial(k+1) : -primefactorial(k+1)
den = primefactorial(k-α₁)*primefactorial(k-α₂)*primefactorial(k-α₃)*
Expand Down
116 changes: 0 additions & 116 deletions src/mpz.jl

This file was deleted.

8 changes: 3 additions & 5 deletions src/primefactorization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ struct PrimeIterator
end
primes() = PrimeIterator()

Compat.IteratorSize(::Type{PrimeIterator}) = Base.IsInfinite()
Compat.IteratorEltype(::Type{PrimeIterator}) = Base.HasEltype()
Base.IteratorSize(::Type{PrimeIterator}) = Base.IsInfinite()
Base.IteratorEltype(::Type{PrimeIterator}) = Base.HasEltype()
Base.eltype(::PrimeIterator) = Int

# Get the `n`th prime; store all primes up to the `n`th if not yet available
Expand All @@ -30,9 +30,7 @@ function prime(n::Int)
@inbounds return primetable[n]
end

Base.start(::PrimeIterator) = 1
Base.next(::PrimeIterator, n) = prime(n), n+1
Base.done(::PrimeIterator, n) = false
Base.iterate(::PrimeIterator, n = 1) = prime(n), n+1

# get primes and their powers as `BigInt`, also cache all results
function bigprime(n::Integer, e::Integer=1)
Expand Down
19 changes: 7 additions & 12 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
if VERSION < v"0.7.0-DEV.2005"
const Test = Base.Test
end

using Test
using WignerSymbols
using Compat
using Compat.LinearAlgebra
using LinearAlgebra

smalljlist = 0:1//2:10
largejlist = 0:1//2:1000

@testset "triangle coefficient" begin
for j1 in smalljlist, j2 in smalljlist
for j3 = abs(j1-j2):(j1+j2)
@test Δ(j1,j2,j3) sqrt(factorial(float(j1+j2-j3))*factorial(float(j1-j2+j3))*
factorial(float(j2+j3-j1))/factorial(float(j1+j2+j3+1)))
@test Δ(j1,j2,j3) sqrt(factorial(big(Int(j1+j2-j3)))*factorial(big(Int(j1-j2+j3)))*
factorial(big(Int(j2+j3-j1)))/factorial(big(Int(j1+j2+j3+1))))
end
end
end
Expand All @@ -25,7 +20,7 @@ end
for j1 in smalljlist, j2 in smalljlist
d1 = 2*j1+1
d2 = 2*j2+1
M = zeros(d1*d2, d1*d2)
M = zeros(Float64, (d1*d2, d1*d2))
ind1 = 1
for m1 in -j1:j1, m2 in -j2:j2
ind2 = 1
Expand Down Expand Up @@ -67,7 +62,7 @@ end
j6range = max(abs(j2-j4),abs(j1-j5)):min((j2+j4),(j1+j5))
j3range = max(abs(j1-j2),abs(j4-j5)):min((j1+j2),(j4+j5))
@test length(j6range) == length(j3range)
M = zeros(length(j3range),length(j6range))
M = zeros(Float64, (length(j3range), length(j6range)))
for (k2,j6) in enumerate(j6range)
for (k1,j3) in enumerate(j3range)
M[k1,k2] = sqrt(2*j3+1)*sqrt(2*j6+1)*wigner6j(j1,j2,j3,j4,j5,j6)
Expand Down Expand Up @@ -115,8 +110,8 @@ end
m1range = -j1:j1
m2range = -j2:j2
m3range = -j3:j3
V1 = Array{Float64}(uninitialized, length(m1range),length(m2range),length(m3range))
V2 = Array{Float64}(uninitialized, length(m1range),length(m2range),length(m3range))
V1 = Array{Float64}(undef, length(m1range),length(m2range),length(m3range))
V2 = Array{Float64}(undef, length(m1range),length(m2range),length(m3range))
for J in max(abs(j1-j2-j3),abs(j1-j2+j3),abs(j1+j2-j3)):(j1+j2+j3)
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))
Expand Down

0 comments on commit cf7c940

Please sign in to comment.