Beispiel #1
0
def test_closure_unnormalizable():
    """
    Test an unnormalizable vector.

    """
    x = np.zeros(3)
    with pytest.raises(ditException):
        closure(x)
Beispiel #2
0
def test_closure_invariance():
    x = np.array([1, 2, 3, 4]) / 10
    y = x * 2
    z = x * .5
    xcl = closure(x)
    ycl = closure(y)
    zcl = closure(z)

    assert_almost_equal_array(xcl, ycl)
    assert_almost_equal_array(ycl, zcl)
    assert_almost_equal_array(zcl, xcl)
Beispiel #3
0
def test_closure_invariance():
    x = np.array([1, 2, 3, 4]) / 10
    y = x * 2
    z = x * .5
    xcl = closure(x)
    ycl = closure(y)
    zcl = closure(z)

    assert np.allclose(xcl, ycl)
    assert np.allclose(ycl, zcl)
    assert np.allclose(zcl, xcl)
Beispiel #4
0
def test_closure_invariance():
    x = np.array([1, 2, 3, 4]) / 10
    y = x*2
    z = x*.5
    xcl = closure(x)
    ycl = closure(y)
    zcl = closure(z)

    assert_almost_equal_array(xcl, ycl)
    assert_almost_equal_array(ycl, zcl)
    assert_almost_equal_array(zcl, xcl)
Beispiel #5
0
def test_basis():
    b = np.array([[1 / 1., -1, 0, 0, 0], [1 / 2., 1 / 2., -1, 0, 0],
                  [1 / 3., 1 / 3., 1 / 3., -1, 0],
                  [1 / 4., 1 / 4., 1 / 4., 1 / 4., -1]])
    b *= np.sqrt([i / (i + 1) for i in range(1, 5)])[:, np.newaxis]
    b = closure(exp2(b))
    b_ = basis(4)
    assert b.shape == b_.shape
    assert np.allclose(b, b_)
Beispiel #6
0
def test_basis():
    b = np.array([[1 / 1., -1, 0, 0, 0], [1 / 2., 1 / 2., -1, 0, 0],
                  [1 / 3., 1 / 3., 1 / 3., -1, 0],
                  [1 / 4., 1 / 4., 1 / 4., 1 / 4., -1]])
    b *= np.sqrt([i / (i + 1) for i in range(1, 5)])[:, np.newaxis]
    b = closure(exp2(b))
    b_ = basis(4)
    assert_equal_shape(b, b_)
    assert_almost_equal_array(b, b_)
Beispiel #7
0
def test_basis():
    b = np.array([[1/1.,   -1,    0,    0,  0],
                  [1/2., 1/2.,   -1,    0,  0],
                  [1/3., 1/3., 1/3.,   -1,  0],
                  [1/4., 1/4., 1/4., 1/4., -1]])
    b *= np.sqrt([i/(i+1) for i in range(1, 5)])[:, np.newaxis]
    b = closure(exp2(b))
    b_ = basis(4)
    assert_equal_shape(b, b_)
    assert_almost_equal_array(b, b_)
Beispiel #8
0
def test_closure():
    # 1D
    x = np.array([1.0, 1.0])
    y = np.array([0.5, 0.5])
    cl_x = closure(x)
    assert x.shape == cl_x.shape
    assert np.allclose(cl_x, y)

    # 2D with multiple rows
    x = np.array([[1.0, 1.0], [1.0, 2.0]])
    y = np.array([[0.5, 0.5], [1 / 3.0, 2 / 3.0]])
    cl_x = closure(x)
    assert x.shape == cl_x.shape
    assert np.allclose(cl_x, y)

    # 2D with one row
    x = np.array([[1.0, 1.0]])
    y = np.array([[0.5, 0.5]])
    cl_x = closure(x)
    assert x.shape == cl_x.shape
    assert np.allclose(cl_x, y)
Beispiel #9
0
def test_closure():
    # 1D
    x = np.array([1.0, 1.0])
    y = np.array([0.5, 0.5])
    cl_x = closure(x)
    assert_equal_shape(x, cl_x)
    assert_almost_equal_array(cl_x, y)

    # 2D with multiple rows
    x = np.array([[1.0, 1.0], [1.0, 2.0]])
    y = np.array([[0.5, 0.5], [1 / 3.0, 2 / 3.0]])
    cl_x = closure(x)
    assert_equal_shape(x, cl_x)
    assert_almost_equal_array(cl_x, y)

    # 2D with one row
    x = np.array([[1.0, 1.0]])
    y = np.array([[0.5, 0.5]])
    cl_x = closure(x)
    assert_equal_shape(x, cl_x)
    assert_almost_equal_array(cl_x, y)
Beispiel #10
0
def test_closure():
    # 1D
    x = np.array([1.0, 1.0])
    y = np.array([0.5, 0.5])
    cl_x = closure(x)
    assert_equal_shape(x, cl_x)
    assert_almost_equal_array(cl_x, y)

    # 2D with multiple rows
    x = np.array([[1.0, 1.0], [1.0, 2.0]])
    y = np.array([[0.5, 0.5], [1/3.0, 2/3.0]])
    cl_x = closure(x)
    assert_equal_shape(x, cl_x)
    assert_almost_equal_array(cl_x, y)

    # 2D with one row
    x = np.array([[1.0, 1.0]])
    y = np.array([[0.5, 0.5]])
    cl_x = closure(x)
    assert_equal_shape(x, cl_x)
    assert_almost_equal_array(cl_x, y)