Module ai.utils
Module containing general utility methods, used throughout the library.
Expand source code
"""Module containing general utility methods, used throughout the library."""
from ._metronome import Metronome
from ._factory import Factory
from . import np, torch, logging, pylogging
__all__ = ["np", "torch", "logging", "Metronome", "pylogging", "Factory"]
Sub-modules
ai.utils.logging-
Logging utilities.
ai.utils.np-
Numpy specific utility methods.
ai.utils.pylogging-
Module for performing console logging. This module wraps the builtin
ai.utils.loggingmodule. ai.utils.torch-
Contains general PyTorch utility methods.
Classes
class Factory (cls: ~T, *args, **kwargs)-
Wraps a class into a factory object. When the object is called, an instance of the class is returned. Useful for when passing uninitialized objects between processes.
The implementation logic is essentially:
def factory(cls, *args, **kwargs): def generate(): return cls(*args, **kwargs) return generateArgs
cls:T- Class or function to be called using
argsandkwargs. Additional args and kwargs may be added when called.
Ancestors
- typing.Generic
class Metronome (period: float)-
Utility for executing at a certain frequency.
Args
period:float- Period (seconds) that this timer should help control.
Methods
def wait(self)-
Blocks until the specified period has passed since the last time this method returned.
Expand source code
def wait(self): """Blocks until the specified period has passed since the last time this method returned.""" if self._last_return is None: time.sleep(self._period) else: time.sleep(max(self._period - time.perf_counter() + self._last_return, 0)) self._last_return = time.perf_counter()