Utils
utils ¶
cache ¶
collections ¶
EventTarget ¶
MutableCollection ¶
Bases: EventTarget
MutableDict ¶
MutableList ¶
MutableSet ¶
flatten(data: Dict[str, Any], *, separator: str = '.', parent_key: Optional[str] = None) -> Dict[Union[str, Tuple[str]], Any] ¶
Flatten a nested dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data | Dict[str, Any] | The nested dictionary to flatten. | required |
separator | str | The separator, by default "." | '.' |
parent_key | Optional[str] | The parent key, by default None | None |
Returns:
| Type | Description |
|---|---|
Dict[str | tuple[str], Any] | The flattened dictionary. |
config ¶
T = TypeVar('T', bound=dataclass) module-attribute ¶
ConfigWrapper ¶
wrapped = wrapped instance-attribute ¶
signature = inspect.signature(wrapped) instance-attribute ¶
filter_keys = filter_keys instance-attribute ¶
name = name instance-attribute ¶
config = config instance-attribute ¶
__init__(wrapped, config: Config, name: Optional[str] = None) ¶
get_params(*args, **kwargs) ¶
__call__(*args, **kwargs) ¶
Config ¶
Bases: MutableMapping
omconf = config if isinstance(config, OmegaConf) else OmegaConf.structured(config) if is_dataclass(config) else OmegaConf.create(config) instance-attribute ¶
__new__(config: Union[Type[T], dict[str, Any]]) -> Union[T, Self] ¶
__new__(config: Type[T]) -> T
__new__(config: dict[str, Any]) -> Self
__init__(config: Any) -> None ¶
__getitem__(name: str) -> Any ¶
__setitem__(name: str, value: Any) -> None ¶
__delitem__(name: str) -> None ¶
__iter__() -> Any ¶
__len__() -> int ¶
__getattr__(name: str) -> Any ¶
wraps(wrapped: Union[type, callable, str, None] = None, **kwargs: Any) -> Union[ConfigWrapper, functools.partial] ¶
wraps(wrapped: Union[type, callable], **kwargs) -> ConfigWrapper
wraps(wrapped: Union[str, None], **kwargs) -> functools.partial
load(path: str) -> Self classmethod ¶
from_dotlist(dotlist: str) -> Self classmethod ¶
from_cli(args: list[str]) -> Self classmethod ¶
configmethod(func: T) -> T ¶
escape ¶
ESCAPED_CHARS = '\\\\`*_{}[]()#+\\-.!' module-attribute ¶
ESCAPED_CHARS_RE = re.compile(f'([{re.escape(ESCAPED_CHARS)}])') module-attribute ¶
UNESCAPED_CHARS_RE = re.compile(f'\\([{re.escape(ESCAPED_CHARS)}])') module-attribute ¶
escape(text: str) -> str ¶
Escape text.
unescape(text: str) -> str ¶
Unescape text.
func ¶
P = ParamSpec('P') module-attribute ¶
T = TypeVar('T') module-attribute ¶
bind(__func: Callable[P, T], *args: P.args, **kwargs: P.kwargs) -> Union[functools.partial, Callable[..., T]] ¶
Bind arguments to a function and return a new function.
This function is similar to functools.partial but it allows to bind arguments by name and by position (converting positional arguments to keyword arguments when possible).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
__func | Callable | The function to bind arguments to. | required |
*args | args | Positional arguments to bind to the function. | () |
**kwargs | kwargs | Keyword arguments to bind to the function. | {} |
Returns:
| Type | Description |
|---|---|
partial or Callable | A new function with the arguments bound. |
hashing ¶
Fast cryptographic hash of Python objects, with a special case for fast hashing of numpy arrays.
Pickler = pickle._Pickler module-attribute ¶
T = TypeVar('T') module-attribute ¶
P = ParamSpec('P') module-attribute ¶
Hashable ¶
Bases: Protocol
A class that can be hashed.
Wrapped ¶
hash(*obj, coerce_mmap=False) ¶
Quick calculation of a hash to identify uniquely Python objects containing numpy arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj | The objects to hash | () | |
coerce_mmap | Make no difference between np.memmap and np.ndarray | False |