code: def exec_multilayer_conv_nnet_old(
      conv_mode,
      ss,
      bsize,
      imshp,
      kshps,
      nkerns,
      unroll_batch=0,
      unroll_kern=0,
      img=T.dmatrix(),
      validate=True,
      conv_op_py=False,
      do_print=True,
      repeat=1,
      unroll_patch=False,
      unroll_patch_size=False,
      verbose=0,
  ):
      # build actual input images
      imgval = global_rng.rand(bsize, imshp[0], imshp[1], imshp[2])
  
      a = T.dmatrix()
      kerns = [a for i in nkerns]
      inputs4 = dmatrix4()
      kerns4 = dmatrix4()
  
      # for each layer
      ntot = 0
      tctot = 0
      tpytot = 0
  
      for kshp, kern, nkern, n_layer in zip(
          kshps, kerns, nkerns, xrange(len(nkerns))
      ):
          if do_print:
              print("************* layer %i ***************" % n_layer)
              print(conv_mode, ss, n_layer, kshp, nkern)
  
          # actual values
          w = global_rng.random_sample(N.r_[nkern, imshp[0], kshp])
          w_flip = flip(w, kshp).reshape(w.shape)
  
          # manual implementation
          # check first stage
          padimg = imgval
          if conv_mode == "full":
              padimg_shp = N.array(imshp[1:]) + 2 * (
                  N.array(kshp) - N.array([1, 1])
              )
              padimg = N.zeros(N.r_[bsize, imshp[0], padimg_shp])
              padimg[
                  :,
                  :,
                  kshp[0] - 1 : -kshp[0] + 1,
                  kshp[1] - 1 : -kshp[1] + 1,
              ] = imgval
  
          outshp = N.hstack(
              (
                  nkern,
                  ConvOp.getOutputShape(imshp[1:], kshp, ss, conv_mode),
              )
          )
  
          time1 = time.time()
          outval = N.zeros(N.r_[bsize, outshp])
          if validate:
              # causes an atexit problem
              from scipy.signal.sigtools import _convolve2d
              from scipy.signal.signaltools import (
                  _valfrommode,
                  _bvalfromboundary,
              )
  
              val = _valfrommode(conv_mode)
              bval = _bvalfromboundary("fill")
              for b in xrange(bsize):  # loop over batches
                  for n in xrange(nkern):  # loop over filters
                      for i in xrange(
                          imshp[0]
                      ):  # loop over input feature maps
                          outval[b, n, ...] += _convolve2d(
                              imgval[b, i, ...],
                              w_flip[n, i, ...],
                              1,
                              val,
                              bval,
                              0,
                          )[0 :: ss[0], 0 :: ss[1]]
              ntot += time.time() - time1
  
          # ConvOp
          if unroll_patch and not unroll_patch_size:
              conv_op = ConvOp(
                  dx=ss[0],
                  dy=ss[1],
                  output_mode=conv_mode,
                  unroll_patch=unroll_patch,
                  verbose=verbose,
              )(inputs4, kerns4)
          else:
              conv_op = ConvOp(
                  imshp,
                  kshp,
                  nkern,
                  bsize,
                  ss[0],
                  ss[1],
                  conv_mode,
                  unroll_batch=unroll_batch,
                  unroll_kern=unroll_kern,
                  unroll_patch=unroll_patch,
                  verbose=verbose,
              )(inputs4, kerns4)
          # l1shp = N.hstack((nkern,
          #                ConvOp.getOutputShape(imshp[1:], kshp, ss, conv_mode)))
          propup2 = function([inputs4, kerns4], conv_op)
          propup3 = function(
              [inputs4, kerns4], conv_op, mode=Mode(linker="py")
          )
  
          time1 = time.time()
          for i in xrange(repeat):
              hidval2_ = propup2(imgval, w_flip)
          hidval2 = hidval2_  # [:,:,0::ss[0],0::ss[1]]
          tctot += time.time() - time1
  
          if conv_op_py:
              time1 = time.time()
              for i in xrange(repeat):
                  hidval3_ = propup3(imgval, w_flip)
              hidval3 = hidval3_  # [:,:,0::ss[0],0::ss[1]]
              tpytot += time.time() - time1
              assert (N.abs(hidval2 - hidval3) < 1e-5).all()
          else:
              tpytot += 0
  
          if validate:
              temp = N.abs(outval - hidval2)
              assert (temp < 1e-5).all()
          if validate and conv_op_py:
              temp = N.abs(outval - hidval3)
              assert (temp < 1e-5).all()
  
          imshp = tuple(outshp)
          imgval = outval.reshape(
              bsize, outshp[0], outshp[1], outshp[2]
          )
  
      return tctot, tpytot, ntot
  
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 2 for calling a global function with example usage: exec_multilayer_conv_nnet_old(conv_mode, ss, bsize, imshp, kshps, nkerns, unroll_batch, unroll_kern, img, validate, conv_op_py, do_print, repeat, unroll_patch, unroll_patch_size, verbose) and returns: tctot,  tpytot,  ntot