code: def matrix_power(
      x: Union[tf.Tensor, tf.Variable],
      n: int,
      /,
      *,
      out: Optional[Union[tf.Tensor, tf.Variable]] = None,
  ) -> Union[tf.Tensor, tf.Variable]:
      if n == 0:
          return tf.broadcast_to(
              tf.eye(x.shape[-2], dtype=x.dtype), x.shape
          )
      elif n < 0:
          x = tf.linalg.inv(x)
          n = abs(n)
  
      if n == 1:
          return x
      elif n == 2:
          return x @ x
      elif n == 3:
          return (x @ x) @ x
  
      z = result = None
      while n > 0:
          z = x if z is None else (z @ z)
          n, bit = divmod(n, 2)
          if bit:
              result = z if result is None else (result @ z)
      # replace any -0 with 0
      result = tf.where(
          tf.equal(result, -0), tf.zeros_like(result), result
      )
      return result
  
imports: from typing import Union, Optional, Tuple, Literal, List, NamedTuple, Sequence
  from collections import namedtuple
  import tensorflow
  from tensorflow.python.framework.dtypes import DType
  import ivy
  from ivy import inf
  from ivy.func_wrapper import with_unsupported_dtypes, with_supported_dtypes
  from .None import backend_version
label_desc: Use image node_id 12 for calling a global function with example usage: matrix_power() and returns: result, tf, x, unknown, unknown