code: def test_batch_normalization_test():
      for axes in ("per-activation", "spatial", (1, 2, 3, 4)):
          for vartype in (T.tensor5, T.tensor3, T.vector):
              x, scale, bias, mean, var = (
                  vartype(n)
                  for n in ("x", "scale", "bias", "mean", "var")
              )
              ndim = x.ndim
              eps = 5e-3  # some non-standard value to test if it's used
  
              # remove non-existing axes
              if isinstance(axes, tuple):
                  axes = tuple(i for i in axes if i < ndim)
              if len(axes) == 0:
                  continue
  
              # forward pass
              out = bn.batch_normalization_test(
                  x, scale, bias, mean, var, axes, eps
              )
              # reference forward pass
              if axes == "per-activation":
                  axes2 = (0,)
              elif axes == "spatial":
                  axes2 = (0,) + tuple(range(2, ndim))
              else:
                  axes2 = axes
              scale2, bias2, mean2, var2 = (
                  T.addbroadcast(t, *axes2)
                  for t in (scale, bias, mean, var)
              )
              out2 = (x - mean2) * (scale2 / T.sqrt(var2 + eps)) + bias2
              # backward pass
              dy = vartype("dy")
              grads = T.grad(
                  None,
                  wrt=[x, scale, bias, mean, var],
                  known_grads={out: dy},
              )
              # reference backward pass
              grads2 = T.grad(
                  None,
                  wrt=[x, scale, bias, mean, var],
                  known_grads={out2: dy},
              )
              # compile
              f = theano.function(
                  [x, scale, bias, mean, var, dy],
                  [out, out2] + grads + grads2,
              )
              # check if the abstract Ops have been replaced
              assert not any(
                  [
                      isinstance(
                          n.op,
                          (
                              bn.AbstractBatchNormTrain,
                              bn.AbstractBatchNormInference,
                              bn.AbstractBatchNormTrainGrad,
                          ),
                      )
                      for n in f.maker.fgraph.toposort()
                  ]
              )
              # run
              for data_shape in (
                  (10, 20, 30, 40, 10),
                  (4, 3, 1, 1, 1),
                  (1, 1, 5, 5, 5),
              ):
                  data_shape = data_shape[:ndim]
                  param_shape = tuple(
                      1 if d in axes2 else s
                      for d, s in enumerate(data_shape)
                  )
                  X = 4 + 3 * np.random.randn(*data_shape).astype(
                      theano.config.floatX
                  )
                  Dy = -1 + 2 * np.random.randn(*data_shape).astype(
                      theano.config.floatX
                  )
                  Scale = np.random.randn(*param_shape).astype(
                      theano.config.floatX
                  )
                  Bias = np.random.randn(*param_shape).astype(
                      theano.config.floatX
                  )
                  Mean = np.random.randn(*param_shape).astype(
                      theano.config.floatX
                  )
                  Var = np.random.rand(*param_shape).astype(
                      theano.config.floatX
                  )
                  outputs = f(X, Scale, Bias, Mean, Var, Dy)
                  # compare outputs
                  utt.assert_allclose(outputs[0], outputs[1])  # out
                  # compare gradients
                  utt.assert_allclose(
                      outputs[2], outputs[2 + 5], atol=4e-5
                  )  # dx
                  utt.assert_allclose(
                      outputs[3], outputs[3 + 5], atol=4e-5
                  )  # dscale
                  utt.assert_allclose(
                      outputs[4], outputs[4 + 5]
                  )  # dbias
                  utt.assert_allclose(
                      outputs[5], outputs[5 + 5]
                  )  # dmean
                  utt.assert_allclose(
                      outputs[6], outputs[6 + 5], rtol=2e-3, atol=4e-5
                  )
  
file_path: Theano/theano/tensor/nnet/tests/test_bn.py
imports: from __future__ import absolute_import, print_function, division
  import theano
  import theano.tensor
  from theano.tests import unittest_tools
  import numpy
  from collections import OrderedDict
  from theano.tensor.nnet import bn
label_desc: Use image node_id 8 for calling a global function with example usage: test_batch_normalization_test() without return types