Ejemplo n.º 1
0
def test_matrix_get_item():
    m = f.matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
    assert m[:] == m
    assert m[:, :] == m
    assert m[2, 1] == 8.0
    assert m[1] == f.row_vector([4, 5, 6])
    assert m[:, -1] == f.vector([3, 6, 9])
    assert m[:, 1] == f.vector([2, 5, 8])
    assert m[:-1, :-1] == f.matrix([[1, 2], [4, 5]])
    assert m[::2, ::2] == f.matrix([[1, 3], [7, 9]])
    assert m[::-1, 1] == f.vector([8, 5, 2])
Ejemplo n.º 2
0
def test_matrix_constructor():
    assert f.matrix([[]]).shape == (1, 0)
    assert f.matrix([[1, 2]]).shape == (1, 2)
    assert f.matrix([[1], [2]]).shape == (2, 1)
    assert f.matrix([[1, 2, 3], [4, 5, 6]]).shape == (2, 3)
    assert f.vector([1, 2, 3]).shape == (3, 1)
    assert f.row_vector([1, 2, 3]).shape == (1, 3)
Ejemplo n.º 3
0
def test_gauss2():
    a = f.matrix([[1, 2, 2, 2], [2, 4, 6, 8], [3, 6, 8, 10]])
    # echelon = elimination.echelon(a)

    # print(f"rref=\n{echelon.rref()}")

    # print(f"rowspace=\n{echelon.rowspace()}")
    # print(f"colspace=\n{echelon.colspace()}")
    # print(f"nullspace=\n{echelon.nullspace()}")
    # print(f"left nullspace=\n{echelon.left_nullspace()}")

    # print(f"x_particular=\n{echelon.solve(f.vector([1, 4, 50]))}")

    b = f.vector([1, 5, 6])
    cnt, x_particular, nullspace = elimination.solve(a, b)
    print(cnt)
    print(x_particular)
    print(nullspace)
    # print(elimination.solve(a, b).count())
    print(elimination.cr_decompose(a))
Ejemplo n.º 4
0
def test_stack():
    v1 = f.vector([1, 2, 3])
    v2 = f.vector([4, 5, 6])

    assert f.hstack(v1, v2) == f.matrix([[1, 2, 3], [4, 5, 6]])
    assert f.vstack(v1, v2) == f.matrix([[1, 2, 3], [4, 5, 6]]).T
Ejemplo n.º 5
0
def test_trunc():
    assert math.trunc(f.vector([-1.3, 2.8, 3])) == f.vector([-1, 2, 3])
Ejemplo n.º 6
0
def test_round():
    assert round(f.vector([-1.3, 2.8, 3])) == f.vector([-1, 3, 3])
Ejemplo n.º 7
0
def test_ceil():
    assert math.ceil(f.vector([-1.3, 2.8, 3])) == f.vector([-1, 3, 3])
Ejemplo n.º 8
0
def test_floor():
    assert math.floor(f.vector([-1.3, 2.8, 3])) == f.vector([-2, 2, 3])
Ejemplo n.º 9
0
def test_pow():
    assert f.vector([-1, 2, -3])**3 == f.vector([-1, 8, -27])
Ejemplo n.º 10
0
def test_neg():
    assert -f.vector([-1, 2]) == f.vector([1, -2])
Ejemplo n.º 11
0
def test_abs():
    assert abs(f.vector([-1, 2])) == f.vector([1, 2])