leaspy.utils.functional

Attributes

Exp

Identity

MatMul

Mean

OrthoBasis

Prod

Sqr

Std

Sum

SumDim

Classes

NamedInputFunction

Bridge from a function with positional parameters to a function with keyword-only parameters.

Functions

get_named_parameters(f)

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

Bases: Generic[RT]

Bridge from a function with positional parameters to a function with keyword-only parameters.

Parameters:
fCallable

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.

parameterstuple[str, …]

Assigned names, in order, for positional parameters of f.

kwsNone (default) or dictionary[str, Any]

Some optional fixed keyword parameters to pass upon function calls.

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]
parameters: Tuple[str, Ellipsis]
kws: leaspy.utils.typing.KwargsType | None = None
call(named_params)

Call the underlying function with the correct positional arguments, retrieved by parameter names in input variables.

Parameters:

named_params (Mapping[str, Any])

Return type:

RT

then(g, **g_kws)

Return a new NamedInputFunction applying (g o f) function.

Parameters:

g (Callable[[RT], S])

static bound_to(f, check_arguments=None)

Return a new factory to create new NamedInputFunction instances that are bound to the provided function.

Parameters:
  • f (Callable[Ellipsis, RT])

  • check_arguments (Optional[Callable[[Tuple[str, Ellipsis], leaspy.utils.typing.KwargsType], None]])

get_named_parameters(f)

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)

Return type:

Tuple[str, Ellipsis]