leaspy.utils.functional¶
Attributes¶
Classes¶
Bridge from a function with positional parameters to a function with keyword-only parameters. |
Functions¶
Get the names of parameters of the input function f, which should be |
Package Contents¶
- Exp¶
- Identity¶
- MatMul¶
- Mean¶
- OrthoBasis¶
- Prod¶
- Sqr¶
- Std¶
- Sum¶
- SumDim¶
- class NamedInputFunction[source]¶
Bases:
Generic[RT]Bridge from a function with positional parameters to a function with keyword-only parameters.
- Attributes:
- f
Callable The original function. The named parameters to be sent in f should be: positional, positional-or-keyword, or variadic arguments. It can also have some keyword-only arguments, but they should be fixed once for all with attribute kws.
- parameters
tuple[str, …] Assigned names, in order, for positional parameters of f.
- kwsNone (default) or
KwargsType Some optional fixed keyword parameters to pass upon function calls.
- f
Notes
We do not implement the mapping of keyword-only to renamed keyword-only parameters for now since it is not needed and would make the logic more complex. Particularly due to the existence of positional-only parameters.
- f: Callable[Ellipsis, RT]¶
- kws: KwargsType | None = None¶
- call(named_params)[source]¶
Call the underlying function with the correct positional arguments, retrieved by parameter names in input variables.
- then(g, **g_kws)[source]¶
Return a new NamedInputFunction applying (g o f) function.
- Parameters:
- g
Callable[RT,S] A function to apply after the original function f.
- g
- Parameters:
g (Callable[[RT], S])
- static bound_to(f, check_arguments=None)[source]¶
Return a new factory to create new NamedInputFunction instances that are bound to the provided function.
- Parameters:
- f
Callable[RT] The function to which the new NamedInputFunction will be bound.
- check_arguments
Callable[tuple[str, …],KwargsType], optional An optional function to check the provided parameters and keyword arguments before creating the NamedInputFunction.
- f
- Parameters:
f (Callable[Ellipsis, RT])
check_arguments (Optional[Callable[[Tuple[str, Ellipsis], KwargsType], None]])
- get_named_parameters(f)[source]¶
Get the names of parameters of the input function f, which should be a NamedInputFunction or a function with keyword-only parameters.
- Parameters:
- f
Callable The function from which to extract parameter names.
- f
- Returns:
- Raises:
ValueErrorIf the function f has positional parameters or if it has keyword-only parameters that are not allowed by the NamedInputFunction interface.
- Parameters:
f (Callable)
- Return type:
Tuple[str, Ellipsis]