code: def sample(
      self,
      num_samples: int,
      *,
      class_idx: Optional[int] = None,
      labels: Optional[Tensor] = None,
      **kwargs: Any,
  ) -> Tensor:
      z = self.generate_z(num_samples)
      if labels is None:
          labels = self.get_sample_labels(num_samples, class_idx)
      elif class_idx is not None:
          msg = "`class_idx` should not be provided when `labels` is provided"
          raise ValueError(msg)
      kw = shallow_copy_dict(kwargs)
      kw["z"] = z
      kw["labels"] = labels
      return safe_execute(self.decode, kw)
  
imports: import torch
  import random
  from abc import abstractmethod
  from abc import ABCMeta
  from torch import Tensor
  from typing import Any
  from typing import Optional
  from cftool.misc import safe_execute
  from cftool.misc import shallow_copy_dict
  from cftool.types import tensor_dict_type
  from ...schema import _forward
  from ...constants import INPUT_KEY
  from ...constants import LABEL_KEY
  from ...constants import PREDICTIONS_KEY
  from ...misc.toolkit import slerp
  from ...misc.toolkit import get_device
label_desc: Use image node_id 3 for calling the GaussianGeneratorMixin obj's underlying member method code with example usage: obj.sample(num_samples) and returns: safe_execute