def concat(self: TFlatData, other: TFlatData) -> TFlatData:
        """Concatenation operation.

        :param other: other dataset.
        :return:
        """
        if (not self._can_flatten) and (not other._can_flatten):
            return self.__class__(datasets=[self, other])

        # Case 1: one is a subset of the other
        if len(self._datasets) == 1 and len(other._datasets) == 1:
            if (
                self._can_flatten
                and self._datasets[0] is other
                and other._indices is None
            ):
                idxs = self._get_lazy_indices() + other._get_lazy_indices()
                return other.subset(idxs)
            elif (
                other._can_flatten
                and other._datasets[0] is self
                and self._indices is None
            ):
                idxs = self._get_lazy_indices() + other._get_lazy_indices()
                return self.subset(idxs)
            elif (
                self._can_flatten
                and other._can_flatten
                and self._datasets[0] is other._datasets[0]
            ):
                idxs = LazyIndices(self._get_lazy_indices(), other._get_lazy_indices())
                return self.__class__(datasets=self._datasets, indices=idxs)

        # Case 2: at least one of them can be flattened
        if self._can_flatten and other._can_flatten:
            if self._indices is None and other._indices is None:
                new_indices = None
            else:
                if len(self._cumulative_sizes) == 0:
                    base_other = 0
                else:
                    base_other = self._cumulative_sizes[-1]
                other_idxs = LazyIndices(other._get_lazy_indices(), offset=base_other)
                new_indices = self._get_lazy_indices() + other_idxs
            return self.__class__(
                datasets=self._datasets + other._datasets, indices=new_indices
            )
        elif self._can_flatten:
            if self._indices is None and other._indices is None:
                new_indices = None
            else:
                if len(self._cumulative_sizes) == 0:
                    base_other = 0
                else:
                    base_other = self._cumulative_sizes[-1]
                other_idxs = LazyRange(0, len(other), offset=base_other)
                new_indices = self._get_lazy_indices() + other_idxs
            return self.__class__(
                datasets=self._datasets + [other], indices=new_indices
            )
        elif other._can_flatten:
            if self._indices is None and other._indices is None:
                new_indices = None
            else:
                base_other = len(self)
                self_idxs = LazyRange(0, len(self))
                other_idxs = LazyIndices(other._get_lazy_indices(), offset=base_other)
                new_indices = self_idxs + other_idxs
            return self.__class__(
                datasets=[self] + other._datasets, indices=new_indices
            )
        else:
            assert False, "should never get here"
Concatenation operation.

        :param other: other dataset.
        :return:
        
avalanche/benchmarks/utils/flat_data.py