leaspy.utils.functional ======================= .. py:module:: leaspy.utils.functional Attributes ---------- .. autoapisummary:: leaspy.utils.functional.Exp leaspy.utils.functional.Identity leaspy.utils.functional.MatMul leaspy.utils.functional.Mean leaspy.utils.functional.OrthoBasis leaspy.utils.functional.Prod leaspy.utils.functional.Sqr leaspy.utils.functional.Std leaspy.utils.functional.Sum leaspy.utils.functional.SumDim Classes ------- .. autoapisummary:: leaspy.utils.functional.NamedInputFunction Functions --------- .. autoapisummary:: leaspy.utils.functional.get_named_parameters Package Contents ---------------- .. py:data:: Exp .. py:data:: Identity .. py:data:: MatMul .. py:data:: Mean .. py:data:: OrthoBasis .. py:data:: Prod .. py:data:: Sqr .. py:data:: Std .. py:data:: Sum .. py:data:: SumDim .. py:class:: NamedInputFunction Bases: :py:obj:`Generic`\ [\ :py:obj:`RT`\ ] Bridge from a function with positional parameters to a function with keyword-only parameters. :Attributes: **f** : :obj:`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** : :obj:`tuple` [:obj:`str`, ...] Assigned names, in order, for positional parameters of `f`. **kws** : None (default) or :class:`~leaspy.utils.typing.KwargsType` Some optional fixed keyword parameters to pass upon function calls. .. rubric:: 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. .. !! processed by numpydoc !! .. py:attribute:: f :type: Callable[Ellipsis, RT] .. py:attribute:: parameters :type: Tuple[str, Ellipsis] .. py:attribute:: kws :type: Optional[leaspy.utils.typing.KwargsType] :value: None .. py:method:: call(named_params) Call the underlying function with the correct positional arguments, retrieved by parameter names in input variables. :Parameters: **named_params** : :obj:`TMapping` [:obj:`str`, :obj:`Any`] A mapping of parameter names to their values. :Returns: :obj:`RT` The result of calling the function `f` with the provided named parameters. .. !! processed by numpydoc !! .. py:method:: then(g, **g_kws) Return a new NamedInputFunction applying (g o f) function. :Parameters: **g** : :obj:`Callable` [:obj:`RT`, :obj:`S`] A function to apply after the original function `f`. .. !! processed by numpydoc !! .. py:method:: bound_to(f, check_arguments = None) :staticmethod: Return a new factory to create new `NamedInputFunction` instances that are bound to the provided function. :Parameters: **f** : :obj:`Callable` [:obj:`RT`] The function to which the new `NamedInputFunction` will be bound. **check_arguments** : :obj:`Callable` [:obj:`tuple` [:obj:`str`, ...], :obj:`~leaspy.utils.typing.KwargsType`], optional An optional function to check the provided parameters and keyword arguments before creating the `NamedInputFunction`. .. !! processed by numpydoc !! .. py:function:: 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** : :obj:`Callable` The function from which to extract parameter names. :Returns: :obj:`tuple` [:obj:`str`, ...] A tuple containing the names of the parameters of the function `f`. :Raises: :obj:`ValueError` If the function `f` has positional parameters or if it has keyword-only parameters that are not allowed by the `NamedInputFunction` interface. .. !! processed by numpydoc !!