code: def test_functional_errors():
      # Specific backend does not matter, as errors are raised
      # during the pattern creation.
  
      rstate = np.random.RandomState(0)
      create_tensor = lambda *shape: rstate.uniform(size=shape).astype(
          "float32"
      )
  
      # raise NotImplementedError("Singleton () axes are not yet supported in einsum.")
      with pytest.raises(NotImplementedError, match="^Singleton"):
          einsum(
              create_tensor(5, 1),
              "i () -> i",
          )
  
      # raise NotImplementedError("Shape rearrangement is not yet supported in einsum.")
      with pytest.raises(
          NotImplementedError, match="^Shape rearrangement"
      ):
          einsum(
              create_tensor(5, 1),
              "a b -> (a b)",
          )
  
      with pytest.raises(
          NotImplementedError, match="^Shape rearrangement"
      ):
          einsum(
              create_tensor(10, 1),
              "(a b) -> a b",
          )
  
      # raise RuntimeError("Encountered empty axis name in einsum.")
      # raise RuntimeError("Axis name in einsum must be a string.")
      # ^ Not tested, these are just a failsafe in case an unexpected error occurs.
  
      # raise NotImplementedError("Anonymous axes are not yet supported in einsum.")
      with pytest.raises(NotImplementedError, match="^Anonymous axes"):
          einsum(
              create_tensor(5, 1),
              "i 2 -> i",
          )
  
      # ParsedExpression error:
      with pytest.raises(EinopsError, match="^Invalid axis identifier"):
          einsum(
              create_tensor(5, 1),
              "i 2j -> i",
          )
  
      # raise ValueError("Einsum pattern must contain '->'.")
      with pytest.raises(ValueError, match="^Einsum pattern"):
          einsum(
              create_tensor(5, 3, 2),
              "i j k",
          )
  
      # raise RuntimeError("Too many axes in einsum.")
      with pytest.raises(RuntimeError, match="^Too many axes"):
          einsum(
              create_tensor(1),
              " ".join(string.ascii_letters) + " extra ->",
          )
  
      # raise RuntimeError("Unknown axis on right side of einsum.")
      with pytest.raises(RuntimeError, match="^Unknown axis"):
          einsum(
              create_tensor(5, 1),
              "i j -> k",
          )
  
      # raise ValueError(
      # "The last argument passed to `einops.einsum` must be a string,"
      # " representing the einsum pattern."
      # )
      with pytest.raises(ValueError, match="^The last argument"):
          einsum(
              "i j k -> i",
              create_tensor(5, 4, 3),
          )
  
      # raise ValueError(
      #     "`einops.einsum` takes at minimum two arguments: the tensors,"
      #     " followed by the pattern."
      # )
      with pytest.raises(ValueError, match="^`einops.einsum` takes"):
          einsum(
              "i j k -> i",
          )
      with pytest.raises(ValueError, match="^`einops.einsum` takes"):
          einsum(
              create_tensor(5, 1),
          )
  
file_path: einops/tests/test_einsum.py
imports: from typing import Any, Callable
  from venv import create
  from .None import collect_test_backends
  from einops.einops import _compactify_pattern_for_einsum, einsum, EinopsError
  import numpy
  import pytest
  import string
label_desc: Use image node_id 4 for calling a global function with example usage: test_functional_errors() without return types