docstr: Adds padding to the time series `X` such that after applying a valid convolution with a kernel/filter
  `w`, the resulting time series has the same shape as the input `X`.
  
  Parameters
  ----------
  X
      Time series to be padded
  W
      Convolution kernel/filter.
  method
      Padding method to be used.
      Possible values:
  
       - `constant` - padding with constant 0.
  
       - `replicate` - repeats the last/extreme value.
  
       - `reflect` - reflects the time series.
  side
      Whether to pad the time series bilateral or only on one side.
      Possible values:
  
       - `bilateral` - time series is padded on both sides.
  
       - `left` - time series is padded only on the left hand side.
  
       - `right` - time series is padded only on the right hand side.
  
  Returns
  -------
  Padded time series.
docstr_tok: ["Adds","padding","to","the","time","series","`","X","`","such","that","after","applying","a","valid","convolution","with","a","kernel\/filter","`","w","`",",","the","resulting","time","series","has","the","same","shape","as","the","input","`","X","`",".","Parameters","--","--","--","--","--","X","Time","series","to","be","padded","W","Convolution","kernel\/filter",".","method","Padding","method","to","be","used",".","Possible","values",":","-","`","constant","`","-","padding","with","constant","0",".","-","`","replicate","`","-","repeats","the","last\/extreme","value",".","-","`","reflect","`","-","reflects","the","time","series",".","side","Whether","to","pad","the","time","series","bilateral","or","only","on","one","side",".","Possible","values",":","-","`","bilateral","`","-","time","series","is","padded","on","both","sides",".","-","`","left","`","-","time","series","is","padded","only","on","the","left","hand","side",".","-","`","right","`","-","time","series","is","padded","only","on","the","right","hand","side",".","Returns","--","--","--","-","Padded","time","series","."]
code: def pad_same(
      X: np.ndarray,
      W: np.ndarray,
      method: str = "replicate",
      side: str = "bilateral",
  ) -> np.ndarray:
      """
      Adds padding to the time series `X` such that after applying a valid convolution with a kernel/filter
      `w`, the resulting time series has the same shape as the input `X`.
  
      Parameters
      ----------
      X
          Time series to be padded
      W
          Convolution kernel/filter.
      method
          Padding method to be used.
          Possible values:
  
           - `constant` - padding with constant 0.
  
           - `replicate` - repeats the last/extreme value.
  
           - `reflect` - reflects the time series.
      side
          Whether to pad the time series bilateral or only on one side.
          Possible values:
  
           - `bilateral` - time series is padded on both sides.
  
           - `left` - time series is padded only on the left hand side.
  
           - `right` - time series is padded only on the right hand side.
  
      Returns
      -------
      Padded time series.
      """
      paddings = [p.value for p in Padding]
      if method not in paddings:
          raise ValueError(
              f"Unknown padding method. Received '{method}'. Select one of the following: {paddings}."
          )
  
      sides = [s.value for s in Side]
      if side not in sides:
          raise ValueError(
              f"Unknown padding side. Received '{side}'. Select one of the following: {sides}."
          )
  
      if len(X.shape) != 1:
          raise ValueError(
              f"Only 1D time series supported. Received a times series with {len(X.shape)} dimensions."
          )
  
      if len(W.shape) != 1:
          raise ValueError(
              "Only 1D kernel/filter supported. Received a kernel/filter "
              f"with {len(W.shape)} dimensions."
          )
  
      pad_size = W.shape[0] - 1
  
      if side == Side.BILATERAL:
          pad_size_right = pad_size // 2
          pad_size_left = pad_size - pad_size_right
  
      elif side == Side.LEFT:
          pad_size_right = 0
          pad_size_left = pad_size
  
      else:
          pad_size_right = pad_size
          pad_size_left = 0
  
      # replicate padding
      if method == Padding.REPLICATE:
          return np.concatenate(
              [
                  np.tile(X[0], pad_size_left),
                  X,
                  np.tile(X[-1], pad_size_right),
              ]
          )
  
      # reflection padding
      if method == Padding.REFLECT:
          return np.concatenate(
              [
                  X[1 : pad_size_left + 1][::-1],
                  X,
                  X[-pad_size_right - 1 : -1][::-1]
                  if pad_size_right > 0
                  else np.array([]),
              ]
          )
  
      # zero padding
      return np.concatenate(
          [np.tile(0, pad_size_left), X, np.tile(0, pad_size_right)]
      )
  
imports: import enum
  import logging
  import numpy
  from typing import Dict
  from alibi_detect.base import BaseDetector, ThresholdMixin, outlier_prediction_dict
  from alibi_detect.utils._types import Literal
label_desc: Use image node_id 3 for calling the SpectralResidual obj's underlying member method code with example usage: obj.pad_same(X, W, method, side) and returns: np, np, np