|
688 | 688 | {
|
689 | 689 | "data": {
|
690 | 690 | "text/plain": [
|
691 |
| - "'pip 23.3.1 from /Users/jhoward/miniconda3/lib/python3.11/site-packages/pip (python 3.11)'" |
| 691 | + "'pip 25.0.1 from /Users/drg/.venv/lib/python3.12/site-packages/pip (python 3.12)'" |
692 | 692 | ]
|
693 | 693 | },
|
694 | 694 | "execution_count": null,
|
|
1194 | 1194 | {
|
1195 | 1195 | "data": {
|
1196 | 1196 | "text/plain": [
|
1197 |
| - "Path('/Users/daniel.roy.greenfeld/fh/fastcore/fastcore')" |
| 1197 | + "Path('/Users/drg/git/fastcore/fastcore')" |
1198 | 1198 | ]
|
1199 | 1199 | },
|
1200 | 1200 | "execution_count": null,
|
|
1261 | 1261 | {
|
1262 | 1262 | "data": {
|
1263 | 1263 | "text/plain": [
|
1264 |
| - "Path('000_tour.ipynb')" |
| 1264 | + "Path('llms.txt')" |
1265 | 1265 | ]
|
1266 | 1266 | },
|
1267 | 1267 | "execution_count": null,
|
|
1440 | 1440 | "text/markdown": [
|
1441 | 1441 | "---\n",
|
1442 | 1442 | "\n",
|
1443 |
| - "[source](https://github.com/AnswerDotAI/fastcore/blob/master/fastcore/xtras.py#L389){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
| 1443 | + "[source](https://github.com/AnswerDotAI/fastcore/blob/main/fastcore/xtras.py#L391){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
1444 | 1444 | "\n",
|
1445 | 1445 | "#### ReindexCollection\n",
|
1446 | 1446 | "\n",
|
|
1451 | 1451 | "text/plain": [
|
1452 | 1452 | "---\n",
|
1453 | 1453 | "\n",
|
1454 |
| - "[source](https://github.com/AnswerDotAI/fastcore/blob/master/fastcore/xtras.py#L389){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
| 1454 | + "[source](https://github.com/AnswerDotAI/fastcore/blob/main/fastcore/xtras.py#L391){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
1455 | 1455 | "\n",
|
1456 | 1456 | "#### ReindexCollection\n",
|
1457 | 1457 | "\n",
|
|
1523 | 1523 | "text/markdown": [
|
1524 | 1524 | "---\n",
|
1525 | 1525 | "\n",
|
1526 |
| - "[source](https://github.com/AnswerDotAI/fastcore/blob/master/fastcore/xtras.py#L400){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
| 1526 | + "[source](https://github.com/AnswerDotAI/fastcore/blob/main/fastcore/xtras.py#L402){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
1527 | 1527 | "\n",
|
1528 | 1528 | "###### ReindexCollection.reindex\n",
|
1529 | 1529 | "\n",
|
|
1534 | 1534 | "text/plain": [
|
1535 | 1535 | "---\n",
|
1536 | 1536 | "\n",
|
1537 |
| - "[source](https://github.com/AnswerDotAI/fastcore/blob/master/fastcore/xtras.py#L400){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
| 1537 | + "[source](https://github.com/AnswerDotAI/fastcore/blob/main/fastcore/xtras.py#L402){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
1538 | 1538 | "\n",
|
1539 | 1539 | "###### ReindexCollection.reindex\n",
|
1540 | 1540 | "\n",
|
|
1623 | 1623 | "text/markdown": [
|
1624 | 1624 | "---\n",
|
1625 | 1625 | "\n",
|
1626 |
| - "[source](https://github.com/AnswerDotAI/fastcore/blob/master/fastcore/xtras.py#L404){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
| 1626 | + "[source](https://github.com/AnswerDotAI/fastcore/blob/main/fastcore/xtras.py#L406){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
1627 | 1627 | "\n",
|
1628 | 1628 | "##### ReindexCollection.cache_clear\n",
|
1629 | 1629 | "\n",
|
|
1634 | 1634 | "text/plain": [
|
1635 | 1635 | "---\n",
|
1636 | 1636 | "\n",
|
1637 |
| - "[source](https://github.com/AnswerDotAI/fastcore/blob/master/fastcore/xtras.py#L404){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
| 1637 | + "[source](https://github.com/AnswerDotAI/fastcore/blob/main/fastcore/xtras.py#L406){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
1638 | 1638 | "\n",
|
1639 | 1639 | "##### ReindexCollection.cache_clear\n",
|
1640 | 1640 | "\n",
|
|
1688 | 1688 | "text/markdown": [
|
1689 | 1689 | "---\n",
|
1690 | 1690 | "\n",
|
1691 |
| - "[source](https://github.com/AnswerDotAI/fastcore/blob/master/fastcore/xtras.py#L401){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
| 1691 | + "[source](https://github.com/AnswerDotAI/fastcore/blob/main/fastcore/xtras.py#L403){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
1692 | 1692 | "\n",
|
1693 | 1693 | "##### ReindexCollection.shuffle\n",
|
1694 | 1694 | "\n",
|
|
1699 | 1699 | "text/plain": [
|
1700 | 1700 | "---\n",
|
1701 | 1701 | "\n",
|
1702 |
| - "[source](https://github.com/AnswerDotAI/fastcore/blob/master/fastcore/xtras.py#L401){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
| 1702 | + "[source](https://github.com/AnswerDotAI/fastcore/blob/main/fastcore/xtras.py#L403){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
1703 | 1703 | "\n",
|
1704 | 1704 | "##### ReindexCollection.shuffle\n",
|
1705 | 1705 | "\n",
|
|
1732 | 1732 | {
|
1733 | 1733 | "data": {
|
1734 | 1734 | "text/plain": [
|
1735 |
| - "['a', 'd', 'h', 'c', 'e', 'b', 'f', 'g']" |
| 1735 | + "['a', 'd', 'g', 'f', 'h', 'e', 'b', 'c']" |
1736 | 1736 | ]
|
1737 | 1737 | },
|
1738 | 1738 | "execution_count": null,
|
|
1988 | 1988 | {
|
1989 | 1989 | "data": {
|
1990 | 1990 | "text/plain": [
|
1991 |
| - "'https://github.com/fastai/fastcore/tree/master/fastcore/test.py#L35'" |
| 1991 | + "'https://github.com/fastai/fastcore/tree/master/fastcore/test.py#L37'" |
1992 | 1992 | ]
|
1993 | 1993 | },
|
1994 | 1994 | "execution_count": null,
|
|
2291 | 2291 | "text/markdown": [
|
2292 | 2292 | "---\n",
|
2293 | 2293 | "\n",
|
2294 |
| - "[source](https://github.com/AnswerDotAI/fastcore/blob/master/fastcore/xtras.py#L530){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
| 2294 | + "[source](https://github.com/AnswerDotAI/fastcore/blob/main/fastcore/xtras.py#L534){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
2295 | 2295 | "\n",
|
2296 | 2296 | "#### EventTimer\n",
|
2297 | 2297 | "\n",
|
|
2302 | 2302 | "text/plain": [
|
2303 | 2303 | "---\n",
|
2304 | 2304 | "\n",
|
2305 |
| - "[source](https://github.com/AnswerDotAI/fastcore/blob/master/fastcore/xtras.py#L530){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
| 2305 | + "[source](https://github.com/AnswerDotAI/fastcore/blob/main/fastcore/xtras.py#L534){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
2306 | 2306 | "\n",
|
2307 | 2307 | "#### EventTimer\n",
|
2308 | 2308 | "\n",
|
|
2336 | 2336 | "name": "stdout",
|
2337 | 2337 | "output_type": "stream",
|
2338 | 2338 | "text": [
|
2339 |
| - "Num Events: 3, Freq/sec: 205.6\n", |
2340 |
| - "Most recent: ▁▁▃▁▇ 254.1 263.2 284.5 259.9 315.7\n" |
| 2339 | + "Num Events: 1, Freq/sec: 155.1\n", |
| 2340 | + "Most recent: ▇▂▂▁▁ 386.7 269.9 285.5 249.6 220.0\n" |
2341 | 2341 | ]
|
2342 | 2342 | }
|
2343 | 2343 | ],
|
|
2416 | 2416 | "text/markdown": [
|
2417 | 2417 | "---\n",
|
2418 | 2418 | "\n",
|
2419 |
| - "[source](https://github.com/AnswerDotAI/fastcore/blob/master/fastcore/xtras.py#L562){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
| 2419 | + "[source](https://github.com/AnswerDotAI/fastcore/blob/main/fastcore/xtras.py#L566){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
2420 | 2420 | "\n",
|
2421 | 2421 | "#### PartialFormatter\n",
|
2422 | 2422 | "\n",
|
|
2427 | 2427 | "text/plain": [
|
2428 | 2428 | "---\n",
|
2429 | 2429 | "\n",
|
2430 |
| - "[source](https://github.com/AnswerDotAI/fastcore/blob/master/fastcore/xtras.py#L562){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
| 2430 | + "[source](https://github.com/AnswerDotAI/fastcore/blob/main/fastcore/xtras.py#L566){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
2431 | 2431 | "\n",
|
2432 | 2432 | "#### PartialFormatter\n",
|
2433 | 2433 | "\n",
|
|
2499 | 2499 | "name": "stdout",
|
2500 | 2500 | "output_type": "stream",
|
2501 | 2501 | "text": [
|
2502 |
| - "2000-01-01 12:00:00 UTC is 2000-01-01 22:00:00+10:00 local time\n" |
| 2502 | + "2000-01-01 12:00:00 UTC is 2000-01-01 20:00:00+08:00 local time\n" |
2503 | 2503 | ]
|
2504 | 2504 | }
|
2505 | 2505 | ],
|
|
2529 | 2529 | "name": "stdout",
|
2530 | 2530 | "output_type": "stream",
|
2531 | 2531 | "text": [
|
2532 |
| - "2000-01-01 12:00:00 local is 2000-01-01 02:00:00+00:00 UTC time\n" |
| 2532 | + "2000-01-01 12:00:00 local is 2000-01-01 04:00:00+00:00 UTC time\n" |
2533 | 2533 | ]
|
2534 | 2534 | }
|
2535 | 2535 | ],
|
|
2632 | 2632 | "text/markdown": [
|
2633 | 2633 | "---\n",
|
2634 | 2634 | "\n",
|
2635 |
| - "[source](https://github.com/AnswerDotAI/fastcore/blob/master/fastcore/xtras.py#L619){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
| 2635 | + "[source](https://github.com/AnswerDotAI/fastcore/blob/main/fastcore/xtras.py#L623){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
2636 | 2636 | "\n",
|
2637 | 2637 | "#### ContextManagers\n",
|
2638 | 2638 | "\n",
|
|
2643 | 2643 | "text/plain": [
|
2644 | 2644 | "---\n",
|
2645 | 2645 | "\n",
|
2646 |
| - "[source](https://github.com/AnswerDotAI/fastcore/blob/master/fastcore/xtras.py#L619){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
| 2646 | + "[source](https://github.com/AnswerDotAI/fastcore/blob/main/fastcore/xtras.py#L623){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
2647 | 2647 | "\n",
|
2648 | 2648 | "#### ContextManagers\n",
|
2649 | 2649 | "\n",
|
|
3172 | 3172 | "def flexicache(*funcs, maxsize=128):\n",
|
3173 | 3173 | " \"Like `lru_cache`, but customisable with policy `funcs`\"\n",
|
3174 | 3174 | " import asyncio\n",
|
| 3175 | + " from collections import OrderedDict\n", |
3175 | 3176 | " def _f(func):\n",
|
3176 |
| - " cache,states = {}, [None]*len(funcs)\n", |
| 3177 | + " cache,states = OrderedDict(), [None]*len(funcs)\n", |
3177 | 3178 | " def _cache_logic(key, execute_func):\n",
|
3178 | 3179 | " if key in cache:\n",
|
3179 | 3180 | " result,states = cache[key]\n",
|
|
3187 | 3188 | " cache[key] = cache.pop(key)\n",
|
3188 | 3189 | " return result\n",
|
3189 | 3190 | " cache[key] = (newres, [f(None) for f in funcs])\n",
|
3190 |
| - " if len(cache) > maxsize: cache.popitem()\n", |
| 3191 | + " if len(cache) > maxsize: cache.popitem(last=False)\n", |
3191 | 3192 | " return newres\n",
|
3192 | 3193 | "\n",
|
3193 | 3194 | " @wraps(func)\n",
|
|
3298 | 3299 | " return flexicache(time_policy(seconds), maxsize=maxsize)"
|
3299 | 3300 | ]
|
3300 | 3301 | },
|
| 3302 | + { |
| 3303 | + "cell_type": "code", |
| 3304 | + "execution_count": null, |
| 3305 | + "metadata": {}, |
| 3306 | + "outputs": [], |
| 3307 | + "source": [ |
| 3308 | + "# demonstrate that flexicache is LRU\n", |
| 3309 | + "@flexicache(maxsize=2)\n", |
| 3310 | + "def cached_func(x): return time()\n", |
| 3311 | + "\n", |
| 3312 | + "time_1 = cached_func(1)\n", |
| 3313 | + "test_eq(time_1, cached_func(1))\n", |
| 3314 | + "\n", |
| 3315 | + "time_2 = cached_func(2)\n", |
| 3316 | + "test_eq(time_1, cached_func(1))\n", |
| 3317 | + "test_eq(time_2, cached_func(2))\n", |
| 3318 | + "\n", |
| 3319 | + "time_3 = cached_func(3) # Removes 1\n", |
| 3320 | + "\n", |
| 3321 | + "test_eq(time_2, cached_func(2)) # cache remains\n", |
| 3322 | + "test_eq(time_3, cached_func(3)) # cache remains\n", |
| 3323 | + "test_ne(time_1, cached_func(1)) # NEQ, removes 2\n", |
| 3324 | + "test_ne(time_2, cached_func(2)) # NEQ, removes 3\n", |
| 3325 | + "test_eq(cached_func(1), cached_func(1))" |
| 3326 | + ] |
| 3327 | + }, |
3301 | 3328 | {
|
3302 | 3329 | "cell_type": "markdown",
|
3303 | 3330 | "metadata": {},
|
|
3355 | 3382 | "#|hide\n",
|
3356 | 3383 | "import nbdev; nbdev.nbdev_export()"
|
3357 | 3384 | ]
|
3358 |
| - }, |
3359 |
| - { |
3360 |
| - "cell_type": "code", |
3361 |
| - "execution_count": null, |
3362 |
| - "metadata": {}, |
3363 |
| - "outputs": [], |
3364 |
| - "source": [] |
3365 | 3385 | }
|
3366 | 3386 | ],
|
3367 | 3387 | "metadata": {
|
|
0 commit comments