code: def test_conv3d(border_mode):
      if ndimage is None or not theano.config.cxx:
          raise SkipTest("conv3d2d tests need SciPy and a c++ compiler")
  
      if theano.config.mode == "FAST_COMPILE":
          mode = theano.compile.mode.get_mode("FAST_RUN")
      else:
          mode = theano.compile.mode.get_default_mode()
  
      shared = theano.tensor._shared
  
      Ns, Ts, C, Hs, Ws = 3, 10, 3, 32, 32
      Nf, Tf, C, Hf, Wf = 32, 5, 3, 5, 5
  
      signals = (
          np.arange(Ns * Ts * C * Hs * Ws)
          .reshape(Ns, Ts, C, Hs, Ws)
          .astype("float32")
      )
      filters = (
          np.arange(Nf * Tf * C * Hf * Wf)
          .reshape(Nf, Tf, C, Hf, Wf)
          .astype("float32")
      )
  
      t0 = time.time()
      pyres = pyconv3d(signals, filters, border_mode)
      print(time.time() - t0)
  
      s_signals = shared(signals)
      s_filters = shared(filters)
      s_output = shared(signals * 0)
  
      out = conv3d(
          s_signals,
          s_filters,
          signals_shape=signals.shape,
          filters_shape=filters.shape,
          border_mode=border_mode,
      )
  
      newconv3d = theano.function(
          [], [], updates={s_output: out}, mode=mode
      )
  
      check_diagonal_subtensor_view_traces(newconv3d)
      t0 = time.time()
      newconv3d()
      print(time.time() - t0)
      utt.assert_allclose(pyres, s_output.get_value(borrow=True))
      gsignals, gfilters = theano.grad(
          out.sum(), [s_signals, s_filters]
      )
      gnewconv3d = theano.function(
          [],
          [],
          updates=[(s_filters, gfilters), (s_signals, gsignals)],
          mode=mode,
          name="grad",
      )
      check_diagonal_subtensor_view_traces(gnewconv3d)
  
      t0 = time.time()
      gnewconv3d()
      print("grad", time.time() - t0)
  
      Ns, Ts, C, Hs, Ws = 3, 3, 3, 5, 5
      Nf, Tf, C, Hf, Wf = 4, 2, 3, 2, 2
  
      signals = np.random.rand(Ns, Ts, C, Hs, Ws).astype("float32")
      filters = np.random.rand(Nf, Tf, C, Hf, Wf).astype("float32")
      utt.verify_grad(
          lambda s, f: conv3d(s, f, border_mode=border_mode),
          [signals, filters],
          eps=1e-1,
          mode=mode,
      )
  
      # Additional Test that covers the case of patched implementation for filter with Tf=1
      Ns, Ts, C, Hs, Ws = 3, 10, 3, 32, 32
      Nf, Tf, C, Hf, Wf = 32, 1, 3, 5, 5
  
      signals = (
          np.arange(Ns * Ts * C * Hs * Ws)
          .reshape(Ns, Ts, C, Hs, Ws)
          .astype("float32")
      )
      filters = (
          np.arange(Nf * Tf * C * Hf * Wf)
          .reshape(Nf, Tf, C, Hf, Wf)
          .astype("float32")
      )
  
      t0 = time.time()
      pyres = pyconv3d(signals, filters, border_mode)
      print(time.time() - t0)
  
      s_signals = shared(signals)
      s_filters = shared(filters)
      s_output = shared(signals * 0)
  
      out = conv3d(
          s_signals,
          s_filters,
          signals_shape=signals.shape,
          filters_shape=filters.shape,
          border_mode=border_mode,
      )
  
      newconv3d = theano.function(
          [], [], updates={s_output: out}, mode=mode
      )
  
      t0 = time.time()
      newconv3d()
      print(time.time() - t0)
      utt.assert_allclose(pyres, s_output.get_value(borrow=True))
      gsignals, gfilters = theano.grad(
          out.sum(), [s_signals, s_filters]
      )
      gnewconv3d = theano.function(
          [],
          [],
          updates=[(s_filters, gfilters), (s_signals, gsignals)],
          mode=mode,
          name="grad",
      )
  
      t0 = time.time()
      gnewconv3d()
      print("grad", time.time() - t0)
  
      Ns, Ts, C, Hs, Ws = 3, 3, 3, 5, 5
      Nf, Tf, C, Hf, Wf = 4, 1, 3, 2, 2
  
      signals = np.random.rand(Ns, Ts, C, Hs, Ws).astype("float32")
      filters = np.random.rand(Nf, Tf, C, Hf, Wf).astype("float32")
      utt.verify_grad(
          lambda s, f: conv3d(s, f, border_mode=border_mode),
          [signals, filters],
          eps=1e-1,
          mode=mode,
      )
  
file_path: Theano/theano/tensor/nnet/tests/test_conv3d2d.py
imports: from __future__ import absolute_import, print_function, division
  import time
  from nose.plugins.skip import SkipTest
  from parameterized import parameterized
  import numpy
  from six.moves import xrange
  import theano
  from theano.gof.opt import check_stack_trace
  from theano.tensor.nnet.conv3d2d import conv3d, get_diagonal_subtensor_view, DiagonalSubtensor, IncDiagonalSubtensor
  import theano.tests.unittest_tools
label_desc: Use image node_id 4 for calling a global function with example usage: test_conv3d(border_mode) without return types