code: def check_docstring_examples_run(
      *, fn, from_container=False, from_array=False, num_sig_fig=2
  ):
      """Performs docstring tests for a given function.
  
      Parameters
      ----------
      fn
          Callable function to be tested.
      from_container
          if True, check docstring of the function as a method of an Ivy Container.
      from_array
          if True, check docstring of the function as a method of an Ivy Array.
      num_sig_fig
          Number of significant figures to check in the example.
  
      Returns
      -------
      None if the test passes, else marks the test as failed.
      """
      """
      Functions skipped as their output dependent on outside factors:
  
      random_normal, random_uniform, shuffle, num_gpus, current_backend,
      get_backend
      """
      to_skip = [
          "random_normal",
          "random_uniform",
          "randint",
          "shuffle",
          "beta",
          "gamma",
          "dev",
          "num_gpus",
          "current_backend",
          "get_backend",
          "namedtuple",
          "invalid_dtype",
          "DType",
          "NativeDtype",
          "Dtype",
          "multinomial",
          "num_cpu_cores",
          "get_all_ivy_arrays_on_dev",
          "num_ivy_arrays_on_dev",
          "total_mem_on_dev",
          "used_mem_on_dev",
          "percent_used_mem_on_dev",
          "function_supported_dtypes",
          "function_unsupported_dtypes",
          "randint",
          "unique_counts",
          "unique_all",
          "dropout",
          "dropout1d",
          "dropout2d",
          "dropout3d",
          "total_mem_on_dev",
          "supports_inplace_updates",
          "get",
          "deserialize",
          "set_split_factor",
      ]
      # the temp skip list consists of functions
      # which have an issue with their implementation
      skip_list_temp = [
          "outer",
          "argmax",
          "split",
          "det",
          "cumprod",
          "sinc",
          "grad",
          "try_else_none",
          # all examples are wrong including functional/ivy
          "einops_reduce",
          "max_unpool1d",
          "pool",
          "put_along_axis",
          "result_type",
          # works only if no backend set
          "rfftn",
          # examples works but exec throws error or generate diff results
          "scaled_dot_product_attention",
          "searchsorted",
          # generates different results in different backends
          "eigh_tridiagonal",
          "log_poisson_loss",
          "dct",
          "idct",
          "set_item",
          "l1_normalize",
          "histogram",
          "native_array",
          "function_supported_devices",
          "acosh",
          "bitwise_invert",
          "cosh",
          "exp",
          "sinh",
          "reciprocal",
          "deg2rad",
          "value_and_grad",
          "vector_norm",
          "set_nest_at_index",
          "set_nest_at_indices",
          "layer_norm",
          "where",
          "trace",
          "eigvalsh",
          "conv2d_transpose",
          # fails due to different backend and their view types
          "sequence_length",
          "max_pool1d",
          "vmap",
          "inner",
          "slogdet",
          "svdvals",
          "nested_map",
          "dill",
          "hardtanh",
          "hardshrink",
          "rfft",
          "general_inner_product",
          "l1_loss",
          "smooth_l1_loss",
          "poisson_nll_loss",
          "choose",
          "cummax",
          "one_hot",
          "tpu_is_available",
          "log2",
          "maximum",
          "minimum",
          "get_referrers_recursive",
          "clip_vector_norm",
          "set_min_base",
          "scatter_flat",
          "scatter_nd",
          "gather",
          "multiprocessing",
          "execute_with_gradients",
          "solve",
          "tensordot",
          "cross_entropy",
          "binary_cross_entropy",
          "sparse_cross_entropy",
          "reptile_step",
          "insert_into_nest_at_index",
          "if_else",
          "while_loop",
          "trace_graph",
          "set_tmp_dir",
      ]
  
      # skip list for array and container docstrings
      skip_arr_cont = [
          # generates different results due to randomization
          "cumprod",
          "supports_inplace_updates",
          "shuffle",
          "dropout",
          "dropout1d",
          "dropout2d",
          "dropout3",
          "svd",
          "unique_all",
          # exec and self run generates diff results
          "dev",
          "scaled_dot_product_attention",
          # temp list for array/container methods
          "einops_reduce",
          "array_equal",
          "batched_outer",
          "huber_loss",
          "softshrink",
          "tt_matrix_to_tensor",
          "unsorted_segment_mean",
          "array_equal",
          "batched_outer",
          "huber_loss",
          "kl_div",
          "soft_margin_loss",
          "threshold",
      ]
  
      # comment out the line below in future to check for the functions in temp skip list
      to_skip += skip_list_temp  # + currently_being_worked_on
  
      if not hasattr(fn, "__name__"):
          return True
      fn_name = fn.__name__
      if fn_name not in ivy.utils.backend.handler.ivy_original_dict:
          return True
  
      if from_container:
          docstring = getattr(
              ivy.utils.backend.handler.ivy_original_dict["Container"],
              fn_name,
          ).__doc__
      elif from_array:
          docstring = getattr(
              ivy.utils.backend.handler.ivy_original_dict["Array"],
              fn_name,
          ).__doc__
      else:
          docstring = ivy.utils.backend.handler.ivy_original_dict[
              fn_name
          ].__doc__
      if docstring is None:
          return True
      if fn_name in to_skip:
          return True
      if (from_container or from_array) and fn_name in skip_arr_cont:
          return True
  
      # removing extra new lines and trailing white spaces from the docstrings
      trimmed_docstring = trim(docstring=docstring)
      trimmed_docstring = trimmed_docstring.split("\n")
      # end_index: -1, if print statement is not found in the docstring
      end_index = -1
  
      # parsed_output is set as an empty string to manage functions with multiple inputs
      parsed_output = ""
  
      # parsing through the docstrings to find lines with print statement
      # following which is our parsed output
      sub = ">>> print("
      for index, line in enumerate(trimmed_docstring):
          if sub in line:
              for i, s in enumerate(trimmed_docstring[index + 1 :]):
                  if s.startswith(">>>") or s.lower().startswith(
                      ("with", "#", "instance")
                  ):
                      end_index = index + i + 1
                      break
              else:
                  end_index = len(trimmed_docstring)
              p_output = trimmed_docstring[index + 1 : end_index]
              p_output = "".join(p_output).replace(" ", "")
              p_output = p_output.replace("...", "")
              if parsed_output != "":
                  parsed_output += ","
              parsed_output += p_output
  
      if end_index == -1:
          return True
  
      executable_lines = []
  
      for line in trimmed_docstring:
          if line.startswith(">>>"):
              executable_lines.append(line.split(">>>")[1][1:])
              is_multiline_executable = True
          if line.startswith("...") and is_multiline_executable:
              executable_lines[-1] += line.split("...")[1][1:]
          if ">>> print(" in line:
              is_multiline_executable = False
  
      # noinspection PyBroadException
      f = StringIO()
      with redirect_stdout(f):
          for line in executable_lines:
              # noinspection PyBroadException
              try:
                  if f.getvalue() != "" and f.getvalue()[-2] != ",":
                      print(",")
                  exec(line)
              except Exception as e:
                  print(e, " ", ivy.current_backend_str(), " ", line)
  
      output = f.getvalue()
      output = output.rstrip()
      output = output.replace(" ", "").replace("\n", "")
      output = output.rstrip(",")
  
      # handling cases when the stdout contains ANSI colour codes
      # 7-bit C1 ANSI sequences
      ansi_escape = re.compile(
          r"""
      \x1B  # ESC
      (?:   # 7-bit C1 Fe (except CSI)
          [@-Z\\-_]
      |     # or [ for CSI, followed by a control sequence
          \[
          [0-?]*  # Parameter bytes
          [ -/]*  # Intermediate bytes
          [@-~]   # Final byte
      )
      """,
          re.VERBOSE,
      )
  
      output = ansi_escape.sub("", output)
  
      # print("Output: ", output)
      # print("Putput: ", parsed_output)
  
      # assert output == parsed_output, "Output is unequal to the docstrings output."
      sig_fig = float(f"1e-{str(num_sig_fig)}")
      atol = sig_fig / 10000
      numeric_pattern = re.compile(
          r"""
              [\{\}\(\)\[\]\<>]|\w+:
          """,
          re.VERBOSE,
      )
  
      num_output = output.replace("ivy.array", "").replace(
          "ivy.Shape", ""
      )
      num_parsed_output = parsed_output.replace(
          "ivy.array", ""
      ).replace("ivy.Shape", "")
      num_output = numeric_pattern.sub("", num_output)
      num_parsed_output = numeric_pattern.sub("", num_parsed_output)
      num_output = num_output.split(",")
      num_parsed_output = num_parsed_output.split(",")
      docstr_result = True
      for doc_u, doc_v in zip(num_output, num_parsed_output):
          try:
              docstr_result = np.allclose(
                  np.nan_to_num(complex(doc_u)),
                  np.nan_to_num(complex(doc_v)),
                  rtol=sig_fig,
                  atol=atol,
              )
          except Exception:
              if str(doc_u) != str(doc_v):
                  docstr_result = False
          if not docstr_result:
              print(
                  "output for ",
                  fn_name,
                  " on run: ",
                  output,
                  "\noutput in docs :",
                  parsed_output,
                  "\n",
                  doc_u,
                  " != ",
                  doc_v,
                  "\n",
              )
              ivy.warn(
                  f"Output is unequal to the docstrings output: {fn_name}",
                  stacklevel=0,
              )
              break
      return docstr_result
  
file_path: ivy/ivy_tests/test_docstrings.py
imports: import warnings
  import re
  from contextlib import redirect_stdout
  from io import StringIO
  import numpy
  import sys
  import pytest
  import ivy
  import ivy_tests.test_ivy.helpers
label_desc: Use image node_id 2 for calling a global function with example usage: check_docstring_examples_run() and returns: docstr_result, True, True, True, True, True, True