apply_to_list#

pytorch_forecasting.utils.apply_to_list(obj: List[Any] | Any, func: Callable) List[Any] | Any[source]#

Apply function to a list of objects or directly if passed value is not a list.

This is useful if the passed object could be either a list to whose elements a function needs to be applied or just an object to whicht to apply the function.

Parameters:
  • obj (Union[List[Any], Any]) – list/tuple on whose elements to apply function, otherwise object to whom to apply function

  • func (Callable) – function to apply

Returns:

list of objects or object depending on function output and

if input obj is of type list/tuple

Return type:

Union[List[Any], Any]