def test_setdiag(): """ Testing setdiag. """ A = np.random.rand(30, 20) x = np.random.rand(20) linalg.setdiag(A, x) assert np.sum(np.abs(x - np.diag(A))) < 1e-10 A = np.random.rand(30, 20).T x = np.random.rand(20) linalg.setdiag(A, x) assert np.sum(np.abs(x - np.diag(A))) < 1e-10
def test_setdiag(): """ Testing setdiag. """ A = np.random.rand(30,20) x = np.random.rand(20) linalg.setdiag(A,x) assert np.sum(np.abs(x-np.diag(A))) < 1e-10 A = np.random.rand(30,20).T x = np.random.rand(20) linalg.setdiag(A,x) assert np.sum(np.abs(x-np.diag(A))) < 1e-10
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))) print "Testing multiple_row_accumulate" X = np.random.rand(30, 20) Y = np.zeros((10, 20)) rows = np.hstack([ np.arange(10, dtype='i'), np.arange(10, dtype='i'), np.arange(10, dtype='i'), np.arange(10, dtype='i'), np.arange(10, dtype='i')
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))) print "Testing multiple_row_accumulate" X = np.random.rand(30,20) Y = np.zeros((10,20)) rows = np.hstack([np.arange(10,dtype='i'),np.arange(10,dtype='i'),np.arange(10,dtype='i'),np.arange(10,dtype='i'),np.arange(10,dtype='i')]) np.random.shuffle(rows) rows = rows[:30] linalg.multiple_row_accumulate(X,rows,Y) Y2 = np.zeros((10,20)) for i,r in enumerate(rows):