예제 #1
0
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
예제 #2
0
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
예제 #3
0
# 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)
예제 #4
0
파일: mathutils.py 프로젝트: MultiPath/TMBP
# 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)