code: def unpack_and_pack_against_numpy(x, ps, pattern: str):
      capturer_backend = CaptureException()
      capturer_numpy = CaptureException()
  
      with capturer_backend:
          unpacked = unpack(x, ps, pattern)
          packed, ps2 = pack(unpacked, pattern=pattern)
  
      with capturer_numpy:
          x_np = asnumpy(x)
          unpacked_np = unpack(x_np, ps, pattern)
          packed_np, ps3 = pack(unpacked_np, pattern=pattern)
  
      assert type(capturer_numpy.exception) == type(
          capturer_backend.exception
      )
      if capturer_numpy.exception is not None:
          # both failed
          return
      else:
          # neither failed, check results are identical
          assert np.allclose(asnumpy(packed), asnumpy(x))
          assert np.allclose(asnumpy(packed_np), asnumpy(x))
          assert len(unpacked) == len(unpacked_np)
          for a, b in zip(unpacked, unpacked_np):
              assert np.allclose(asnumpy(a), b)
  
file_path: einops/tests/test_packing.py
imports: import dataclasses
  import typing
  import numpy
  import pytest
  from einops import EinopsError, asnumpy, pack, unpack
  from tests import collect_test_backends
label_desc: Use image node_id 3 for calling a global function with example usage: unpack_and_pack_against_numpy(x, ps, pattern) without return types