Exemplo n.º 1
0
def test_memoizer():

    po = Powerlaw()

    a = np.random.uniform(-3, -1, 2000)
    b = np.random.uniform(0.1, 10, 2000)

    for aa, bb in zip(a, b):

        po.index = aa
        po.K = bb

        po(1.0)
Exemplo n.º 2
0
def test_duplicate():

    instance = Powerlaw()
    instance.index = -2.25
    instance.K = 0.5

    # Duplicate it

    duplicate = instance.duplicate()

    # Check that we have the same results

    assert duplicate(2.25) == instance(2.25)

    # Check that the parameters are not linked anymore
    instance.index = -1.12

    assert instance.index.value != duplicate.index.value

    print(instance)
    print(duplicate)
Exemplo n.º 3
0
def test_pickling_unpickling():

    # 1d function
    po = Powerlaw()

    po.K = 5.35

    new_po = pickle.loads(pickle.dumps(po))

    assert new_po.K.value == po.K.value

    # 2d function
    gs = Gaussian_on_sphere()

    _ = pickle.loads(pickle.dumps(gs))

    # 3d function
    c = Continuous_injection_diffusion()

    _ = pickle.loads(pickle.dumps(c))

    # composite function
    po2 = Powerlaw()
    li = Line()
    composite = po2 * li + po2 - li + 2 * po2 / li  # type: Function1D

    # Change some parameter
    composite.K_1 = 3.2
    composite.a_2 = 1.56

    dump = pickle.dumps(composite)

    new_composite = pickle.loads(dump)

    assert new_composite.K_1.value == composite.K_1.value
    assert new_composite.a_2.value == composite.a_2.value