code: def reduce_irls_eqn(
      key: Tuple, key_pattern: List[str], pdf: pd.DataFrame
  ) -> pd.DataFrame:
      """
      This function constructs lists of rows from the beta, XtGX, and XtY matrices corresponding to a particular header
      in X and alpha value evaluated in different sample_blocks, and then reduces those lists by element-wise mean in the
      case of beta and element-wise summation in the case of xtgx and xty. This reduction is repeated once for
      each sample_block, where the contribution of that sample_block is omitted.  There is therefore a one-to-one
      mapping of the starting lists and the reduced lists, e.g.:
  
          Input:
              List(xtgx_sample_block0, xtgx_sample_block1, ..., xtgx_sample_blockN)
          Output:
              List(xtgx_sum_excluding_sample_block0, xtgx_sum_excluding_sample_block1, ..., xtgx_sum_excluding_sample_blockN)
  
      Args:
          key : unique key identifying the rows emitted by a groupBy statement
          key_pattern : pattern of columns used in the groupBy statement
          pdf : starting Pandas DataFrame containing the lists of rows from XtX and XtY for block X identified by :key:
              schema (specified by the irls_eqn_struct):
               |-- header_block: string
               |-- sample_block: string
               |-- label: string
               |-- alpha_name : string
               |-- header: string
               |-- sort_key: integer
               |-- beta : double
               |-- xtgx: array
               |    |-- element: double
               |-- xty: array
               |    |-- element: double
  
      Returns:
          transformed Pandas DataFrame containing the aggregated leave-fold-out rows from XtX and XtY
              schema (specified by the irls_eqn_struct):
               |-- header_block: string
               |-- sample_block: string
               |-- label: string
               |-- alpha_name : string
               |-- header: string
               |-- sort_key: integer
               |-- beta : double
               |-- xtgx: array
               |    |-- element: double
               |-- xty: array
               |    |-- element: double
      """
      sum_xtgx = pdf["xtgx"].sum()
      sum_xty = pdf["xty"].sum()
      mean_beta = pdf["beta"].mean()
  
      # Use numpy broadcast to subtract each row from the sum
      pdf["xtgx"] = list(sum_xtgx - np.vstack(pdf["xtgx"].array))
      pdf["xty"] = list(sum_xty - pdf["xty"])
      pdf["beta"] = list(
          (pdf.shape[0] * mean_beta - pdf["beta"]) / (pdf.shape[0] - 1)
      )
  
      return pdf
  
imports: from .ridge_udfs import *
label_desc: Use image node_id 2 for calling a global function with example usage: reduce_irls_eqn(key, key_pattern, pdf) and returns: pdf