Пример #1
0
def test_bernoulli():
    if NumCpp.NO_USE_BOOST:
        return

    value = np.random.randint(0, 20)
    assert (roundScaler(NumCpp.bernoulli_Scaler(value), NUM_DECIMALS_ROUND) ==
            roundScaler(sp.bernoulli(value)[-1], NUM_DECIMALS_ROUND))
Пример #2
0
def bernoulli(k):
    """ The kth Bernoulli number.

    This function is written as a look-up table for the first few Bernoulli numbers for speed. The Bernoulli number definition we use is:

    .. math::
       \\frac{x}{e^x - 1} \\equiv \\sum_{n = 0}^\\infty \\frac{B_n x^n}{n!} \\,.

    Parameters
    ----------
    k : int
        The Bernoulli number to return.

    Returns
    -------
    float
        The kth Bernoulli number.
    """

    import scipy.special as sp

    B_n = np.array([
        1, -1 / 2, 1 / 6, 0, -1 / 30, 0, 1 / 42, 0, -1 / 30, 0, 5 / 66, 0,
        -691 / 2730, 0, 7 / 6, 0, -3617 / 510, 0, 43867 / 798, 0,
        -174611 / 330, 0, 854513 / 138
    ])

    if k <= 22:
        return B_n[k]
    else:
        return sp.bernoulli(k)[-1]
Пример #3
0
def dexpinv(g, h, order=5):
    r"""
    Inverse of the derivative of the exponential map.

    .. math::
        dexp^{-1} : \mathfrak{g} \rightarrow T\mathfrak{g}

    Evaluates the map by the following formula:

    .. math::
        dexp_g^{-1}(h) = h - \frac{1}{2}[g,h] + \frac{B_2}{2!}[g,[g,h]] + \cdots = \sum_{k=0}^{\text{order}}
         \frac{B_k}{k!}\text{ad}_g^k(h)

    where :math:`B_k` are the :math:`k`-th Bernioulli numbers. The infinite series is truncated at `order`.

    :param g: Element of a Lie algebra.
    :param h:
    :param order:
    :return:

    +------------------------+-----------------+-----------------+
    | Valid kwargs           | Default Value   | Valid Values    |
    +========================+=================+=================+
    | order                  | 5               | > 0             |
    +------------------------+-----------------+-----------------+

    """

    if g.abelian:
        return LieAlgebra(h)
    if order < 2:
        return h

    B = bernoulli(order)

    def adg(e):
        return commutator(g, e)

    k = 0
    stack = h
    out = B[k] * h

    k = 1
    stack = adg(stack)
    out += B[k] * stack
    k += 1

    while k < order:
        stack = adg(stack)
        out += B[k] / factorial(k) * stack
        k += 2

    return out
Пример #4
0
 def test_bernoulli(self):
     assert_mpmath_equal(lambda n: sc.bernoulli(int(n))[int(n)],
                         lambda n: float(mpmath.bernoulli(int(n))),
                         [IntArg(0, 13000)],
                         rtol=1e-9, n=13000)
Пример #5
0
 def test_bernoulli(self):
     assert_mpmath_equal(lambda n: sc.bernoulli(int(n))[int(n)],
                         lambda n: float(mpmath.bernoulli(int(n))),
                         [IntArg(0, 13000)],
                         rtol=1e-9,
                         n=13000)
