Skip to content

Commit 7bc84d1

Browse files
author
Vincent Moens
committed
[Minor,Feature] Add prefix arg to timeit.todict
ghstack-source-id: f1ff685 Pull Request resolved: #2576
1 parent b875979 commit 7bc84d1

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

torchrl/_utils.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,15 @@ def print(prefix=None) -> str: # noqa: T202
117117
return "\n".join(string)
118118

119119
@classmethod
120-
def todict(cls, percall=True):
120+
def todict(cls, percall=True, prefix=None):
121+
def _make_key(key):
122+
if prefix:
123+
return f"{prefix}/{key}"
124+
return key
125+
121126
if percall:
122-
return {key: val[0] for key, val in cls._REG.items()}
123-
return {key: val[1] for key, val in cls._REG.items()}
127+
return {_make_key(key): val[0] for key, val in cls._REG.items()}
128+
return {_make_key(key): val[1] for key, val in cls._REG.items()}
124129

125130
@staticmethod
126131
def erase():

0 commit comments

Comments
 (0)