code: def test_convolution(self):
      #        print '\n\n*************************************************'
      #        print '           TEST CONVOLUTION'
      #        print '*************************************************'
  
      # fixed parameters
      bsize = 10  # batch size
      imshp = (28, 28)
      kshp = (5, 5)
      nkern = 5
      ssizes = ((1, 1), (2, 2), (3, 3), (4, 4))
      convmodes = ("full", "valid")
  
      # symbolic stuff
      bias = tensor.dvector()
      kerns = tensor.dmatrix()
      input = tensor.dmatrix()
      rng = np.random.RandomState(3423489)
      filters = rng.randn(nkern, np.prod(kshp))
      biasvals = rng.randn(nkern)
  
      for mode in ("FAST_COMPILE", "FAST_RUN"):
          ttot, ntot = 0, 0
          for conv_mode in convmodes:
              for ss in ssizes:
                  output, outshp = sp.convolve(
                      kerns,
                      kshp,
                      nkern,
                      input,
                      imshp,
                      ss,
                      bias=bias,
                      mode=conv_mode,
                  )
                  f = function([kerns, bias, input], output, mode=mode)
  
                  # now test with real values
                  img2d = np.arange(bsize * np.prod(imshp)).reshape(
                      (bsize,) + imshp
                  )
                  img1d = img2d.reshape(bsize, -1)
  
                  # create filters (need to be flipped to use convolve2d)
                  filtersflipped = np.zeros((nkern,) + kshp)
                  for k in range(nkern):
                      it = reversed(filters[k, :])
                      for i in range(kshp[0]):
                          for j in range(kshp[1]):
                              filtersflipped[k, i, j] = next(it)
  
                  # compute output with convolve2d
                  if conv_mode == "valid":
                      fulloutshp = np.array(imshp) - np.array(kshp) + 1
                  else:
                      fulloutshp = np.array(imshp) + np.array(kshp) - 1
                  ntime1 = time.time()
                  refout = np.zeros(
                      (bsize,) + tuple(fulloutshp) + (nkern,)
                  )
                  for b in range(bsize):
                      for n in range(nkern):
                          refout[b, ..., n] = convolve2d(
                              img2d[b, :, :],
                              filtersflipped[n, ...],
                              conv_mode,
                          )
                  ntot += time.time() - ntime1
  
                  # need to flatten images
                  bench1 = refout[:, 0 :: ss[0], 0 :: ss[1], :].reshape(
                      bsize, -1, nkern
                  )
                  bench1 += biasvals.reshape(1, 1, nkern)
  
                  # swap the last two dimensions (output needs to be nkern x outshp)
                  bench1 = np.swapaxes(bench1, 1, 2)
                  ttime1 = time.time()
                  out1 = f(filters, biasvals, img1d)
                  ttot += time.time() - ttime1
                  temp = bench1.flatten() - out1.flatten()
  
                  assert (temp < 1e-5).all()
  
imports: from __future__ import absolute_import, print_function, division
  from nose.plugins.skip import SkipTest
  import sys
  import time
  import unittest
  import theano.sparse
  import scipy.sparse
  from scipy.signal import convolve2d
  import scipy.sparse
  import numpy
  from six.moves import xrange
  from theano import function, tensor
  import theano
  from theano.compat import next
  from theano.sparse.sandbox import sp
  from theano.sparse.tests.test_basic import random_lil
  from theano.tests import unittest_tools
  from theano.sparse.tests.test_basic import sparse_random_inputs
  from theano.tests.unittest_tools import attr
label_desc: Use image node_id 1 for calling the TestSP obj's underlying member method code with example usage: obj.test_convolution() without return types