def test_product_matrix_vector(): """ Test product_matrix_vector agains Numpy. """ A = np.random.rand(30, 20) b = np.random.rand(10) c = np.zeros((40)) linalg.product_matrix_vector(A[:10, :].T, b, c[10:30]) assert sum(np.abs(c[10:30] - np.dot(A[:10, :].T, b))) < 1e-10 A = np.random.rand(20, 30) b = np.random.rand(30) c = np.zeros((20)) linalg.product_matrix_vector(A, b, c) assert sum(np.abs(c - np.dot(A, b))) < 1e-10 A = np.random.rand(30, 20) b = np.random.rand(20) c = np.zeros((30)) linalg.product_matrix_vector(A, b, c) assert sum(np.abs(c - np.dot(A, b))) < 1e-10
def test_product_matrix_vector(): """ Test product_matrix_vector agains Numpy. """ A = np.random.rand(30,20) b = np.random.rand(10) c = np.zeros((40)) linalg.product_matrix_vector(A[:10,:].T,b,c[10:30]) assert sum(np.abs(c[10:30] - np.dot(A[:10,:].T,b))) < 1e-10 A = np.random.rand(20,30) b = np.random.rand(30) c = np.zeros((20)) linalg.product_matrix_vector(A,b,c) assert sum(np.abs(c - np.dot(A,b))) < 1e-10 A = np.random.rand(30,20) b = np.random.rand(20) c = np.zeros((30)) linalg.product_matrix_vector(A,b,c) assert sum(np.abs(c - np.dot(A,b))) < 1e-10
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # The views and conclusions contained in the software and documentation are those of the # authors and should not be interpreted as representing official policies, either expressed # or implied, of Hugo Larochelle. import numpy as np import scipy.linalg import mlpython.mathutils.linalg as linalg import mlpython.mathutils.nonlinear as nonlinear print "Testing product_matrix_vector" A = np.random.rand(30, 20) b = np.random.rand(10) c = np.zeros((40)) linalg.product_matrix_vector(A[:10, :].T, b, c[10:30]) print "NumPy vs mathutils.linalg diff.:", sum( np.abs(c[10:30] - np.dot(A[:10, :].T, b))) 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)
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # The views and conclusions contained in the software and documentation are those of the # authors and should not be interpreted as representing official policies, either expressed # or implied, of Hugo Larochelle. import numpy as np import scipy.linalg import mlpython.mathutils.linalg as linalg import mlpython.mathutils.nonlinear as nonlinear print "Testing product_matrix_vector" A = np.random.rand(30,20) b = np.random.rand(10) c = np.zeros((40)) linalg.product_matrix_vector(A[:10,:].T,b,c[10:30]) print "NumPy vs mathutils.linalg diff.:",sum(np.abs(c[10:30] - np.dot(A[:10,:].T,b))) 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)