@local_optimizer([gemm_no_inplace])
def local_gemm_to_ger(node):
 if (node.op == gemm_no_inplace):
  (z, a, x, y, b) = node.inputs
  if (x.broadcastable[1] and y.broadcastable[0]):
   xv = x.dimshuffle(0)
   yv = y.dimshuffle(1)
   try:
    bval = T.get_scalar_constant_value(b)
   except T.NotScalarConstantError:
    return
   if (bval == 1):
    rval = ger(z, a, xv, yv)
    return [rval]
   elif (bval == 0):
    zeros = T.zeros([x.shape[0], y.shape[1]], x.dtype)
    rval = ger(zeros, a, xv, yv)
    return [rval]
   else:
    return

@ local_optimizer ( [ gemm_no_inplace ] ) def local_gemm_to_ger ( node ) : if ( node . op == gemm_no_inplace ) : ( z , a , x , y , b ) = node . inputs if ( x . broadcastable [ 1 ] and y . broadcastable [ 0 ] ) : xv = x . dimshuffle ( 0 ) yv = y . dimshuffle ( 1 ) try : bval = T . get_scalar_constant_value ( b ) except T . NotScalarConstantError : return if ( bval == 1 ) : rval = ger ( z , a , xv , yv ) return [ rval ] elif ( bval == 0 ) : zeros = T . zeros ( [ x . shape [ 0 ] , y . shape [ 1 ] ] , x . dtype ) rval = ger ( zeros , a , xv , yv ) return [ rval ] else : return
gemm computing an outer-product -> ger .