Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/spdl/source/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import random
import sys
import time
from collections.abc import Iterable, Iterator, Sequence
from collections.abc import Iterable, Iterator, Sequence, Sized
from typing import TypeVar

from ._type import IterableWithShuffle
Expand Down Expand Up @@ -220,6 +220,14 @@ def __iter__(self) -> Iterator[T]:
if self._shuffle_last:
self._shuffle()

def __len__(self) -> int:
if isinstance(self.src, Sized):
return len(self.src)
else:
raise TypeError(
f"Source iterator of type {type(self.src)} does not support length"
)


def embed_shuffle(
src: IterableWithShuffle[T], /, *, shuffle_last: bool = False, epoch: int = 0
Expand Down
Loading