code: def test_optimized_historical_forecasts_regression(self, config):
      ts, model_config, multi_models, forecast_horizon = config
      # slightly longer to not affect the last predictable timestamp
      ts_covs = self.ts_covs
      start = 14
  
      model_cls = LinearRegressionModel
      _, model_kwargs, _, _ = model_config
      # cover several covariates combinations and several regression models
      # ocl == forecast horizon
      model_kwargs_same = model_kwargs.copy()
      model_kwargs_same["output_chunk_length"] = forecast_horizon
      model_kwargs_same["multi_models"] = multi_models
      model_same = model_cls(**model_kwargs_same)
      model_same.fit(
          series=ts[:start],
          past_covariates=ts_covs
          if model_same.supports_past_covariates
          else None,
          future_covariates=ts_covs
          if model_same.supports_future_covariates
          else None,
      )
      # ocl >= forecast horizon
      model_kwargs_diff = model_kwargs.copy()
      model_kwargs_diff["output_chunk_length"] = 5
      model_kwargs_diff["multi_models"] = multi_models
      model_diff = model_cls(**model_kwargs_same)
      model_diff.fit(
          series=ts[:start],
          past_covariates=ts_covs
          if model_diff.supports_past_covariates
          else None,
          future_covariates=ts_covs
          if model_diff.supports_future_covariates
          else None,
      )
      # no parametrization to save time on model training at the cost of test granularity
      for model in [model_same, model_diff]:
          for last_points_only in [True, False]:
              for stride in [1, 2]:
                  hist_fct = model.historical_forecasts(
                      series=ts,
                      past_covariates=ts_covs
                      if model.supports_past_covariates
                      else None,
                      future_covariates=ts_covs
                      if model.supports_future_covariates
                      else None,
                      start=start,
                      retrain=False,
                      last_points_only=last_points_only,
                      stride=stride,
                      forecast_horizon=forecast_horizon,
                      enable_optimization=False,
                  )
  
                  # manually packing the series in list to match expected inputs
                  opti_hist_fct = model._optimized_historical_forecasts(
                      series=[ts],
                      past_covariates=[ts_covs]
                      if model.supports_past_covariates
                      else None,
                      future_covariates=[ts_covs]
                      if model.supports_future_covariates
                      else None,
                      start=start,
                      last_points_only=last_points_only,
                      stride=stride,
                      forecast_horizon=forecast_horizon,
                  )
                  # pack the output to generalize the tests
                  if last_points_only:
                      hist_fct = [hist_fct]
                      opti_hist_fct = [opti_hist_fct]
  
                  for fct, opti_fct in zip(hist_fct, opti_hist_fct):
                      assert (
                          fct.time_index == opti_fct.time_index
                      ).all()
                      np.testing.assert_array_almost_equal(
                          fct.all_values(), opti_fct.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 10 for calling the TestHistoricalforecast obj's underlying member method code with example usage: obj.test_optimized_historical_forecasts_regression(config) without return types