def _validate_data_size(self, name, value):
    if isinstance(value, to.Tensor):
        assert (not value.requires_grad), 'Do not add gradient-sensitive tensors to SampleCollections. This is a fast road to weird retain_graph errors!'
    if isinstance(value, dict):
        for (k, v) in value.items():
            self._validate_data_size(f'{name}.{k}', v)
        return
    if isinstance(value, tuple):
        for (i, v) in enumerate(value):
            self._validate_data_size(f'{name}[{i}]', v)
        return
    if isinstance(value, (np.ndarray, to.Tensor)):
        vlen = value.shape[0]
    else:
        assert isinstance(value, Sequence)
        vlen = len(value)
    if self.continuous:
        if (not ((vlen == self.length) or (vlen == (self.length + 1)))):
            raise pyrado.ShapeErr(msg=f'The data list {name} must have {self.length} or {self.length}+1 elements,but has {vlen} elements.')
    elif (not (vlen == self.length)):
        raise pyrado.ShapeErr(msg=f'The data list {name} must have {self.length} elements,but has {vlen} elements.')
def _validate_data_size(self, name, value):
    if isinstance(value, to.Tensor):
        assert (not value.requires_grad), 'Do not add gradient-sensitive tensors to SampleCollections. This is a fast road to weird retain_graph errors!'
    if isinstance(value, dict):
        for (k, v) in value.items():
            self._validate_data_size(f'{name}.{k}', v)
        return
    if isinstance(value, tuple):
        for (i, v) in enumerate(value):
            self._validate_data_size(f'{name}[{i}]', v)
        return
    if isinstance(value, (np.ndarray, to.Tensor)):
        vlen = value.shape[0]
    else:
        assert isinstance(value, Sequence)
        vlen = len(value)
    if self.continuous:
        if (not ((vlen == self.length) or (vlen == (self.length + 1)))):
            raise pyrado.ShapeErr(msg=f'The data list {name} must have {self.length} or {self.length}+1 elements,but has {vlen} elements.')
    elif (not (vlen == self.length)):
        raise pyrado.ShapeErr(msg=f'The data list {name} must have {self.length} elements,but has {vlen} elements.')