laplax.util.ops
Contains operations for flexible/adaptive compute.
str_to_bool ¶
Convert a string representation of a boolean to a boolean value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
str
|
A string representation of a boolean ("True" or "False"). |
required |
Returns:
Type | Description |
---|---|
bool
|
The corresponding boolean value. |
Raises:
Type | Description |
---|---|
ValueError
|
If the string does not represent a valid boolean value. |
Source code in laplax/util/ops.py
precompute_list ¶
precompute_list(func: Callable, items: Iterable, precompute: bool | None = None, **kwargs: Kwargs) -> Callable
Precompute results for a list of items or return the original function.
If option
is enabled, this function applies func
to all items in items
and stores the results for later retrieval. Otherwise, it returns func
as-is.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func
|
Callable
|
The function to apply to each item in the list. |
required |
items
|
Iterable
|
An iterable of items to process. |
required |
precompute
|
bool | None
|
Determines whether to precompute results: - None: Use the default precompute setting. - bool: Specify directly whether to precompute. |
None
|
**kwargs
|
Kwargs
|
Additional keyword arguments, including: - precompute_list_batch_size: Batch size for precomputing results. |
{}
|
Returns:
Type | Description |
---|---|
Callable
|
A function to retrieve precomputed elements by index, or the original
|