def batched_dot(a, b):
 (a, b) = (as_tensor_variable(a), as_tensor_variable(b))
 if (a.ndim == 0):
  raise TypeError('a must have at least one (batch) axis')
 elif (b.ndim == 0):
  raise TypeError('b must have at least one (batch) axis')
 elif (a.ndim == 1):
  return (a.dimshuffle(*([0] + (['x'] * (b.ndim - 1)))) * b)
 elif (b.ndim == 1):
  return (a * b.dimshuffle(*([0] + (['x'] * (a.ndim - 1)))))
 elif ((a.ndim > 3) or (b.ndim > 3)):
  return batched_tensordot(a, b, [[(a.ndim - 1)], [numpy.maximum(1, (b.ndim - 2))]])
 else:
  return theano.tensor.blas.BatchedDot()(a, b)

def batched_dot ( a , b ) : ( a , b ) = ( as_tensor_variable ( a ) , as_tensor_variable ( b ) ) if ( a . ndim == 0 ) : raise TypeError ( 'a must have at least one (batch) axis' ) elif ( b . ndim == 0 ) : raise TypeError ( 'b must have at least one (batch) axis' ) elif ( a . ndim == 1 ) : return ( a . dimshuffle ( * ( [ 0 ] + ( [ 'x' ] * ( b . ndim - 1 ) ) ) ) * b ) elif ( b . ndim == 1 ) : return ( a * b . dimshuffle ( * ( [ 0 ] + ( [ 'x' ] * ( a . ndim - 1 ) ) ) ) ) elif ( ( a . ndim > 3 ) or ( b . ndim > 3 ) ) : return batched_tensordot ( a , b , [ [ ( a . ndim - 1 ) ] , [ numpy . maximum ( 1 , ( b . ndim - 2 ) ) ] ] ) else : return theano . tensor . blas . BatchedDot ( ) ( a , b )
compute the batched dot product of two variables: batched_dot[i] = dot note that this batched_dot function does one of three things .