code: def calculate_moving_average(
      data: torch.Tensor, start: int, end: int
  ):
      cat = []
      pad = data.new_zeros(1, *data.shape[1:])
      cat.append(pad)
      if start <= 0:
          # pad = data.new_zeros(-start, *data.shape[1:])
          pad = data[:1].repeat(-start, *[1 for _ in data.shape[1:]])
          cat.append(pad)
  
      if start > 0:
          data = data[start:]
      if end < 0:
          data = data[:end]
      cat.append(data)
  
      if end > 0:
          # pad = data.new_zeros(end, *data.shape[1:])
          pad = data[-1:].repeat(end, *[1 for _ in data.shape[1:]])
          cat.append(pad)
  
      data = torch.cat(cat, dim=0)
      cum = data.cumsum(dim=0)
  
      range_ = end - start + 1
  
      avg = cum[range_:] - cum[:-range_]
      avg /= range_
  
      return avg
  
file_path: labml/samples/stocks/dataset.py
imports: import numpy
  import torch
  from labml import monit, lab
  from labml import tracker
  from torch.utils.data import Dataset
  from stocks import CandleIdx
  from stocks.build_numpy_cache import build_cache
label_desc: Use image node_id 2 for calling a global function with example usage: calculate_moving_average(data, start, end) and returns: avg