code: def make_checks(loop_orders, dtypes, sub):
      init = ""
      for i, (loop_order, dtype) in enumerate(zip(loop_orders, dtypes)):
          var = f"%(lv{int(i)})s"
          # List of dimensions of var that are not broadcasted
          nonx = [x for x in loop_order if x != "x"]
          if nonx:
              # If there are dimensions that are not broadcasted
              # this is a check that the number of dimensions of the
              # tensor is as expected.
              min_nd = max(nonx) + 1
              init += f"""
              if (PyArray_NDIM({var}) < {min_nd}) {{
                  PyErr_SetString(PyExc_ValueError, "Not enough dimensions on input.");
                  %(fail)s
              }}
              """
  
          # In loop j, adjust represents the difference of values of the
          # data pointer between the beginning and the end of the
          # execution of loop j+1 (the loop inside the current one). It
          # is equal to the stride in loop j+1 times the length of loop
          # j+1, or 0 for the inner-most loop.
          adjust = "0"
  
          # We go from the inner loop to the outer loop
          for j, index in reversed(list(enumerate(loop_order))):
              if index != "x":
                  # Initialize the variables associated to the jth loop
                  # jump = stride - adjust
                  jump = f"({var}_stride{index}) - ({adjust})"
                  init += f"""
                  {var}_n{index} = PyArray_DIMS({var})[{index}];
                  {var}_stride{index} = PyArray_STRIDES({var})[{index}] / sizeof({dtype});
                  {var}_jump{index}_{j} = {jump};
                  """
                  adjust = f"{var}_n{index}*{var}_stride{index}"
              else:
                  jump = f"-({adjust})"
                  init += f"""
                  {var}_jump{index}_{j} = {jump};
                  """
                  adjust = "0"
      check = ""
  
      # This loop builds multiple if conditions to verify that the
      # dimensions of the inputs match, and the first one that is true
      # raises an informative error message
  
      runtime_broadcast_error_msg = (
          "Runtime broadcasting not allowed. "
          "One input had a distinct dimension length of 1, but was not marked as broadcastable: "
          "(input[%%i].shape[%%i] = %%lld, input[%%i].shape[%%i] = %%lld). "
          "If broadcasting was intended, use `specify_broadcastable` on the relevant input."
      )
  
      for matches in zip(*loop_orders):
          to_compare = [
              (j, x) for j, x in enumerate(matches) if x != "x"
          ]
  
          # elements of to_compare are pairs ( input_variable_idx, input_variable_dim_idx )
          if len(to_compare) < 2:
              continue
  
          j0, x0 = to_compare[0]
          for j, x in to_compare[1:]:
              check += f"""
              if (%(lv{j0})s_n{x0} != %(lv{j})s_n{x})
              {{
                  if (%(lv{j0})s_n{x0} == 1 || %(lv{j})s_n{x} == 1)
                  {{
                      PyErr_Format(PyExc_ValueError, "{runtime_broadcast_error_msg}",
                     {j0},
                     {x0},
                     (long long int) %(lv{j0})s_n{x0},
                     {j},
                     {x},
                     (long long int) %(lv{j})s_n{x}
                      );
                  }} else {{
                      PyErr_Format(PyExc_ValueError, "Input dimension mismatch: (input[%%i].shape[%%i] = %%lld, input[%%i].shape[%%i] = %%lld)",
                         {j0},
                         {x0},
                         (long long int) %(lv{j0})s_n{x0},
                         {j},
                         {x},
                         (long long int) %(lv{j})s_n{x}
                      );
                  }}
                  %(fail)s
              }}
          """
  
      return init % sub + check % sub
  
file_path: pytensor/pytensor/tensor/elemwise_cgen.py
imports: from pytensor.configdefaults import config
label_desc: Use image node_id 2 for calling a global function with example usage: make_checks(loop_orders, dtypes, sub) and returns: unknown