code: def discount_with_boundaries(rewards, episode_starts, gamma):
      """
      computes discounted sums along 0th dimension of x (reward), while taking into account the start of each episode.
          y[t] = x[t] + gamma*x[t+1] + gamma^2*x[t+2] + ... + gamma^k x[t+k],
                  where k = len(x) - t - 1
  
      :param rewards: (np.ndarray) the input vector (rewards)
      :param episode_starts: (np.ndarray) 2d array of bools, indicating when a new episode has started
      :param gamma: (float) the discount factor
      :return: (np.ndarray) the output vector (discounted rewards)
      """
      discounted_rewards = np.zeros_like(rewards)
      n_samples = rewards.shape[0]
      discounted_rewards[n_samples - 1] = rewards[n_samples - 1]
      for step in range(n_samples - 2, -1, -1):
          discounted_rewards[step] = rewards[
              step
          ] + gamma * discounted_rewards[step + 1] * (
              1 - episode_starts[step + 1]
          )
      return discounted_rewards
  
file_path: stable-baselines/stable_baselines/common/math_util.py
imports: import numpy
  import scipy.signal
label_desc: Use image node_id 7 for calling a global function with example usage: discount_with_boundaries(rewards, episode_starts, gamma) and returns: discounted_rewards