code: def stochastic_encode(
      self, x0, t, use_original_steps=False, noise=None
  ):
      # fast, but does not allow for exact reconstruction
      # t serves as an index to gather the correct alphas
      if use_original_steps:
          sqrt_alphas_cumprod = self.sqrt_alphas_cumprod
          sqrt_one_minus_alphas_cumprod = (
              self.sqrt_one_minus_alphas_cumprod
          )
      else:
          sqrt_alphas_cumprod = torch.sqrt(self.ddim_alphas)
          sqrt_one_minus_alphas_cumprod = (
              self.ddim_sqrt_one_minus_alphas
          )
  
      if noise is None:
          noise = torch.randn_like(x0)
      return (
          extract_into_tensor(sqrt_alphas_cumprod, t, x0.shape) * x0
          + extract_into_tensor(
              sqrt_one_minus_alphas_cumprod, t, x0.shape
          )
          * noise
      )
  
file_path: StableDiffusion/ldm/models/diffusion/ddim.py
imports: import torch
  import numpy
  from tqdm import tqdm
  from ldm.modules.diffusionmodules.util import make_ddim_sampling_parameters, make_ddim_timesteps, noise_like, extract_into_tensor
label_desc: Use image node_id 8 for calling the DDIMSampler obj's underlying member method code with example usage: obj.stochastic_encode(x0, t, use_original_steps, noise) and returns: unknown