예제 #1
0
def test_matrix_vector_multiplication():
    result = []
    for i in range(rownum):
        result.append(Vector(A[i]).dot(x))

    y = Vector(result)
    assert A * x == y
    assert x * A == y

    # multiply column by column
    result = Vector.zero(size=rownum)
    AT = tuple(A.transpose().vectorize_rows())
    for i in range(rownum):
        result = result + AT[i] * x.components[i]

    assert result == A * x

    # multiply column by column (using axpy)
    result = Vector.zero(size=rownum)
    AT = tuple(A.transpose().vectorize_rows())
    for i in range(rownum):
        result = axpy(AT[i], x.components[i], result)

    assert result == A * x
예제 #2
0
def test_zero_creation():
    assert Vector.zero(2) == Vector(0, 0)
    assert Vector.zero(5) == Vector(0, 0, 0, 0, 0)
예제 #3
0
def test_vector_splitting_to_basis_products():
    product_vector = Vector.zero(len(a))
    for i, component in enumerate(a):
        product_vector += Vector.basis(i, len(a)) * component

    assert product_vector == a
예제 #4
0
 def zero(cls, m: int, n: int) -> 'Matrix':
     """
     Returns the zero matrix of given dimensions
     """
     return cls(rows=(Vector.zero(n) for _ in range(m)))