Skip to content

Commit 009f4b8

Browse files
authored
Merge pull request #742 from AnswerDotAI/fix-duplicate-chunked
remove duplicate chunked func
2 parents 2c84c09 + 0eb84df commit 009f4b8

2 files changed

Lines changed: 1 addition & 31 deletions

File tree

fastcore/basics.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -245,17 +245,6 @@ def gen(func, seq, cond=ret_true):
245245
"Like `(func(o) for o in seq if cond(func(o)))` but handles `StopIteration`"
246246
return itertools.takewhile(cond, map(func,seq))
247247

248-
# %% ../nbs/01_basics.ipynb
249-
def chunked(it, chunk_sz=None, drop_last=False, n_chunks=None):
250-
"Return batches from iterator `it` of size `chunk_sz` (or return `n_chunks` total)"
251-
assert bool(chunk_sz) ^ bool(n_chunks)
252-
if n_chunks: chunk_sz = max(math.ceil(len(it)/n_chunks), 1)
253-
if not isinstance(it, Iterator): it = iter(it)
254-
while True:
255-
res = list(itertools.islice(it, chunk_sz))
256-
if res and (len(res)==chunk_sz or not drop_last): yield res
257-
if len(res)<chunk_sz: return
258-
259248
# %% ../nbs/01_basics.ipynb
260249
def chunked(it, chunk_sz=None, drop_last=False, n_chunks=None, pad=False, pad_val=None):
261250
"Return batches from iterator `it` of size `chunk_sz` (or return `n_chunks` total)"

nbs/01_basics.ipynb

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,26 +1476,7 @@
14761476
{
14771477
"cell_type": "code",
14781478
"execution_count": null,
1479-
"id": "67befaab",
1480-
"metadata": {},
1481-
"outputs": [],
1482-
"source": [
1483-
"#| export\n",
1484-
"def chunked(it, chunk_sz=None, drop_last=False, n_chunks=None):\n",
1485-
" \"Return batches from iterator `it` of size `chunk_sz` (or return `n_chunks` total)\"\n",
1486-
" assert bool(chunk_sz) ^ bool(n_chunks)\n",
1487-
" if n_chunks: chunk_sz = max(math.ceil(len(it)/n_chunks), 1)\n",
1488-
" if not isinstance(it, Iterator): it = iter(it)\n",
1489-
" while True:\n",
1490-
" res = list(itertools.islice(it, chunk_sz))\n",
1491-
" if res and (len(res)==chunk_sz or not drop_last): yield res\n",
1492-
" if len(res)<chunk_sz: return"
1493-
]
1494-
},
1495-
{
1496-
"cell_type": "code",
1497-
"execution_count": null,
1498-
"id": "fe7f167e",
1479+
"id": "a0bb26d6",
14991480
"metadata": {},
15001481
"outputs": [],
15011482
"source": [

0 commit comments

Comments
 (0)