Example #1
0
def dot_tensor_tensor():
  A = numeric.arange(1,7).reshape(2,1,3)
  B = numeric.arange(7,13).reshape(3,1,2)
  AB = numeric.dot(A,B)
  assert AB.ndim == 4, 'A,B ndim'
  assert AB.dtype == int, 'A,B dtype'
  assert numpy.equal( AB, [[[[58,64]]],[[[139,154]]]] ).all(), 'A,B data'
  BA = numeric.dot(B,A)
  assert BA.ndim == 4, 'B,A ndim'
  assert BA.dtype == int, 'B,A dtype'
  assert numpy.equal( BA, [[[[39,54,69]]],[[[49,68,87]]],[[[59,82,105]]]] ).all(), 'B,A data'
Example #2
0
def dot_matrix_vector():
  A = numeric.arange(1,5).reshape(2,2)
  B = numeric.arange(5,7)
  AB = numeric.dot(A,B)
  assert AB.ndim == 1, 'A,B ndim'
  assert AB.dtype == int, 'A,B dtype'
  assert numpy.equal( AB, [17,39] ).all(), 'A,B data'
  BA = numeric.dot(B,A)
  assert BA.ndim == 1, 'B,A ndim'
  assert BA.dtype == int, 'B,A dtype'
  assert numpy.equal( BA, [23,34] ).all(), 'B,A data'
Example #3
0
def dot_matrix_matrix():
  A = numeric.arange(1,5).reshape(2,2)
  B = numeric.arange(5,9).reshape(2,2)
  AB = numeric.dot(A,B)
  assert AB.ndim == 2, 'A,B ndim'
  assert AB.dtype == int, 'A,B dtype'
  assert numpy.equal( AB, [[19,22],[43,50]] ).all(), 'A,B data'
  ATB = numeric.dot(A.T,B)
  assert ATB.ndim == 2, 'A.T,B ndim'
  assert ATB.dtype == int, 'A.T,B dtype'
  assert numpy.equal( ATB, [[26,30],[38,44]] ).all(), 'A.T,B data'
  ABT = numeric.dot(A,B.T)
  assert ABT.ndim == 2, 'A,B.T ndim'
  assert ABT.dtype == int, 'A,B.T dtype'
  assert numpy.equal( ABT, [[17,23],[39,53]] ).all(), 'A,B.T data'