Ejemplo n.º 1
0
def test_striu():
    # Shears encoded as vector from triangle above diagonal of shear mat
    S = [0.1, 0.2, 0.3]
    assert_array_equal(tss.striu2mat(S),
                       [[ 1. ,  0.1,  0.2],
                        [ 0. ,  1. ,  0.3],
                        [ 0. ,  0. ,  1. ]])
    assert_array_equal(tss.striu2mat([1]),
                       [[ 1.,  1.],
                        [ 0.,  1.]])
    for n, N in ((1, 2),
                 (3, 3),
                 (6, 4),
                 (10, 5),
                 (15, 6),
                 (21, 7),
                 (78, 13)):
        shears = np.arange(n)
        M = tss.striu2mat(shears)
        e = np.eye(N)
        inds = np.triu(np.ones((N,N)), 1).astype(bool)
        e[inds] = shears
        assert_array_equal(M, e)
    for n in (2, 4, 5, 7, 8, 9):
        shears = np.zeros(n)
        assert_raises(ValueError, tss.striu2mat, shears)
Ejemplo n.º 2
0
def test_fillpos():
    # Takes np array
    xyz = np.zeros((3, ))
    w, x, y, z = tq.fillpositive(xyz)
    assert w == 1
    # Or lists
    xyz = [0] * 3
    w, x, y, z = tq.fillpositive(xyz)
    assert w == 1
    # Errors with wrong number of values
    assert_raises(ValueError, tq.fillpositive, [0, 0])
    assert_raises(ValueError, tq.fillpositive, [0] * 4)
    # Errors with negative w2
    assert_raises(ValueError, tq.fillpositive, [1.0] * 3)
    # Test corner case where w is near zero
    wxyz = tq.fillpositive([1, 0, 0])
    assert wxyz[0] == 0.0
    eps = np.finfo(float).eps
    wxyz = tq.fillpositive([1 + eps, 0, 0])
    assert wxyz[0] == 0.0
    # Bump up the floating point error - raises error
    assert_raises(ValueError, tq.fillpositive, [1 + eps * 3, 0, 0])
    # Increase threshold, happy again
    wxyz = tq.fillpositive([1 + eps * 3, 0, 0], w2_thresh=eps * -10)
    assert wxyz[0] == 0.0
Ejemplo n.º 3
0
def test_fillpos():
    # Takes np array
    xyz = np.zeros((3,))
    w,x,y,z = tq.fillpositive(xyz)
    assert w == 1
    # Or lists
    xyz = [0] * 3
    w,x,y,z = tq.fillpositive(xyz)
    assert w == 1
    # Errors with wrong number of values
    assert_raises(ValueError, tq.fillpositive, [0, 0])
    assert_raises(ValueError, tq.fillpositive, [0]*4)
    # Errors with negative w2
    assert_raises(ValueError, tq.fillpositive, [1.0]*3)
    # Test corner case where w is near zero
    wxyz = tq.fillpositive([1, 0, 0])
    assert wxyz[0] == 0.0
    eps = np.finfo(float).eps
    wxyz = tq.fillpositive([1 + eps, 0, 0])
    assert wxyz[0] == 0.0
    # Bump up the floating point error - raises error
    assert_raises(ValueError, tq.fillpositive, [1 + eps * 3, 0, 0])
    # Increase threshold, happy again
    wxyz = tq.fillpositive([1 + eps * 3, 0, 0], w2_thresh=eps * -10)
    assert wxyz[0] == 0.0
Ejemplo n.º 4
0
def test_mat2axangle_thresh():
    # Test precision threshold to mat2axangle
    axis, angle = mat2axangle(np.eye(3))
    assert_almost_equal(axis, [0, 0, 1])
    assert_almost_equal(angle, 0)
    offset = 1e-6
    mat = np.diag([1 + offset] * 3)
    axis, angle = mat2axangle(mat)
    assert_almost_equal(axis, [0, 0, 1])
    assert_almost_equal(angle, 0)
    offset = 1e-4
    mat = np.diag([1 + offset] * 3)
    assert_raises(ValueError, mat2axangle, mat)
    axis, angle = mat2axangle(mat, 1e-4)
    assert_almost_equal(axis, [0, 0, 1])
    assert_almost_equal(angle, 0)
Ejemplo n.º 5
0
def test_no_reflection():
    assert_raises(ValueError, mat2rfnorm, np.eye(3))
    assert_raises(ValueError, aff2rfnorm, np.eye(4))
    # Rotations are not reflections
    for mat in euler_mats:
        assert_raises(ValueError, mat2rfnorm, mat)
        aff = np.eye(4)
        aff[:3, :3] = mat
        assert_raises(ValueError, aff2rfnorm, aff)
Ejemplo n.º 6
0
def test_errors():
    M = np.ones((3, 3))
    assert_raises(ValueError, mat2axangle, M)
    A = np.eye(4)
    A[:3, :3] = M
    assert_raises(ValueError, aff2axangle, A)
Ejemplo n.º 7
0
def test_compose():
    # Test that rotation vector raises error
    T = np.ones(3)
    R = np.ones(3)
    Z = np.ones(3)
    assert_raises(ValueError, compose, T, R, Z)