code: def test_total_norm_constraint():
      import numpy as np
      import theano
      import theano.tensor as T
      from lasagne.updates import total_norm_constraint
  
      x1 = T.scalar()
      x2 = T.matrix()
      threshold = 5.0
      tensors1 = total_norm_constraint(
          [x1, x2], threshold, return_norm=False
      )
      tensors2, norm = total_norm_constraint(
          [x1, x2], threshold, return_norm=True
      )
  
      f1 = theano.function([x1, x2], [tensors1[0], tensors1[1]])
      f2 = theano.function([x1, x2], [tensors2[0], tensors2[1], norm])
  
      x_test = np.arange(1 + 9, dtype="float32")
      x1_test = x_test[-1]
      x2_test = x_test[:9].reshape((3, 3))
      x1_out1, x2_out1 = f1(x1_test, x2_test)
      x1_out2, x2_out2, norm = f2(x1_test, x2_test)
  
      np.testing.assert_array_almost_equal(x1_out1, x1_out2)
      np.testing.assert_array_almost_equal(x2_out1, x2_out2)
  
      x_out = [float(x1_out1)] + list(x2_out1.flatten())
  
      np.testing.assert_array_almost_equal(np.linalg.norm(x_test), norm)
      np.testing.assert_array_almost_equal(
          np.linalg.norm(x_out), threshold
      )
  
file_path: Lasagne/lasagne/tests/test_updates.py
imports: import pytest
  import numpy
  import theano
  import theano.tensor
  import lasagne
label_desc: Use image node_id 5 for calling a global function with example usage: test_total_norm_constraint() without return types