A = np.random.rand(20, 30) b = np.random.rand(30) c = np.zeros((20)) linalg.product_matrix_vector(A, b, c) print "NumPy vs mathutils.linalg diff.:", sum(np.abs(c - np.dot(A, b))) A = np.random.rand(30, 20) b = np.random.rand(20) c = np.zeros((30)) linalg.product_matrix_vector(A, b, c) print "NumPy vs mathutils.linalg diff.:", sum(np.abs(c - np.dot(A, b))) print "Testing product_matrix_matrix" A = np.random.rand(20, 30) B = np.random.rand(30, 40) C = np.zeros((20, 40)) linalg.product_matrix_matrix(A, B, C) print "NumPy vs mathutils.linalg diff.:", np.sum(np.abs(C - np.dot(A, B))) A = np.random.rand(30, 20) B = np.random.rand(30, 40) C = np.zeros((20, 40)) linalg.product_matrix_matrix(A.T, B, C) np.dot(A.T, B) print "NumPy vs mathutils.linalg diff.:", np.sum(np.abs(C - np.dot(A.T, B))) A = np.random.rand(20, 30) B = np.random.rand(40, 30) C = np.zeros((20, 40)) linalg.product_matrix_matrix(A, B.T, C) print "NumPy vs mathutils.linalg diff.:", np.sum(np.abs(C - np.dot(A, B.T))) A = np.random.rand(30, 20) B = np.random.rand(40, 30) C = np.zeros((20, 40))
b = np.random.rand(30) c = np.zeros((20)) linalg.product_matrix_vector(A,b,c) print "NumPy vs mathutils.linalg diff.:",sum(np.abs(c - np.dot(A,b))) A = np.random.rand(30,20) b = np.random.rand(20) c = np.zeros((30)) linalg.product_matrix_vector(A,b,c) print "NumPy vs mathutils.linalg diff.:",sum(np.abs(c - np.dot(A,b))) print "Testing product_matrix_matrix" A = np.random.rand(20,30) B = np.random.rand(30,40) C = np.zeros((20,40)) linalg.product_matrix_matrix(A,B,C) print "NumPy vs mathutils.linalg diff.:",np.sum(np.abs(C - np.dot(A,B))) A = np.random.rand(30,20) B = np.random.rand(30,40) C = np.zeros((20,40)) linalg.product_matrix_matrix(A.T,B,C) np.dot(A.T,B) print "NumPy vs mathutils.linalg diff.:",np.sum(np.abs(C - np.dot(A.T,B))) A = np.random.rand(20,30) B = np.random.rand(40,30) C = np.zeros((20,40)) linalg.product_matrix_matrix(A,B.T,C) print "NumPy vs mathutils.linalg diff.:",np.sum(np.abs(C - np.dot(A,B.T))) A = np.random.rand(30,20) B = np.random.rand(40,30) C = np.zeros((20,40))
def test_product_matrix_matrix(): """ Testing product_matrix_matrix """ A = np.random.rand(20, 30) B = np.random.rand(30, 40) C = np.zeros((20, 40)) linalg.product_matrix_matrix(A, B, C) assert np.sum(np.abs(C - np.dot(A, B))) < 1e-10 A = np.random.rand(30, 20) B = np.random.rand(30, 40) C = np.zeros((20, 40)) linalg.product_matrix_matrix(A.T, B, C) np.dot(A.T, B) assert np.sum(np.abs(C - np.dot(A.T, B))) < 1e-10 A = np.random.rand(20, 30) B = np.random.rand(40, 30) C = np.zeros((20, 40)) linalg.product_matrix_matrix(A, B.T, C) assert np.sum(np.abs(C - np.dot(A, B.T))) < 1e-10 A = np.random.rand(30, 20) B = np.random.rand(40, 30) C = np.zeros((20, 40)) linalg.product_matrix_matrix(A.T, B.T, C) assert np.sum(np.abs(C - np.dot(A.T, B.T))) < 1e-10 A = np.random.rand(20, 30) B = np.random.rand(30, 40) C = np.zeros((40, 20)) linalg.product_matrix_matrix(A, B, C.T) assert np.sum(np.abs(C.T - np.dot(A, B))) < 1e-10 A = np.random.rand(30, 20) B = np.random.rand(30, 40) C = np.zeros((40, 20)) linalg.product_matrix_matrix(A.T, B, C.T) assert np.sum(np.abs(C.T - np.dot(A.T, B))) < 1e-10 A = np.random.rand(20, 30) B = np.random.rand(40, 30) C = np.zeros((40, 20)) linalg.product_matrix_matrix(A, B.T, C.T) assert np.sum(np.abs(C.T - np.dot(A, B.T))) < 1e-10 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) assert np.sum(np.abs(C.T - np.dot(A.T, B.T))) < 1e-10 # Testing with fortran order A = np.zeros((20, 30), order='fortran') A[:] = np.random.rand(20, 30) B = np.random.rand(30, 40) C = np.zeros((20, 40)) linalg.product_matrix_matrix(A, B, C) assert np.sum(np.abs(C - np.dot(A, B))) < 1e-10 A = np.zeros((30, 20), order='fortran') A[:] = np.random.rand(30, 20) B = np.random.rand(30, 40) C = np.zeros((20, 40)) linalg.product_matrix_matrix(A.T, B, C) np.dot(A.T, B) assert np.sum(np.abs(C - np.dot(A.T, B))) < 1e-10 A = np.zeros((20, 30), order='fortran') A[:] = np.random.rand(20, 30) B = np.random.rand(40, 30) C = np.zeros((20, 40)) linalg.product_matrix_matrix(A, B.T, C) assert np.sum(np.abs(C - np.dot(A, B.T))) < 1e-10 A = np.zeros((30, 20), order='fortran') A[:] = np.random.rand(30, 20) B = np.random.rand(40, 30) C = np.zeros((20, 40)) linalg.product_matrix_matrix(A.T, B.T, C) assert np.sum(np.abs(C - np.dot(A.T, B.T))) < 1e-10 A = np.zeros((20, 30), order='fortran') A[:] = np.random.rand(20, 30) B = np.random.rand(30, 40) C = np.zeros((40, 20)) linalg.product_matrix_matrix(A, B, C.T) assert np.sum(np.abs(C.T - np.dot(A, B))) < 1e-10 A = np.zeros((30, 20), order='fortran') A[:] = np.random.rand(30, 20) B = np.random.rand(30, 40) C = np.zeros((40, 20)) linalg.product_matrix_matrix(A.T, B, C.T) assert np.sum(np.abs(C.T - np.dot(A.T, B))) < 1e-10 A = np.zeros((20, 30), order='fortran') A[:] = np.random.rand(20, 30) B = np.random.rand(40, 30) C = np.zeros((40, 20)) linalg.product_matrix_matrix(A, B.T, C.T) assert np.sum(np.abs(C.T - np.dot(A, B.T))) < 1e-10 A = np.zeros((30, 20), order='fortran') 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) assert np.sum(np.abs(C.T - np.dot(A.T, B.T))) < 1e-10 A = np.random.rand(1, 30) B = np.random.rand(30, 1) C = np.zeros((1, 1)) linalg.product_matrix_matrix(A, B, C) assert np.sum(np.abs(C - np.dot(A, B))) < 1e-10
def test_product_matrix_matrix(): """ Testing product_matrix_matrix """ A = np.random.rand(20,30) B = np.random.rand(30,40) C = np.zeros((20,40)) linalg.product_matrix_matrix(A,B,C) assert np.sum(np.abs(C - np.dot(A,B))) < 1e-10 A = np.random.rand(30,20) B = np.random.rand(30,40) C = np.zeros((20,40)) linalg.product_matrix_matrix(A.T,B,C) np.dot(A.T,B) assert np.sum(np.abs(C - np.dot(A.T,B))) < 1e-10 A = np.random.rand(20,30) B = np.random.rand(40,30) C = np.zeros((20,40)) linalg.product_matrix_matrix(A,B.T,C) assert np.sum(np.abs(C - np.dot(A,B.T))) < 1e-10 A = np.random.rand(30,20) B = np.random.rand(40,30) C = np.zeros((20,40)) linalg.product_matrix_matrix(A.T,B.T,C) assert np.sum(np.abs(C - np.dot(A.T,B.T))) < 1e-10 A = np.random.rand(20,30) B = np.random.rand(30,40) C = np.zeros((40,20)) linalg.product_matrix_matrix(A,B,C.T) assert np.sum(np.abs(C.T - np.dot(A,B))) < 1e-10 A = np.random.rand(30,20) B = np.random.rand(30,40) C = np.zeros((40,20)) linalg.product_matrix_matrix(A.T,B,C.T) assert np.sum(np.abs(C.T - np.dot(A.T,B))) < 1e-10 A = np.random.rand(20,30) B = np.random.rand(40,30) C = np.zeros((40,20)) linalg.product_matrix_matrix(A,B.T,C.T) assert np.sum(np.abs(C.T - np.dot(A,B.T))) < 1e-10 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) assert np.sum(np.abs(C.T - np.dot(A.T,B.T))) < 1e-10 # Testing with fortran order A = np.zeros((20,30),order='fortran') A[:] = np.random.rand(20,30) B = np.random.rand(30,40) C = np.zeros((20,40)) linalg.product_matrix_matrix(A,B,C) assert np.sum(np.abs(C - np.dot(A,B))) < 1e-10 A = np.zeros((30,20),order='fortran') A[:] = np.random.rand(30,20) B = np.random.rand(30,40) C = np.zeros((20,40)) linalg.product_matrix_matrix(A.T,B,C) np.dot(A.T,B) assert np.sum(np.abs(C - np.dot(A.T,B))) < 1e-10 A = np.zeros((20,30),order='fortran') A[:] = np.random.rand(20,30) B = np.random.rand(40,30) C = np.zeros((20,40)) linalg.product_matrix_matrix(A,B.T,C) assert np.sum(np.abs(C - np.dot(A,B.T))) < 1e-10 A = np.zeros((30,20),order='fortran') A[:] = np.random.rand(30,20) B = np.random.rand(40,30) C = np.zeros((20,40)) linalg.product_matrix_matrix(A.T,B.T,C) assert np.sum(np.abs(C - np.dot(A.T,B.T))) < 1e-10 A = np.zeros((20,30),order='fortran') A[:] = np.random.rand(20,30) B = np.random.rand(30,40) C = np.zeros((40,20)) linalg.product_matrix_matrix(A,B,C.T) assert np.sum(np.abs(C.T - np.dot(A,B))) < 1e-10 A = np.zeros((30,20),order='fortran') A[:] = np.random.rand(30,20) B = np.random.rand(30,40) C = np.zeros((40,20)) linalg.product_matrix_matrix(A.T,B,C.T) assert np.sum(np.abs(C.T - np.dot(A.T,B))) < 1e-10 A = np.zeros((20,30),order='fortran') A[:] = np.random.rand(20,30) B = np.random.rand(40,30) C = np.zeros((40,20)) linalg.product_matrix_matrix(A,B.T,C.T) assert np.sum(np.abs(C.T - np.dot(A,B.T))) < 1e-10 A = np.zeros((30,20),order='fortran') 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) assert np.sum(np.abs(C.T - np.dot(A.T,B.T))) < 1e-10 A = np.random.rand(1,30) B = np.random.rand(30,1) C = np.zeros((1,1)) linalg.product_matrix_matrix(A,B,C) assert np.sum(np.abs(C - np.dot(A,B))) < 1e-10