tools module
Full Documentation for hippynn.tools
module.
Click here for a summary page.
Misc. helpful functions which are not part of the library organization per se.
- active_directory(dirname, create=None)[source]
Context manager for temporarily switching the current working directory.
If create is None, always succeed. If create is True, only succeed if the directory does not exist, and create one. If create is False, only succeed if the directory does exist, and switch to it.
In other words, use create=True if you want to force that it’s a new directory. Use create=False if you want to switch to an existing directory. Use create=None create a directory if you are okay with either alternative.
- Parameters:
dirname – directory to enter
create – (None,True,False)
- Returns:
None
- Raises:
If directory status not compatible with create constraints.
- arrdict_len(array_dictionary)[source]
Return the length of one of the arrays in a dictionary. Under the assumption that they are all the same. :param array_dictionary: :return:
- is_equal_state_dict(d1, d2, raise_where=False)[source]
Checks if two pytorch state dictionaries are equal. Calls itself recursively if the value for a parameter is a dictionary.
- Parameters:
d1
d2
raise_where – if not equal, use an assertion to fail.
- Returns:
- log_terminal(file, *args, **kwargs)[source]
- Param:
file: filename or string
- Param:
args: piped to
open(file,*args,**kwargs)
if file is a string- Param:
kwargs: piped to
open(file,*args,**kwargs)
if file is a string
Context manager where stdout and stderr are redirected to the specified file in addition to the usual stdout and stderr. The manager yields the file. Writes to the opened file object with “with log_terminal(…) as <file>” will not automatically be piped into the terminal.