code: def format_reconciled_forecasts(
      df: pd.DataFrame,
      prediction_length: int,
      fcst_col_name: str,
      S: pd.DataFrame,
  ):
      target_dim = S.shape[0]
  
      assert len(df) == target_dim * prediction_length
  
      # we want rows to correspond to time and columns to forecasts
      hier_forecasts = df.pivot(columns="ds", values=fcst_col_name)
  
      # we want columns to follow the order of the rows of S
      hier_forecasts = hier_forecasts.loc[S.index].T
  
      # we want rows to be sorted according to time
      hier_forecasts = hier_forecasts.sort_index()
  
      return np.array(hier_forecasts)
  
imports: from typing import List, Optional, Union, Any, Dict
  import numpy
  import pandas
  from statsforecast import StatsForecast
  from hierarchicalforecast.core import HierarchicalReconciliation
  from hierarchicalforecast.core import _build_fn_name
  from gluonts.core.component import validated
  from gluonts.dataset import DataEntry
  from gluonts.dataset.util import forecast_start
  from gluonts.model.predictor import RepresentablePredictor
  from gluonts.model.forecast import QuantileForecast
  from gluonts.ext.statsforecast import ModelConfig
label_desc: Use image node_id 4 for calling a global function with example usage: format_reconciled_forecasts(df, prediction_length, fcst_col_name, S) and returns: np