ai2_kit.core.util module#
- class ai2_kit.core.util.JoinTag[source]#
Bases:
object
a tag to join strings in a list
- yaml_tag = '!join'#
- class ai2_kit.core.util.LoadTextTag[source]#
Bases:
object
a tag to read string from file
- yaml_tag = '!load_text'#
- class ai2_kit.core.util.LoadYamlTag[source]#
Bases:
object
a tag to read string from file
- yaml_tag = '!load_yaml'#
- ai2_kit.core.util.dict_nested_get(d: dict, keys: ~typing.List[str], default=<object object>)#
get value from nested dict
- ai2_kit.core.util.dict_nested_set(d: dict, keys: List[str], value)#
set value to nested dict
- ai2_kit.core.util.dump_json(obj, path: str)#
- ai2_kit.core.util.dump_text(text: str, path: str, **kwargs)#
- ai2_kit.core.util.ensure_dir(path: str)#
- ai2_kit.core.util.expand_globs(patterns: Iterable[str], raise_invalid=False) List[str] #
Expand glob patterns in paths
- Parameters:
patterns – list of paths or glob patterns
raise_invalid – if True, will raise error if no file found for a glob pattern
- Returns:
list of expanded paths
- ai2_kit.core.util.flat_evenly(list_of_lists)#
flat a list of lists and ensure the output result distributed evenly >>> flat_evenly([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) [1, 4, 7, 2, 5, 8, 3, 6, 9] Ref: https://stackoverflow.com/questions/76751171/how-to-flat-a-list-of-lists-and-ensure-the-output-result-distributed-evenly-in-p
- ai2_kit.core.util.flush_stdio()#
- ai2_kit.core.util.limit(it, size=- 1)#
limit the size of an iterable
- ai2_kit.core.util.list_even_sample(l, size)#
- ai2_kit.core.util.list_random_sample(l, size, seed=None)#
- ai2_kit.core.util.list_sample(l, size, method='even', **kwargs)#
- ai2_kit.core.util.load_yaml_files(*paths: Tuple[Path], quiet: bool = False, purge_anonymous=True)[source]#
- ai2_kit.core.util.merge_dict(lo: dict, ro: dict, path=None, ignore_none=True, quiet=False)#
Merge two dict, the left dict will be overridden. Note: list will be replaced instead of merged.
- ai2_kit.core.util.parse_path_list(path_list_str: Union[str, List[str]], to_abs: bool = False)[source]#
Parse path list of environment variable style string