ml.utils.containers

Helper functions for applying functions to containers.

ml.utils.containers.recursive_apply(item: Any, func: Callable[[Tensor], Tensor]) Any[source]

Applies a function recursively to tensors in an item.

Parameters:
  • item – The item to apply the function to

  • func – The function to apply (for the tensor)

Returns:

The same item, with the function applied

ml.utils.containers.recursive_chunk(item: Any, num_chunks: int, dim: int = 0) Iterable[Any][source]

Recursively chunk tensors N times.

Parameters:
  • item – The item to recursively chunk

  • num_chunks – The number of splits to make

  • dim – The split dimension

Yields:

N chunks of items