code: def test_rearrange_imperative():
      for backend in collect_test_backends(symbolic=False, layers=True):
          print("Test layer for ", backend.framework_name)
  
          for (
              pattern,
              axes_lengths,
              input_shape,
              wrong_shapes,
          ) in rearrangement_patterns:
              x = numpy.arange(
                  numpy.prod(input_shape), dtype="float32"
              ).reshape(input_shape)
              result_numpy = rearrange(x, pattern, **axes_lengths)
              layer = backend.layers().Rearrange(
                  pattern, **axes_lengths
              )
              for shape in wrong_shapes:
                  try:
                      layer(
                          backend.from_numpy(
                              numpy.zeros(shape, dtype="float32")
                          )
                      )
                  except:
                      pass
                  else:
                      raise AssertionError("Failure expected")
  
              # simple pickling / unpickling
              layer2 = pickle.loads(pickle.dumps(layer))
              result1 = backend.to_numpy(layer(backend.from_numpy(x)))
              result2 = backend.to_numpy(layer2(backend.from_numpy(x)))
              assert numpy.allclose(result_numpy, result1)
              assert numpy.allclose(result1, result2)
  
              just_sum = backend.layers().Reduce(
                  "...->", reduction="sum"
              )
  
              variable = backend.from_numpy(x)
              result = just_sum(layer(variable))
  
              result.backward()
              assert numpy.allclose(backend.to_numpy(variable.grad), 1)
  
file_path: einops/tests/test_layers.py
imports: import pickle
  import tempfile
  from collections import namedtuple
  import numpy
  import pytest
  from einops import rearrange, reduce
  from .None import collect_test_backends, is_backend_tested, FLOAT_REDUCTIONS
label_desc: Use image node_id 1 for calling a global function with example usage: test_rearrange_imperative() without return types