code: def test_optimized_historical_forecasts_torch_with_encoders(
      self, config
  ):
      (
          use_covs,
          last_points_only,
          overlap_end,
          stride,
          horizon,
          use_int_idx,
          use_multi_series,
      ) = config
      icl = 3
      ocl = 5
      len_val_series = 10
      series_train, series_val = (
          self.ts_pass_train[:10],
          self.ts_pass_val[:len_val_series],
      )
      if use_int_idx:
          series_train = TimeSeries.from_values(
              series_train.all_values(), columns=series_train.columns
          )
          series_val = TimeSeries.from_times_and_values(
              values=series_val.all_values(),
              times=pd.RangeIndex(
                  start=series_train.end_time() + series_train.freq,
                  stop=series_train.end_time()
                  + (len(series_val) + 1) * series_train.freq,
                  step=series_train.freq,
              ),
              columns=series_train.columns,
          )
  
      def f_encoder(idx):
          return idx.month if not use_int_idx else idx
  
      model = NLinearModel(
          input_chunk_length=icl,
          add_encoders={
              "custom": {"past": [f_encoder], "future": [f_encoder]},
          },
          output_chunk_length=ocl,
          n_epochs=1,
          **tfm_kwargs,
      )
      if use_covs:
          pc = tg.gaussian_timeseries(
              start=series_train.start_time(),
              end=series_val.end_time()
              + max(0, horizon - ocl) * series_train.freq,
              freq=series_train.freq,
          )
          fc = tg.gaussian_timeseries(
              start=series_train.start_time(),
              end=series_val.end_time()
              + max(ocl, horizon) * series_train.freq,
              freq=series_train.freq,
          )
      else:
          pc, fc = None, None
  
      model.fit(series_train, past_covariates=pc, future_covariates=fc)
  
      if use_multi_series:
          series_val = [
              series_val,
              (series_val + 10)
              .shift(1)
              .with_columns_renamed(series_val.columns, "test_col"),
          ]
          pc = [pc, pc.shift(1)] if pc is not None else None
          fc = [fc, fc.shift(1)] if fc is not None else None
  
      hist_fct = model.historical_forecasts(
          series=series_val,
          past_covariates=pc,
          future_covariates=fc,
          retrain=False,
          last_points_only=last_points_only,
          overlap_end=overlap_end,
          stride=stride,
          forecast_horizon=horizon,
          enable_optimization=False,
      )
  
      opti_hist_fct = model._optimized_historical_forecasts(
          series=series_val
          if isinstance(series_val, list)
          else [series_val],
          past_covariates=pc
          if (isinstance(pc, list) or pc is None)
          else [pc],
          future_covariates=fc
          if (isinstance(fc, list) or fc is None)
          else [fc],
          last_points_only=last_points_only,
          overlap_end=overlap_end,
          stride=stride,
          forecast_horizon=horizon,
      )
  
      if not isinstance(series_val, list):
          series_val = [series_val]
          hist_fct = [hist_fct]
          opti_hist_fct = [opti_hist_fct]
  
      for series, hfc, ohfc in zip(series_val, hist_fct, opti_hist_fct):
          if not isinstance(hfc, list):
              hfc = [hfc]
              ohfc = [ohfc]
  
          if not last_points_only and overlap_end:
              n_pred_series_expected = 8
              n_pred_points_expected = horizon
              first_ts_expected = series.time_index[icl]
              last_ts_expected = (
                  series.end_time() + series.freq * horizon
              )
          elif not last_points_only:  # overlap_end = False
              n_pred_series_expected = len(series) - icl - horizon + 1
              n_pred_points_expected = horizon
              first_ts_expected = series.time_index[icl]
              last_ts_expected = series.end_time()
          elif overlap_end:  # last_points_only = True
              n_pred_series_expected = 1
              n_pred_points_expected = 8
              first_ts_expected = (
                  series.time_index[icl] + (horizon - 1) * series.freq
              )
              last_ts_expected = (
                  series.end_time() + series.freq * horizon
              )
          else:  # last_points_only = True, overlap_end = False
              n_pred_series_expected = 1
              n_pred_points_expected = len(series) - icl - horizon + 1
              first_ts_expected = (
                  series.time_index[icl] + (horizon - 1) * series.freq
              )
              last_ts_expected = series.end_time()
  
          # to make it simple in case of stride, we assume that non-optimized hist fc returns correct results
          if stride > 1:
              n_pred_series_expected = len(hfc)
              n_pred_points_expected = len(hfc[0])
              first_ts_expected = hfc[0].start_time()
              last_ts_expected = hfc[-1].end_time()
  
          # check length match between optimized and default hist fc
          assert len(ohfc) == n_pred_series_expected
          assert len(hfc) == len(ohfc)
          # check hist fc start
          assert ohfc[0].start_time() == first_ts_expected
          # check hist fc end
          assert ohfc[-1].end_time() == last_ts_expected
          for hfc, ohfc in zip(hfc, ohfc):
              assert hfc.columns.equals(series.columns)
              assert ohfc.columns.equals(series.columns)
              assert len(ohfc) == n_pred_points_expected
              assert (hfc.time_index == ohfc.time_index).all()
              np.testing.assert_array_almost_equal(
                  hfc.all_values(), ohfc.all_values()
              )
  
imports: import itertools
  from itertools import product
  import numpy
  import pandas
  import pytest
  import darts
  from darts import TimeSeries, concatenate
  from darts.dataprocessing.transformers import Scaler
  from darts.datasets import AirPassengersDataset
  from darts.logging import get_logger
  from darts.models import ARIMA, AutoARIMA, CatBoostModel, LightGBMModel, LinearRegressionModel, NaiveSeasonal, NotImportedModule
  from darts.tests.conftest import tfm_kwargs
  from darts.utils import timeseries_generation
label_desc: Use image node_id 13 for calling the TestHistoricalforecast obj's underlying member method code with example usage: obj.test_optimized_historical_forecasts_torch_with_encoders(config) and returns: unknown