Пример #6
0
def doTest():
    print(colored('Testing Special Module', 'magenta'))

    print(colored('Testing airy_ai scaler', 'cyan'))
    value = np.random.rand(1).item()
    if (roundScaler(NumCpp.airy_ai_Scaler(value),
                    NUM_DECIMALS_ROUND) == roundScaler(
                        sp.airy(value)[0].item(), NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing airy_ai array', 'cyan'))
    shapeInput = np.random.randint(20, 100, [
        2,
    ])
    shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item())
    cArray = NumCpp.NdArray(shape)
    data = np.random.rand(shape.rows, shape.cols)
    cArray.setArray(data)
    if np.array_equal(
            roundArray(NumCpp.airy_ai_Array(cArray), NUM_DECIMALS_ROUND),
            roundArray(sp.airy(data)[0], NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing airy_ai_prime scaler', 'cyan'))
    value = np.random.rand(1).item()
    if (roundScaler(NumCpp.airy_ai_prime_Scaler(value),
                    NUM_DECIMALS_ROUND) == roundScaler(
                        sp.airy(value)[1].item(), NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing airy_ai_prime array', 'cyan'))
    shapeInput = np.random.randint(20, 100, [
        2,
    ])
    shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item())
    cArray = NumCpp.NdArray(shape)
    data = np.random.rand(shape.rows, shape.cols)
    cArray.setArray(data)
    if np.array_equal(
            roundArray(NumCpp.airy_ai_prime_Array(cArray), NUM_DECIMALS_ROUND),
            roundArray(sp.airy(data)[1], NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing airy_bi scaler', 'cyan'))
    value = np.random.rand(1).item()
    if (roundScaler(NumCpp.airy_bi_Scaler(value),
                    NUM_DECIMALS_ROUND) == roundScaler(
                        sp.airy(value)[2].item(), NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing airy_bi array', 'cyan'))
    shapeInput = np.random.randint(20, 100, [
        2,
    ])
    shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item())
    cArray = NumCpp.NdArray(shape)
    data = np.random.rand(shape.rows, shape.cols)
    cArray.setArray(data)
    if np.array_equal(
            roundArray(NumCpp.airy_bi_Array(cArray), NUM_DECIMALS_ROUND),
            roundArray(sp.airy(data)[2], NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing airy_bi_prime scaler', 'cyan'))
    value = np.random.rand(1).item()
    if (roundScaler(NumCpp.airy_bi_prime_Scaler(value),
                    NUM_DECIMALS_ROUND) == roundScaler(
                        sp.airy(value)[3].item(), NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing airy_bi_prime array', 'cyan'))
    shapeInput = np.random.randint(20, 100, [
        2,
    ])
    shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item())
    cArray = NumCpp.NdArray(shape)
    data = np.random.rand(shape.rows, shape.cols)
    cArray.setArray(data)
    if np.array_equal(
            roundArray(NumCpp.airy_bi_prime_Array(cArray), NUM_DECIMALS_ROUND),
            roundArray(sp.airy(data)[3], NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing bernoulli scaler', 'cyan'))
    value = np.random.randint(0, 20)
    if (roundScaler(NumCpp.bernoulli_Scaler(value),
                    NUM_DECIMALS_ROUND) == roundScaler(
                        sp.bernoulli(value)[-1], NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing bessel_in scaler', 'cyan'))
    order = np.random.randint(0, 10)
    value = np.random.rand(1).item()
    if (roundScaler(NumCpp.bessel_in_Scaler(order, value),
                    NUM_DECIMALS_ROUND) == roundScaler(
                        sp.iv(order, value).item(), NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing bessel_in array', 'cyan'))
    shapeInput = np.random.randint(20, 100, [
        2,
    ])
    shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item())
    cArray = NumCpp.NdArray(shape)
    order = np.random.randint(0, 10)
    data = np.random.rand(shape.rows, shape.cols)
    cArray.setArray(data)
    if np.array_equal(
            roundArray(NumCpp.bessel_in_Array(order, cArray),
                       NUM_DECIMALS_ROUND),
            roundArray(sp.iv(order, data), NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing bessel_in_prime scaler', 'cyan'))
    order = np.random.randint(0, 10)
    value = np.random.rand(1).item()
    if (roundScaler(NumCpp.bessel_in_prime_Scaler(order, value),
                    NUM_DECIMALS_ROUND) == roundScaler(
                        sp.ivp(order, value).item(), NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing bessel_in_prime array', 'cyan'))
    shapeInput = np.random.randint(20, 100, [
        2,
    ])
    shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item())
    cArray = NumCpp.NdArray(shape)
    order = np.random.randint(0, 10)
    data = np.random.rand(shape.rows, shape.cols)
    cArray.setArray(data)
    if np.array_equal(
            roundArray(NumCpp.bessel_in_prime_Array(order, cArray),
                       NUM_DECIMALS_ROUND),
            roundArray(sp.ivp(order, data), NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing bessel_jn scaler', 'cyan'))
    order = np.random.randint(0, 10)
    value = np.random.rand(1).item()
    if (roundScaler(NumCpp.bessel_jn_Scaler(order, value),
                    NUM_DECIMALS_ROUND) == roundScaler(
                        sp.jv(order, value).item(), NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing bessel_jn array', 'cyan'))
    shapeInput = np.random.randint(20, 100, [
        2,
    ])
    shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item())
    cArray = NumCpp.NdArray(shape)
    order = np.random.randint(0, 10)
    data = np.random.rand(shape.rows, shape.cols)
    cArray.setArray(data)
    if np.array_equal(
            roundArray(NumCpp.bessel_jn_Array(order, cArray),
                       NUM_DECIMALS_ROUND),
            roundArray(sp.jv(order, data), NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing bessel_jn_prime scaler', 'cyan'))
    order = np.random.randint(0, 10)
    value = np.random.rand(1).item()
    if (roundScaler(NumCpp.bessel_jn_prime_Scaler(order, value),
                    NUM_DECIMALS_ROUND) == roundScaler(
                        sp.jvp(order, value).item(), NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing bessel_jn_prime array', 'cyan'))
    shapeInput = np.random.randint(20, 100, [
        2,
    ])
    shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item())
    cArray = NumCpp.NdArray(shape)
    order = np.random.randint(0, 10)
    data = np.random.rand(shape.rows, shape.cols)
    cArray.setArray(data)
    if np.array_equal(
            roundArray(NumCpp.bessel_jn_prime_Array(order, cArray),
                       NUM_DECIMALS_ROUND),
            roundArray(sp.jvp(order, data), NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing bessel_kn scaler', 'cyan'))
    order = np.random.randint(0, 10)
    value = np.random.rand(1).item()
    if (roundScaler(NumCpp.bessel_kn_Scaler(order, value),
                    NUM_DECIMALS_ROUND) == roundScaler(
                        sp.kn(order, value).item(), NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing bessel_kn array', 'cyan'))
    shapeInput = np.random.randint(20, 100, [
        2,
    ])
    shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item())
    cArray = NumCpp.NdArray(shape)
    order = np.random.randint(0, 5)
    data = np.random.rand(shape.rows, shape.cols)
    cArray.setArray(data)
    if np.array_equal(
            roundArray(NumCpp.bessel_kn_Array(order, cArray),
                       NUM_DECIMALS_ROUND),
            roundArray(sp.kn(order, data), NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing bessel_kn_prime scaler', 'cyan'))
    order = np.random.randint(0, 5)
    value = np.random.rand(1).item()
    if (roundScaler(NumCpp.bessel_kn_prime_Scaler(order, value),
                    NUM_DECIMALS_ROUND) == roundScaler(
                        sp.kvp(order, value).item(), NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing bessel_kn_prime array', 'cyan'))
    shapeInput = np.random.randint(20, 100, [
        2,
    ])
    shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item())
    cArray = NumCpp.NdArray(shape)
    order = np.random.randint(0, 5)
    data = np.random.rand(shape.rows, shape.cols)
    cArray.setArray(data)
    if np.array_equal(
            roundArray(NumCpp.bessel_kn_prime_Array(order, cArray),
                       NUM_DECIMALS_ROUND),
            roundArray(sp.kvp(order, data), NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing bessel_yn scaler', 'cyan'))
    order = np.random.randint(0, 5)
    value = np.random.rand(1).item()
    if (roundScaler(NumCpp.bessel_yn_Scaler(order, value),
                    NUM_DECIMALS_ROUND) == roundScaler(
                        sp.yn(order, value).item(), NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing bessel_yn array', 'cyan'))
    shapeInput = np.random.randint(20, 100, [
        2,
    ])
    shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item())
    cArray = NumCpp.NdArray(shape)
    order = np.random.randint(0, 5)
    data = np.random.rand(shape.rows, shape.cols)
    cArray.setArray(data)
    if np.array_equal(
            roundArray(NumCpp.bessel_yn_Array(order, cArray),
                       NUM_DECIMALS_ROUND),
            roundArray(sp.yn(order, data), NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing bessel_yn_prime scaler', 'cyan'))
    order = np.random.randint(0, 5)
    value = np.random.rand(1).item()
    if (roundScaler(NumCpp.bessel_yn_prime_Scaler(order, value),
                    NUM_DECIMALS_ROUND) == roundScaler(
                        sp.yvp(order, value).item(), NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing bessel_yn_prime array', 'cyan'))
    shapeInput = np.random.randint(20, 100, [
        2,
    ])
    shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item())
    cArray = NumCpp.NdArray(shape)
    order = np.random.randint(0, 5)
    data = np.random.rand(shape.rows, shape.cols)
    cArray.setArray(data)
    if np.array_equal(
            roundArray(NumCpp.bessel_yn_prime_Array(order, cArray),
                       NUM_DECIMALS_ROUND),
            roundArray(sp.yvp(order, data), NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing beta scaler', 'cyan'))
    a = np.random.rand(1).item() * 10
    b = np.random.rand(1).item() * 10
    if (roundScaler(NumCpp.beta_Scaler(a, b),
                    NUM_DECIMALS_ROUND) == roundScaler(
                        sp.beta(a, b).item(), NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing beta array', 'cyan'))
    shapeInput = np.random.randint(20, 100, [
        2,
    ])
    shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item())
    aArray = NumCpp.NdArray(shape)
    bArray = NumCpp.NdArray(shape)
    a = np.random.rand(shape.rows, shape.cols) * 10
    b = np.random.rand(shape.rows, shape.cols) * 10
    aArray.setArray(a)
    bArray.setArray(b)
    if np.array_equal(
            roundArray(NumCpp.beta_Array(aArray, bArray), NUM_DECIMALS_ROUND),
            roundArray(sp.beta(a, b), NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing cnr', 'cyan'))
    n = np.random.randint(0, 50)
    r = np.random.randint(0, n + 1)
    if round(NumCpp.cnr(n, r)) == round(sp.comb(n, r)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing cyclic_hankel_1', 'cyan'))
    order = np.random.randint(0, 6)
    value = np.random.rand(1).item() * 10
    if (roundComplex(complex(NumCpp.cyclic_hankel_1(order, value)),
                     NUM_DECIMALS_ROUND) == roundComplex(
                         sp.hankel1(order, value), NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing cyclic_hankel_2', 'cyan'))
    order = np.random.randint(0, 6)
    value = np.random.rand(1).item() * 10
    if (roundComplex(complex(NumCpp.cyclic_hankel_2(order, value)),
                     NUM_DECIMALS_ROUND) == roundComplex(
                         sp.hankel2(order, value), NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing digamma scaler', 'cyan'))
    value = np.random.rand(1).item() * 10
    if (roundScaler(NumCpp.digamma_Scaler(value),
                    NUM_DECIMALS_ROUND) == roundScaler(sp.digamma(value),
                                                       NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing digamma array', 'cyan'))
    shapeInput = np.random.randint(20, 100, [
        2,
    ])
    shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item())
    cArray = NumCpp.NdArray(shape)
    data = np.random.rand(shape.rows, shape.cols) * 10
    cArray.setArray(data)
    if np.array_equal(
            roundArray(NumCpp.digamma_Array(cArray), NUM_DECIMALS_ROUND),
            roundArray(sp.digamma(data), NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing erf scaler', 'cyan'))
    value = np.random.rand(1).item()
    if (roundScaler(NumCpp.erf_Scaler(value),
                    NUM_DECIMALS_ROUND) == roundScaler(sp.erf(value),
                                                       NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing erf array', 'cyan'))
    shapeInput = np.random.randint(20, 100, [
        2,
    ])
    shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item())
    cArray = NumCpp.NdArray(shape)
    data = np.random.rand(shape.rows, shape.cols)
    cArray.setArray(data)
    if np.array_equal(roundArray(NumCpp.erf_Array(cArray), NUM_DECIMALS_ROUND),
                      roundArray(sp.erf(data), NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing erf_inv scaler', 'cyan'))
    value = np.random.rand(1).item()
    if (roundScaler(NumCpp.erf_inv_Scaler(value),
                    NUM_DECIMALS_ROUND) == roundScaler(sp.erfinv(value),
                                                       NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing erf_inv array', 'cyan'))
    shapeInput = np.random.randint(20, 100, [
        2,
    ])
    shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item())
    cArray = NumCpp.NdArray(shape)
    data = np.random.rand(shape.rows, shape.cols)
    cArray.setArray(data)
    if np.array_equal(
            roundArray(NumCpp.erf_inv_Array(cArray), NUM_DECIMALS_ROUND),
            roundArray(sp.erfinv(data), NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing erfc scaler', 'cyan'))
    value = np.random.rand(1).item()
    if (roundScaler(NumCpp.erfc_Scaler(value),
                    NUM_DECIMALS_ROUND) == roundScaler(sp.erfc(value),
                                                       NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing erfc array', 'cyan'))
    shapeInput = np.random.randint(20, 100, [
        2,
    ])
    shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item())
    cArray = NumCpp.NdArray(shape)
    data = np.random.rand(shape.rows, shape.cols)
    cArray.setArray(data)
    if np.array_equal(
            roundArray(NumCpp.erfc_Array(cArray), NUM_DECIMALS_ROUND),
            roundArray(sp.erfc(data), NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing erfc_inv scaler', 'cyan'))
    value = np.random.rand(1).item()
    if (roundScaler(NumCpp.erfc_inv_Scaler(value),
                    NUM_DECIMALS_ROUND) == roundScaler(sp.erfcinv(value),
                                                       NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing erfc_inv array', 'cyan'))
    shapeInput = np.random.randint(20, 100, [
        2,
    ])
    shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item())
    cArray = NumCpp.NdArray(shape)
    data = np.random.rand(shape.rows, shape.cols)
    cArray.setArray(data)
    if np.array_equal(
            roundArray(NumCpp.erfc_inv_Array(cArray), NUM_DECIMALS_ROUND),
            roundArray(sp.erfcinv(data), NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing factorial scaler', 'cyan'))
    n = np.random.randint(0, 170)
    if (roundScaler(NumCpp.factorial_Scaler(n),
                    NUM_DECIMALS_ROUND) == roundScaler(
                        sp.factorial(n).item(), NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing factorial array', 'cyan'))
    shapeInput = np.random.randint(20, 100, [
        2,
    ])
    shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item())
    cArray = NumCpp.NdArrayUInt32(shape)
    data = np.random.randint(0, 170, [shape.rows, shape.cols])
    cArray.setArray(data)
    if np.array_equal(
            roundArray(NumCpp.factorial_Array(cArray), NUM_DECIMALS_ROUND),
            roundArray(sp.factorial(data), NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing gamma scaler', 'cyan'))
    value = np.random.rand(1).item()
    if (roundScaler(NumCpp.gamma_Scaler(value),
                    NUM_DECIMALS_ROUND) == roundScaler(sp.gamma(value),
                                                       NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing gamma array', 'cyan'))
    shapeInput = np.random.randint(20, 100, [
        2,
    ])
    shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item())
    cArray = NumCpp.NdArray(shape)
    data = np.random.rand(shape.rows, shape.cols)
    cArray.setArray(data)
    if np.array_equal(
            roundArray(NumCpp.gamma_Array(cArray), NUM_DECIMALS_ROUND),
            roundArray(sp.gamma(data), NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    # There is no scipy equivalent to this function
    print(colored('Testing gamma1pm1 scaler', 'cyan'))
    value = np.random.rand(1).item()
    answer = NumCpp.gamma1pm1_Scaler(value)
    print(colored('\tPASS', 'green'))

    print(colored('Testing gamma1pm1 array', 'cyan'))
    shapeInput = np.random.randint(20, 100, [
        2,
    ])
    shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item())
    cArray = NumCpp.NdArray(shape)
    data = np.random.rand(shape.rows, shape.cols)
    cArray.setArray(data)
    answer = NumCpp.gamma1pm1_Array(cArray)
    print(colored('\tPASS', 'green'))

    print(colored('Testing log_gamma scaler', 'cyan'))
    value = np.random.rand(1).item()
    if (roundScaler(NumCpp.log_gamma_Scaler(value),
                    NUM_DECIMALS_ROUND) == roundScaler(sp.loggamma(value),
                                                       NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing log_gamma array', 'cyan'))
    shapeInput = np.random.randint(20, 100, [
        2,
    ])
    shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item())
    cArray = NumCpp.NdArray(shape)
    data = np.random.rand(shape.rows, shape.cols)
    cArray.setArray(data)
    if np.array_equal(
            roundArray(NumCpp.log_gamma_Array(cArray), NUM_DECIMALS_ROUND),
            roundArray(sp.loggamma(data), NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing pnr', 'cyan'))
    n = np.random.randint(0, 10)
    r = np.random.randint(0, n + 1)
    if round(NumCpp.pnr(n, r)) == round(sp.perm(n, r)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing polygamma scaler', 'cyan'))
    order = np.random.randint(1, 5)
    value = np.random.rand(1).item()
    if (roundScaler(NumCpp.polygamma_Scaler(order, value),
                    NUM_DECIMALS_ROUND) == roundScaler(
                        sp.polygamma(order, value).item(),
                        NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing polygamma array', 'cyan'))
    order = np.random.randint(1, 5)
    shapeInput = np.random.randint(20, 100, [
        2,
    ])
    shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item())
    cArray = NumCpp.NdArray(shape)
    data = np.random.rand(shape.rows, shape.cols)
    cArray.setArray(data)
    if np.array_equal(
            roundArray(NumCpp.polygamma_Array(order, cArray),
                       NUM_DECIMALS_ROUND),
            roundArray(sp.polygamma(order, data), NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    # There is no scipy equivalent to this function
    print(colored('Testing prime scaler', 'cyan'))
    value = np.random.randint(10000)
    answer = NumCpp.prime_Scaler(value)
    print(colored('\tPASS', 'green'))

    print(colored('Testing prime array', 'cyan'))
    shapeInput = np.random.randint(20, 100, [
        2,
    ])
    shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item())
    cArray = NumCpp.NdArrayUInt32(shape)
    data = np.random.randint(0, 10000, [shape.rows, shape.cols])
    cArray.setArray(data)
    answer = NumCpp.prime_Array(cArray)
    print(colored('\tPASS', 'green'))

    print(colored('Testing riemann_zeta scaler', 'cyan'))
    value = np.random.rand(1).item() * 5 + 1
    if (roundScaler(NumCpp.riemann_zeta_Scaler(value),
                    NUM_DECIMALS_ROUND) == roundScaler(
                        sp.zeta(value, 1).item(), NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing riemann_zeta array', 'cyan'))
    shapeInput = np.random.randint(20, 100, [
        2,
    ])
    shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item())
    cArray = NumCpp.NdArray(shape)
    data = np.random.rand(shape.rows, shape.cols) * 5 + 1
    cArray.setArray(data)
    if np.array_equal(
            roundArray(NumCpp.riemann_zeta_Array(cArray), NUM_DECIMALS_ROUND),
            roundArray(sp.zeta(data, 1), NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing softmax Axis::None', 'cyan'))
    shapeInput = np.random.randint(20, 100, [
        2,
    ])
    shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item())
    cArray = NumCpp.NdArray(shape)
    data = np.random.rand(shape.rows, shape.cols)
    cArray.setArray(data)
    if np.array_equal(
            roundArray(NumCpp.softmax(cArray, NumCpp.Axis.NONE),
                       NUM_DECIMALS_ROUND),
            roundArray(sp.softmax(data), NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing spherical_bessel_jn scaler', 'cyan'))
    order = np.random.randint(0, 10)
    value = np.random.rand(1).item()
    if (roundScaler(NumCpp.spherical_bessel_jn_Scaler(order, value),
                    NUM_DECIMALS_ROUND) == roundScaler(
                        sp.spherical_jn(order, value).item(),
                        NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing spherical_bessel_jn array', 'cyan'))
    shapeInput = np.random.randint(20, 100, [
        2,
    ])
    shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item())
    cArray = NumCpp.NdArray(shape)
    order = np.random.randint(0, 10)
    data = np.random.rand(shape.rows, shape.cols)
    cArray.setArray(data)
    if np.array_equal(
            roundArray(NumCpp.spherical_bessel_jn_Array(order, cArray),
                       NUM_DECIMALS_ROUND),
            roundArray(sp.spherical_jn(order, data), NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing spherical_bessel_yn scaler', 'cyan'))
    order = np.random.randint(0, 10)
    value = np.random.rand(1).item()
    if (roundScaler(NumCpp.spherical_bessel_yn_Scaler(order, value),
                    NUM_DECIMALS_ROUND) == roundScaler(
                        sp.spherical_yn(order, value).item(),
                        NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing spherical_bessel_yn array', 'cyan'))
    shapeInput = np.random.randint(20, 100, [
        2,
    ])
    shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item())
    cArray = NumCpp.NdArray(shape)
    order = np.random.randint(0, 10)
    data = np.random.rand(shape.rows, shape.cols)
    cArray.setArray(data)
    if np.array_equal(
            roundArray(NumCpp.spherical_bessel_yn_Array(order, cArray),
                       NUM_DECIMALS_ROUND),
            roundArray(sp.spherical_yn(order, data), NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    # There is no equivalent scipy functions
    print(colored('Testing spherical_hankel_1 scaler', 'cyan'))
    order = np.random.randint(0, 10)
    value = np.random.rand(1).item()
    result = NumCpp.spherical_hankel_1(order, value)
    print(colored('\tPASS', 'green'))

    print(colored('Testing spherical_hankel_2 scaler', 'cyan'))
    order = np.random.randint(0, 10)
    value = np.random.rand(1).item()
    result = NumCpp.spherical_hankel_2(order, value)
    print(colored('\tPASS', 'green'))

    print(colored('Testing trigamma scaler', 'cyan'))
    value = np.random.rand(1).item()
    if (roundScaler(NumCpp.trigamma_Scaler(value),
                    NUM_DECIMALS_ROUND) == roundScaler(
                        sp.polygamma(1, value).item(), NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing trigamma array', 'cyan'))
    shapeInput = np.random.randint(20, 100, [
        2,
    ])
    shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item())
    cArray = NumCpp.NdArray(shape)
    data = np.random.rand(shape.rows, shape.cols)
    cArray.setArray(data)
    if np.array_equal(
            roundArray(NumCpp.trigamma_Array(cArray), NUM_DECIMALS_ROUND),
            roundArray(sp.polygamma(1, data), NUM_DECIMALS_ROUND)):
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))
Пример #7
0
def bernoulli(val):
    return special.bernoulli(val)[val]