示例#1
0
def test_getdiag():
    """
    Testing getdiag.
    """

    A = np.random.rand(30, 20)
    x = np.zeros((20))
    linalg.getdiag(A, x)
    assert np.sum(np.abs(x - np.diag(A))) < 1e-10
    A = np.random.rand(30, 20).T
    x = np.zeros((20))
    linalg.getdiag(A, x)
    assert np.sum(np.abs(x - np.diag(A))) < 1e-10
示例#2
0
def test_getdiag():
    """
    Testing getdiag.
    """

    A = np.random.rand(30,20)
    x = np.zeros((20))
    linalg.getdiag(A,x)
    assert np.sum(np.abs(x-np.diag(A))) < 1e-10
    A = np.random.rand(30,20).T
    x = np.zeros((20))
    linalg.getdiag(A,x)
    assert np.sum(np.abs(x-np.diag(A))) < 1e-10
示例#3
0
B = np.random.rand(40, 30)
C = np.zeros((40, 20))
linalg.product_matrix_matrix(A.T, B.T, C.T)
print "NumPy vs mathutils.linalg diff.:", np.sum(np.abs(C.T -
                                                        np.dot(A.T, B.T)))

A = np.random.rand(1, 30)
B = np.random.rand(30, 1)
C = np.zeros((1, 1))
linalg.product_matrix_matrix(A, B, C)
print "NumPy vs mathutils.linalg diff.:", np.sum(np.abs(C - np.dot(A, B)))

print "Testing getdiag"
A = np.random.rand(30, 20)
x = np.zeros((20))
linalg.getdiag(A, x)
print "NumPy vs mathutils.linalg diff.:", np.sum(np.abs(x - np.diag(A)))
A = np.random.rand(30, 20).T
x = np.zeros((20))
linalg.getdiag(A, x)
print "NumPy vs mathutils.linalg diff.:", np.sum(np.abs(x - np.diag(A)))

print "Testing setdiag"
A = np.random.rand(30, 20)
x = np.random.rand(20)
linalg.setdiag(A, x)
print "NumPy vs mathutils.linalg diff.:", np.sum(np.abs(x - np.diag(A)))
A = np.random.rand(30, 20).T
x = np.random.rand(20)
linalg.setdiag(A, x)
print "NumPy vs mathutils.linalg diff.:", np.sum(np.abs(x - np.diag(A)))
示例#4
0
A[:] = np.random.rand(30,20)
B = np.random.rand(40,30)
C = np.zeros((40,20))
linalg.product_matrix_matrix(A.T,B.T,C.T)
print "NumPy vs mathutils.linalg diff.:",np.sum(np.abs(C.T - np.dot(A.T,B.T)))

A = np.random.rand(1,30)
B = np.random.rand(30,1)
C = np.zeros((1,1))
linalg.product_matrix_matrix(A,B,C)
print "NumPy vs mathutils.linalg diff.:",np.sum(np.abs(C - np.dot(A,B)))

print "Testing getdiag"
A = np.random.rand(30,20)
x = np.zeros((20))
linalg.getdiag(A,x)
print "NumPy vs mathutils.linalg diff.:",np.sum(np.abs(x-np.diag(A)))
A = np.random.rand(30,20).T
x = np.zeros((20))
linalg.getdiag(A,x)
print "NumPy vs mathutils.linalg diff.:",np.sum(np.abs(x-np.diag(A)))

print "Testing setdiag"
A = np.random.rand(30,20)
x = np.random.rand(20)
linalg.setdiag(A,x)
print "NumPy vs mathutils.linalg diff.:",np.sum(np.abs(x-np.diag(A)))
A = np.random.rand(30,20).T
x = np.random.rand(20)
linalg.setdiag(A,x)
print "NumPy vs mathutils.linalg diff.:",np.sum(np.abs(x-np.diag(A)))