malib.utils.general module

class malib.utils.general.BufferDict[source]

Bases: dict

property capacity: int
index(indices)[source]
index_func(x, indices)[source]
set_data(index, new_data)[source]
set_data_func(x, index, new_data)[source]
malib.utils.general.frozen_data(data)[source]
malib.utils.general.iter_dicts_recursively(d1, d2)[source]

Assuming dicts have the exact same structure.

malib.utils.general.iter_many_dicts_recursively(*d, history=None)[source]

Assuming dicts have the exact same structure, or raise KeyError.

malib.utils.general.iterate_recursively(d: Dict)[source]
malib.utils.general.tensor_cast(custom_caster: Optional[Callable] = None, callback: Optional[Callable] = None, dtype_mapping: Optional[Dict] = None, device='cpu')[source]

Casting the inputs of a method into tensors if needed.

Note:

This function does not support recursive iteration.

Args:

custom_caster (Callable, optional): Customized caster. Defaults to None. callback (Callable, optional): Callback function, accepts returns of wrapped function as inputs. Defaults to None. dtype_mapping (Dict, optional): Specify the data type for inputs which you wanna. Defaults to None.

Returns:

Callable: A decorator.

malib.utils.general.update_configs(update_dict, ori_dict=None)[source]

Update global configs with a given dict