File: test_digamma.py

package info (click to toggle)
python-scipy 0.18.1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 75,464 kB
  • ctags: 79,406
  • sloc: python: 143,495; cpp: 89,357; fortran: 81,650; ansic: 79,778; makefile: 364; sh: 265
file content (34 lines) | stat: -rw-r--r-- 1,192 bytes parent folder | download
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
from __future__ import division
import numpy as np
from numpy import pi, log, sqrt
from scipy.special._testutils import FuncData
from scipy.special import digamma

# Euler-Mascheroni constant
euler = 0.57721566490153286


def test_consistency():
    # Make sure the implementation of digamma for real arguments
    # agrees with the implementation of digamma for complex arguments.

    # It's all poles after -1e16
    x = np.r_[-np.logspace(15, -30, 200), np.logspace(-30, 300, 200)]
    dataset = np.vstack((x + 0j, digamma(x))).T
    FuncData(digamma, dataset, 0, 1, rtol=5e-14, nan_ok=True).check()


def test_special_values():
    # Test special values from Gauss's digamma theorem. See
    #
    # https://en.wikipedia.org/wiki/Digamma_function

    dataset = [(1, -euler),
               (0.5, -2*log(2) - euler),
               (1/3, -pi/(2*sqrt(3)) - 3*log(3)/2 - euler),
               (1/4, -pi/2 - 3*log(2) - euler),
               (1/6, -pi*sqrt(3)/2 - 2*log(2) - 3*log(3)/2 - euler),
               (1/8, -pi/2 - 4*log(2) - (pi + log(2 + sqrt(2)) - log(2 - sqrt(2)))/sqrt(2) - euler)]

    dataset = np.asarray(dataset)
    FuncData(digamma, dataset, 0, 1, rtol=1e-14).check()