Skip to content

Commit b82d56a

Browse files
committed
sort_by_run
1 parent cba246d commit b82d56a

File tree

5 files changed

+36
-4
lines changed

5 files changed

+36
-4
lines changed

fastcore/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.3.14"
1+
__version__ = "1.3.15"

fastcore/_nbdev.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@
176176
"modified_env": "03_xtras.ipynb",
177177
"ContextManagers": "03_xtras.ipynb",
178178
"str2bool": "03_xtras.ipynb",
179+
"sort_by_run": "03_xtras.ipynb",
179180
"threaded": "03a_parallel.ipynb",
180181
"startthread": "03a_parallel.ipynb",
181182
"set_num_threads": "03a_parallel.ipynb",

fastcore/xtras.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
'maybe_open', 'image_size', 'bunzip', 'join_path_file', 'loads', 'loads_multi', 'untar_dir', 'repo_details',
55
'run', 'open_file', 'save_pickle', 'load_pickle', 'truncstr', 'spark_chars', 'sparkline', 'autostart',
66
'EventTimer', 'stringfmt_names', 'PartialFormatter', 'partial_format', 'utc2local', 'local2utc', 'trace',
7-
'round_multiple', 'modified_env', 'ContextManagers', 'str2bool']
7+
'round_multiple', 'modified_env', 'ContextManagers', 'str2bool', 'sort_by_run']
88

99
# Cell
1010
from .imports import *
@@ -368,4 +368,16 @@ def __exit__(self, *args, **kwargs): self.stack.__exit__(*args, **kwargs)
368368
def str2bool(s):
369369
"Case-insensitive convert string `s` too a bool (`y`,`yes`,`t`,`true`,`on`,`1`->`True`)"
370370
if not isinstance(s,str): return bool(s)
371-
return bool(distutils.util.strtobool(s)) if s else False
371+
return bool(distutils.util.strtobool(s)) if s else False
372+
373+
# Cell
374+
def sort_by_run(fs):
375+
end = L(fs).attrgot('toward_end')
376+
inp,res = L(fs)[~end] + L(fs)[end], L()
377+
while len(inp):
378+
for i,o in enumerate(inp):
379+
if _is_first(o, inp):
380+
res.append(inp.pop(i))
381+
break
382+
else: raise Exception("Impossible to sort")
383+
return res

nbs/03_xtras.ipynb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,6 +1876,25 @@
18761876
"for o in 1,True: assert str2bool(o)"
18771877
]
18781878
},
1879+
{
1880+
"cell_type": "code",
1881+
"execution_count": null,
1882+
"metadata": {},
1883+
"outputs": [],
1884+
"source": [
1885+
"#export\n",
1886+
"def sort_by_run(fs):\n",
1887+
" end = L(fs).attrgot('toward_end')\n",
1888+
" inp,res = L(fs)[~end] + L(fs)[end], L()\n",
1889+
" while len(inp):\n",
1890+
" for i,o in enumerate(inp):\n",
1891+
" if _is_first(o, inp):\n",
1892+
" res.append(inp.pop(i))\n",
1893+
" break\n",
1894+
" else: raise Exception(\"Impossible to sort\")\n",
1895+
" return res"
1896+
]
1897+
},
18791898
{
18801899
"cell_type": "markdown",
18811900
"metadata": {},

settings.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ author = Jeremy Howard and Sylvain Gugger
77
author_email = [email protected]
88
copyright = fast.ai
99
branch = master
10-
version = 1.3.14
10+
version = 1.3.15
1111
min_python = 3.6
1212
audience = Developers
1313
language = English

0 commit comments

Comments
 (0)