chromadol.util¶
Utils for chromadol.
Functions
|
Add to collection if not already there. |
|
Extract the argument value from a function call, or the default if not given. |
|
The identity function. |
|
|
|
|
|
Return wrapped method that only subdicts it's outputs to only |
|
Get a |
|
Like builtin map, but returns a list, and if iterable is None, returns a partial function that can directly be applied to an iterable. |
|
return a subdict with only the given keys |
Wraps all methods that contain an |
Classes
|
Delegates all attributes to the wrapped object |
- class chromadol.util.Delegator(wrapped_obj)[source]¶
Bases:
objectDelegates all attributes to the wrapped object
- chromadol.util.add_if_missing(collection, ids, embeddings=None, metadatas=None, documents=None, images=None, uris=None)[source]¶
Add to collection if not already there.
- chromadol.util.argument_value(argname, func, args, kwargs)[source]¶
Extract the argument value from a function call, or the default if not given.
Note that this
>>> func = lambda x, y, z=42: None >>> argument_value('z', func, [1, 2], {}) # z not given, so use default 42 >>> argument_value('z', func, [1, 2], {'z': 4}) # z given, so use that 4 >>> argument_value('z', func, [1, 2, 3], {}) # y given as positional, so use that 3
- chromadol.util.identity(x)[source]¶
The identity function. Returns what it is given.
- Return type:
TypeVar(T)
- chromadol.util.keep_only_include_keys(method)[source]¶
Return wrapped method that only subdicts it’s outputs to only
includekeys.
- chromadol.util.map_arguments(func, args, kwargs)[source]¶
Get a
{argname: argval, ...}dict from the args and kwargs of a function call.>>> func = lambda x, y, z=42: None >>> map_arguments(func, [1], {'y': 2}) # x as positional, y as keyword, z not given {'x': 1, 'y': 2, 'z': 42} >>> map_arguments(func, [1, 2], {'z': 4}) # z given, so use that {'x': 1, 'y': 2, 'z': 4} >>> map_arguments(func, [1, 2, 3], {}) # y given as positional, so use that {'x': 1, 'y': 2, 'z': 3}
- chromadol.util.mapped_list(func, iterable=None, *, max_workers=1)[source]¶
Like builtin map, but returns a list, and if iterable is None, returns a partial function that can directly be applied to an iterable. This is useful, for instance, for making a data loader from any single-uri loader.
Example
>>> mapped_list(lambda x: x**2, [1,2,3]) [1, 4, 9] >>> squares = mapped_list(lambda x: x**2) # iterable=None -> partial >>> squares([1,2,3]) [1, 4, 9]