code: def valid_elements_for_evaluation(
      reference_arrays: List[
          Union[np.array, pd.Series, List[Union[int, float]]]
      ],
      arrays: List[
          Optional[
              Union[
                  int,
                  float,
                  np.array,
                  pd.Series,
                  List[Union[int, float]],
              ]
          ]
      ],
      reference_array_names: str,
      drop_leading_only: bool,
      keep_inf: bool,
  ):
      """Keeps finite elements from reference_array, and corresponding elements in *arrays.
  
      Parameters
      ----------
      reference_arrays : `list` [`numpy.array`, `pandas.Series` or `list` [`int`, `float`]]
          The reference arrays where the indices of NA/infs are populated.
          If length is longer than 1, a logical and will be used to choose valid elements.
      arrays : `list` [`int`, `float`, `numpy.array`, `pandas.Series` or `list` [`int`, `float`]]
          The arrays with the indices of NA/infs in ``reference_array`` to be dropped.
      reference_array_names : `str`
          The reference array name to be printed in the warning.
      drop_leading_only : `bool`
          True means dropping the leading NA/infs only
          (drop the leading indices whose values are not valid in any reference array).
          False means dropping all NA/infs regardless of where they are.
      keep_inf : `bool`
          True means dropping NA only.
          False means dropping both NA and INF.
      Returns
      -------
      arrays_valid_elements : `list` [`numpy.array`]
          List of numpy arrays with valid indices [*reference_arrays, *arrays]
      """
      if not all_equal_length(*reference_arrays, *arrays):
          raise Exception("length of arrays do not match")
  
      if len(reference_arrays) == 0:
          return reference_arrays + arrays
  
      reference_arrays = [
          np.array(reference_array)
          for reference_array in reference_arrays
      ]
      array_length = reference_arrays[0].shape[0]
  
      # Defines a function to perform the opposite of `numpy.isnan`.
      def is_not_nan(x):
          """Gets the True/False for elements that are not/are NANs.
  
          Parameters
          ----------
          x : array-like
              The input array.
  
          Returns
          -------
          is_not_nan : `numpy.array`
              True/False array indicating whethere the elements are not NAN/ are NAN.
          """
          return ~np.isnan(x)
  
      validation_func = is_not_nan if keep_inf else np.isfinite
      # Finds the indices of finite elements in reference array
      keep = [
          validation_func(reference_array)
          for reference_array in reference_arrays
      ]
      if drop_leading_only:
          # Gets the index where the first True is.
          # All the False after this True will not be heading False
          # and shouldn't be dropped.
          # If multiple arrays in ``reference_arrays``,
          # this will be the minimum.
          valid_indices = [np.where(array)[0] for array in keep]
          heading_lengths = [
              length[0] if length.shape[0] > 0 else array_length
              for length in valid_indices
          ]
          heading_length = min(heading_lengths)
          # Generates arrays with the is_heading flag.
          is_not_heading = np.repeat(
              [False, True],
              [heading_length, array_length - heading_length],
          )
      else:
          is_not_heading = np.repeat([False, True], [array_length, 0])
      keep = np.logical_and.reduce(keep, axis=0)
      keep = np.logical_or(keep, is_not_heading)
      num_remaining = keep.sum()
      num_removed = array_length - num_remaining
      removed_elements = "NA" if keep_inf else "NA or infinite"
      if num_remaining == 0:
          warnings.warn(
              f"There are 0 non-null elements for evaluation."
          )
      if num_removed > 0:
          warnings.warn(
              f"{num_removed} value(s) in {reference_array_names} were {removed_elements} and are omitted in error calc."
          )
  
      # Keeps these indices in all arrays. Leaves float, int, and None as-is
      return [array[keep] for array in reference_arrays] + [
          np.array(array)[keep]
          if (
              array is not None
              and not isinstance(array, (float, int, np.float32))
          )
          else array
          for array in arrays
      ]
  
imports: import math
  import warnings
  from collections import namedtuple
  from enum import Enum
  from functools import partial
  from typing import List
  from typing import Optional
  from typing import Union
  import numpy
  import pandas
  from scipy.stats import pearsonr
  from sklearn.metrics import mean_absolute_error
  from sklearn.metrics import mean_squared_error
  from sklearn.metrics import median_absolute_error
  from sklearn.metrics import r2_score
  from greykite.common.constants import ACTUAL_COL
  from greykite.common.constants import COVERAGE_VS_INTENDED_DIFF
  from greykite.common.constants import LOWER_BAND_COVERAGE
  from greykite.common.constants import PREDICTED_COL
  from greykite.common.constants import PREDICTED_LOWER_COL
  from greykite.common.constants import PREDICTED_UPPER_COL
  from greykite.common.constants import PREDICTION_BAND_COVERAGE
  from greykite.common.constants import PREDICTION_BAND_WIDTH
  from greykite.common.constants import UPPER_BAND_COVERAGE
  from greykite.common.logging import LoggingLevelEnum
  from greykite.common.logging import log_message
label_desc: Use image node_id 2 for calling a global function with example usage: valid_elements_for_evaluation(reference_arrays, arrays, reference_array_names, drop_leading_only, keep_inf) and returns: unknown, unknown, unknown