nerva_numpy.utilities

Miscellaneous utilities (formatting, timing, parsing, I/O).

Functions

load_dict_from_npz(filename)

Loads a dictionary from a file in .npz format

parse_function_call(text)

Parse a string of the shape NAME(key1=value1, key2=value2, ...).

pp(name, x)

Pretty-print a tensor with name and shape info, using NumPy formatting.

pp_numpy(name, arr)

Internal helper: pretty-print using NumPy arrays only.

save_dict_to_npz(filename, data)

Saves a dictionary of NumPy arrays to a compressed .npz file.

set_numpy_options()

Configure NumPy print options for readable output.

Classes

FunctionCall(name, arguments)

StopWatch()

nerva_numpy.utilities.set_numpy_options()[source]

Configure NumPy print options for readable output.

nerva_numpy.utilities.pp_numpy(name: str, arr: numpy.ndarray)[source]

Internal helper: pretty-print using NumPy arrays only.

nerva_numpy.utilities.pp(name: str, x: numpy.ndarray)[source]

Pretty-print a tensor with name and shape info, using NumPy formatting.

class nerva_numpy.utilities.StopWatch[source]

Bases: object

seconds()[source]

Get elapsed time in seconds since creation or last reset.

reset()[source]

Reset the timer to the current time.

class nerva_numpy.utilities.FunctionCall(name: str, arguments: dict)[source]

Bases: object

has_key(key: str) bool[source]

Check if the given key exists in parsed arguments.

get_value(key: str) str[source]
as_scalar(key: str, default_value: float = None) float[source]
as_string(key: str, default_value: str = '') str[source]
nerva_numpy.utilities.parse_function_call(text: str) FunctionCall[source]

Parse a string of the shape NAME(key1=value1, key2=value2, …). If there are no arguments the parentheses may be omitted. If there is only one parameter, it is allowed to pass NAME(value) instead of NAME(key=value)

nerva_numpy.utilities.load_dict_from_npz(filename: str) Dict[str, numpy.ndarray][source]

Loads a dictionary from a file in .npz format

nerva_numpy.utilities.save_dict_to_npz(filename: str, data: Dict[str, numpy.ndarray])[source]

Saves a dictionary of NumPy arrays to a compressed .npz file.