Skip to content

Commit 3e9c187

Browse files
authored
Merge pull request #72 from putianyi889/master
Make pochhammer more robust
2 parents d2add70 + 055248f commit 3e9c187

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

src/specialfunctions.jl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,7 @@ function pochhammer(x::Number,n::Integer)
4545
ret
4646
end
4747

48-
pochhammer(x::AbstractArray{T,1},n::Integer) where {T<:Number} = [pochhammer(x[i],n) for i=1:length(x)]
49-
pochhammer(x::AbstractArray{T,2},n::Integer) where {T<:Number} = [pochhammer(x[i,j],n) for i=1:size(x,1),j=1:size(x,2)]
50-
pochhammer(x::AbstractArray{T},n::Integer) where {T<:Number} = reshape([ pochhammer(x[i],n) for i in eachindex(x) ], size(x))
51-
52-
pochhammer(x::Number,n::Number) = gamma(x+n)/gamma(x)
53-
pochhammer(x::AbstractArray{T},n::Number) where {T<:Number} = gamma(x+n)./gamma(x)
48+
pochhammer(x::Number,n::Number) = isinteger(n) ? pochhammer(x,Int(n)) : ogamma(x)/ogamma(x+n)
5449

5550
function pochhammer(x::Number,n::UnitRange{T}) where T<:Real
5651
ret = Vector{promote_type(typeof(x),T)}(length(n))
@@ -61,6 +56,8 @@ function pochhammer(x::Number,n::UnitRange{T}) where T<:Real
6156
ret
6257
end
6358

59+
ogamma(x::Number) = (isinteger(x) && x<0) ? zero(float(x)) : inv(gamma(x))
60+
6461
"""
6562
Stirling's asymptotic series for ``\\Gamma(z)``.
6663
"""

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ include("butterflytests.jl")
2828
include("sphericalharmonics/sphericalharmonictests.jl")
2929

3030
include("toeplitztests.jl")
31+
32+
include("specialfunctionstests.jl")

test/specialfunctionstests.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using FastTransforms
2+
using Compat.Test
3+
import FastTransforms.pochhammer
4+
5+
const sqrtpi = 1.772453850905516027298
6+
7+
@testset "Pochhammer" begin
8+
@test pochhammer(2,3) == 24
9+
@test pochhammer(0.5,3) == 0.5*1.5*2.5
10+
@test pochhammer(0.5,0.5) == 1/sqrtpi
11+
@test pochhammer(0,1) == 0
12+
@test pochhammer(-1,2) == 0
13+
@test pochhammer(-5,3) == -60
14+
@test pochhammer(-1,-0.5) == 0
15+
@test 1.0/pochhammer(-0.5,-0.5) == 0
16+
@test pochhammer(-1+0im,-1) == -0.5
17+
end

0 commit comments

Comments
 (0)