Skip to content

Commit

Permalink
0.535
Browse files Browse the repository at this point in the history
  • Loading branch information
sizhky committed Jun 20, 2024
1 parent 83dfd23 commit 21f7126
Show file tree
Hide file tree
Showing 8 changed files with 225 additions and 228 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Changelog
#### 0.535
🐞 `AD` hotfix

#### 0.534
🎉 `store_scrap` is a new way to store on disk and show jupyter cell outputs in other notebooks.
Best for presenting complex analyses without worrying about running time-consuming notebooks
Expand Down
13 changes: 9 additions & 4 deletions nbs/markups.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"def _default(self, obj):\n",
" import numpy as np\n",
" from datetime import datetime, date\n",
"\n",
" if isinstance(obj, P):\n",
" return str(obj)\n",
" if isinstance(obj, (AD, AD2)):\n",
Expand All @@ -96,6 +97,7 @@
" return list(obj)\n",
" try:\n",
" import torch\n",
"\n",
" if isinstance(obj, torch.Tensor):\n",
" obj = obj.cpu().detach().numpy()\n",
" except:\n",
Expand All @@ -107,7 +109,6 @@
" return getattr(obj.__class__, \"__json__\", _default.default)(obj)\n",
"\n",
"\n",
"\n",
"_default.default = JSONEncoder().default\n",
"JSONEncoder.default = _default\n",
"\n",
Expand Down Expand Up @@ -215,8 +216,8 @@
" else:\n",
" return AttrDict(value) if isinstance(value, dict) else value\n",
"\n",
" __getitem__ = (\n",
" lambda self, x: AttrDict({_x: self[_x] for _x in x})\n",
" __getitem__ = lambda self, x: (\n",
" AttrDict({_x: self[_x] for _x in x})\n",
" if isinstance(x, (list, L))\n",
" else getattr(self, str(x))\n",
" )\n",
Expand Down Expand Up @@ -324,7 +325,8 @@
"\n",
" def summary(self, current_path=\"\", depth=0, sep=\" \", max_items=10):\n",
" max_items = int(os.environ.get(\"AD_MAX_ITEMS\", max_items))\n",
" if max_items == -1: max_items = 1e3\n",
" if max_items == -1:\n",
" max_items = 1e3\n",
" sep = os.environ.get(\"AD_SEP\", sep)\n",
"\n",
" def format_path(path, key):\n",
Expand Down Expand Up @@ -365,6 +367,7 @@
" is_multiline = False\n",
" ogitem = item\n",
" if isinstance(item, (str, P)):\n",
" item = str(item)\n",
" is_multiline = \"\\n\" in item\n",
" _sep = (\n",
" \" ...\\n...\\n...\\n...\\n... \" if is_multiline else \".........\"\n",
Expand Down Expand Up @@ -422,6 +425,7 @@
"\n",
"AD = AttrDict\n",
"\n",
"\n",
"def decompose(i):\n",
" print(\n",
" AD(\n",
Expand All @@ -430,6 +434,7 @@
" )\n",
" )\n",
"\n",
"\n",
"def pretty_json(\n",
" i, fpath=None, indent=4, print_with_logger=True, return_as_string=False\n",
"):\n",
Expand Down
417 changes: 200 additions & 217 deletions scripts.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ author = Yeshwanth Reddy
author_email = 1992chinna@gmail.com
copyright = sizhky
branch = master
version = 0.534
version = 0.535
min_python = 3.7
audience = Developers
language = English
Expand Down
2 changes: 1 addition & 1 deletion torch_snippets.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: torch_snippets
Version: 0.534
Version: 0.535
Summary: One line functions for common tasks
Home-page: https://github.com/sizhky/torch_snippets/tree/master/
Author: Yeshwanth Reddy
Expand Down
2 changes: 1 addition & 1 deletion torch_snippets/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.534"
__version__ = "0.535"
from .loader import *
from .paths import *
from .markup import *
Expand Down
13 changes: 9 additions & 4 deletions torch_snippets/markup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
def _default(self, obj):
import numpy as np
from datetime import datetime, date

if isinstance(obj, P):
return str(obj)
if isinstance(obj, (AD, AD2)):
Expand All @@ -30,6 +31,7 @@ def _default(self, obj):
return list(obj)
try:
import torch

if isinstance(obj, torch.Tensor):
obj = obj.cpu().detach().numpy()
except:
Expand All @@ -41,7 +43,6 @@ def _default(self, obj):
return getattr(obj.__class__, "__json__", _default.default)(obj)



_default.default = JSONEncoder().default
JSONEncoder.default = _default

Expand Down Expand Up @@ -149,8 +150,8 @@ def _wrap(self, value):
else:
return AttrDict(value) if isinstance(value, dict) else value

__getitem__ = (
lambda self, x: AttrDict({_x: self[_x] for _x in x})
__getitem__ = lambda self, x: (
AttrDict({_x: self[_x] for _x in x})
if isinstance(x, (list, L))
else getattr(self, str(x))
)
Expand Down Expand Up @@ -258,7 +259,8 @@ def find_address(self, key, current_path=""):

def summary(self, current_path="", depth=0, sep=" ", max_items=10):
max_items = int(os.environ.get("AD_MAX_ITEMS", max_items))
if max_items == -1: max_items = 1e3
if max_items == -1:
max_items = 1e3
sep = os.environ.get("AD_SEP", sep)

def format_path(path, key):
Expand Down Expand Up @@ -299,6 +301,7 @@ class Torch:
is_multiline = False
ogitem = item
if isinstance(item, (str, P)):
item = str(item)
is_multiline = "\n" in item
_sep = (
" ...\n...\n...\n...\n... " if is_multiline else "........."
Expand Down Expand Up @@ -356,6 +359,7 @@ def fetch(self, addr):

AD = AttrDict


def decompose(i):
print(
AD(
Expand All @@ -364,6 +368,7 @@ def decompose(i):
)
)


def pretty_json(
i, fpath=None, indent=4, print_with_logger=True, return_as_string=False
):
Expand Down
1 change: 1 addition & 0 deletions torch_snippets/markup2.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ class Torch:
is_multiline = False
ogitem = item
if isinstance(item, (str, P)):
item = str(item)
is_multiline = "\n" in item
_sep = (
" ...\n...\n...\n...\n... " if is_multiline else "........."
Expand Down

0 comments on commit 21f7126

Please sign in to comment.