Skip to content

Commit

Permalink
Missing files
Browse files Browse the repository at this point in the history
Signed-off-by: Alexey Kudinkin <ak@anyscale.com>
  • Loading branch information
alexeykudinkin committed Sep 16, 2024
1 parent 0c77896 commit 583d244
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions python/ray/_private/collections.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from typing import List, Any


def split(items: List[Any], chunk_size: int):
"""Splits provided list into chunks of given size"""

assert chunk_size > 0, "Chunk size has to be > 0"

for i in range(0, len(items), chunk_size):
yield items[i : i + chunk_size]
18 changes: 18 additions & 0 deletions python/ray/tests/test_collections.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import sys

import pytest

from ray._private.collections import split


def test_split():
ints = list(range(0, 5))

assert list(split(ints, 5)) == [ints]
assert list(split(ints, 10)) == [ints]
assert list(split(ints, 1)) == [[e] for e in ints]
assert list(split(ints, 2)) == [[0, 1], [2, 3], [4]]


if __name__ == "__main__":
sys.exit(pytest.main(["-v", __file__]))

0 comments on commit 583d244

Please sign in to comment.