docstr: Predict using a trained forecaster.
  
  :params data: The data support following formats:
  
          | 1. A numpy ndarray x:
          | x's shape is (num_samples, lookback, feature_dim) where lookback and feature_dim
          | should be the same as past_seq_len and input_feature_num.
          |
          | 2. A tfdataset
          | A TFDataset instance which contains x and y with same shape as the tuple.
          | the tfdataset needs to return at least x in each iteration
          | with the shape as following:
          | x's shape is (num_samples, lookback, feature_dim) where lookback and feature_dim
          | should be the same as past_seq_len and input_feature_num.
          | If returns x and y only get x.
          |
          | 3. A bigdl.chronos.data.tsdataset.TSDataset instance
          | Forecaster will automatically process the TSDataset.
          | By default, TSDataset will be transformed to a tfdataset,
          | Users may call `roll` on the TSDataset before calling `fit`
          | Then the training speed will be faster but will consume more memory.
  
  :params batch_size: predict batch size. The value will not affect evaluate
          result but will affect resources cost(e.g. memory and time).
          The value default to 32. If set to None,
          the model will be used directly for inference.
  :param quantize: if use the quantized model to predict.
  
  :return: A numpy array with shape (num_samples, horizon, target_dim).
docstr_tok: ["Predict","using","a","trained","forecaster",".",":","params","data",":","The","data","support","following","formats",":","|","1",".","A","numpy","ndarray","x",":","|","x","'s","shape","is","(","num_samples",",","lookback",",","feature_dim",")","where","lookback","and","feature_dim","|","should","be","the","same","as","past_seq_len","and","input_feature_num",".","|","|","2",".","A","tfdataset","|","A","TFDataset","instance","which","contains","x","and","y","with","same","shape","as","the","tuple",".","|","the","tfdataset","needs","to","return","at","least","x","in","each","iteration","|","with","the","shape","as","following",":","|","x","'s","shape","is","(","num_samples",",","lookback",",","feature_dim",")","where","lookback","and","feature_dim","|","should","be","the","same","as","past_seq_len","and","input_feature_num",".","|","If","returns","x","and","y","only","get","x",".","|","|","3",".","A","bigdl.chronos.data.tsdataset.TSDataset","instance","|","Forecaster","will","automatically","process","the","TSDataset",".","|","By","default",",","TSDataset","will","be","transformed","to","a","tfdataset",",","|","Users","may","call","`","roll","`","on","the","TSDataset","before","calling","`","fit","`","|","Then","the","training","speed","will","be","faster","but","will","consume","more","memory",".",":","params","batch_size",":","predict","batch","size",".","The","value","will","not","affect","evaluate","result","but","will","affect","resources","cost","(","e.g",".","memory","and","time",")",".","The","value","default","to","32",".","If","set","to","None",",","the","model","will","be","used","directly","for","inference",".",":","param","quantize",":","if","use","the","quantized","model","to","predict",".",":","return",":","A","numpy","array","with","shape","(","num_samples",",","horizon",",","target_dim",")","."]
code: def predict(self, data, batch_size=32, quantize=False):
      """
      Predict using a trained forecaster.
  
      :params data: The data support following formats:
  
              | 1. A numpy ndarray x:
              | x's shape is (num_samples, lookback, feature_dim) where lookback and feature_dim
              | should be the same as past_seq_len and input_feature_num.
              |
              | 2. A tfdataset
              | A TFDataset instance which contains x and y with same shape as the tuple.
              | the tfdataset needs to return at least x in each iteration
              | with the shape as following:
              | x's shape is (num_samples, lookback, feature_dim) where lookback and feature_dim
              | should be the same as past_seq_len and input_feature_num.
              | If returns x and y only get x.
              |
              | 3. A bigdl.chronos.data.tsdataset.TSDataset instance
              | Forecaster will automatically process the TSDataset.
              | By default, TSDataset will be transformed to a tfdataset,
              | Users may call `roll` on the TSDataset before calling `fit`
              | Then the training speed will be faster but will consume more memory.
  
      :params batch_size: predict batch size. The value will not affect evaluate
              result but will affect resources cost(e.g. memory and time).
              The value default to 32. If set to None,
              the model will be used directly for inference.
      :param quantize: if use the quantized model to predict.
  
      :return: A numpy array with shape (num_samples, horizon, target_dim).
      """
      if isinstance(data, TSDataset):
          if data.lookback is None:
              data.roll(
                  lookback=self.model_config["past_seq_len"],
                  horizon=self.model_config["future_seq_len"],
              )
  
      invalidInputError(
          self.fitted,
          "You must call fit or restore first before calling predict!",
      )
  
      if self.distributed:
          if isinstance(data, np.ndarray):
              data = np_to_xshards(data, self.workers_per_node)
          if isinstance(data, TSDataset):
              input_data, _ = data.to_numpy()
              data = np_to_xshards(input_data, self.workers_per_node)
          invalidInputError(
              not isinstance(data, tf.data.Dataset),
              "prediction on tf.data.Dataset will be supported in future.",
          )
          yhat = self.internal.predict(data, batch_size=batch_size)
  
          # pytorch and tf2 have different behavior, when `future_seq_len` and
          # `output_feature_num` are equal to 1, they will not squeeze data.
          yhat = xshard_to_np(yhat, mode="yhat")
      else:
          if isinstance(data, TSDataset):
              data = data.to_tf_dataset(batch_size, batch_size)
          if batch_size or isinstance(data, tf.data.Dataset):
              if quantize:
                  invalidInputError(
                      self.accelerate_method == "tensorflow_int8",
                      "Can't find the quantized model, "
                      "please call .quantize() method first",
                  )
                  yhat = self.accelerated_model.predict(data)
              else:
                  yhat = self.internal.predict(data)
          else:
              if quantize:
                  invalidInputError(
                      self.accelerate_method == "tensorflow_int8",
                      "Can't find the quantized model, "
                      "please call .quantize() method first",
                  )
                  yhat = self.accelerated_model(
                      data, training=False
                  ).numpy()
              else:
                  yhat = self.internal(data, training=False).numpy()
      return yhat
  
imports: import warnings
  import keras
  import tensorflow
  import numpy
  from bigdl.chronos.forecaster.abstract import Forecaster
  from bigdl.chronos.data import TSDataset
  from bigdl.chronos.metric.forecast_metrics import Evaluator
  from bigdl.nano.utils.common import invalidInputError
  from bigdl.chronos.forecaster.tf.utils import np_to_data_creator, tsdata_to_data_creator, np_to_xshards, xshard_to_np, np_to_tfdataset
label_desc: Use image node_id 4 for calling the BaseTF2Forecaster obj's underlying member method code with example usage: obj.predict(data, batch_size, quantize) and returns: yhat