code: def flip(kern, kshp):
      "flip the kernel as scipy.convolv2d do it flipped."
      flip = N.zeros(kern.shape)
      if len(kern.shape) == 2:
          kern = kern.reshape(-1)
          it = reversed(kern)
          for i in xrange(kshp[0]):
              for j in xrange(kshp[1]):
                  flip[i, j] = next(it)
      elif len(kern.shape) == 3:
          kern = kern.reshape(kern.shape[0], -1)
          for k in xrange(kern.shape[0]):
              it = reversed(kern[k, :])
              for i in xrange(kshp[0]):
                  for j in xrange(kshp[1]):
                      flip[k, i, j] = next(it)
      elif len(kern.shape) == 4:
          kern = kern.reshape(kern.shape[0], kern.shape[1], -1)
          for k in xrange(kern.shape[0]):
              for m in xrange(kern.shape[1]):
                  it = reversed(kern[k, m, :])
                  for i in xrange(kshp[0]):
                      for j in xrange(kshp[1]):
                          flip[k, m, i, j] = next(it)
      else:
          raise NotImplementedError()
      return flip
  
file_path: Theano/theano/tensor/nnet/tests/speed_test_conv.py
imports: from __future__ import absolute_import, print_function, division
  import time
  import numpy
  from six.moves import xrange
  from theano import function, Mode
  import theano.tensor
  from theano.tensor.nnet.conv import ConvOp
label_desc: Use image node_id 1 for calling a global function with example usage: flip(kern, kshp) and returns: flip