function#

import tensorwaves.function

Express mathematical expressions in terms of computational functions.

class PositionalArgumentFunction(function: Callable[[...], ndarray], argument_order: Iterable[str])[source]#

Bases: Function[Dict[str, ndarray], ndarray]

Wrapper around a function with positional arguments.

This class provides a __call__() that can take a DataSample for a function with positional arguments. Its argument_order redirect the keys in the DataSample to the argument positions in its underlying function.

function: Callable[[...], ndarray][source]#

A function with positional arguments only.

argument_order: tuple[str, ...][source]#

Ordered labels for each positional argument.

class ParametrizedBackendFunction(function: Callable[[...], ndarray], argument_order: Iterable[str], parameters: Mapping[str, ParameterValue])[source]#

Bases: ParametrizedFunction[Dict[str, ndarray], ndarray]

Implements ParametrizedFunction for a specific computational back-end.

property function: Callable[[...], ndarray][source]#
property argument_order: tuple[str, ...][source]#
property parameters: dict[str, ParameterValue][source]#

Get dict of parameters.

update_parameters(new_parameters: Mapping[str, ParameterValue]) None[source]#

Update the collection of parameters.

get_source_code(function: Function) str[source]#

Get the backend source code used to compile this function.

>>> import sympy as sp
>>> from tensorwaves.function.sympy import create_function
>>> x, y = sp.symbols("x y")
>>> expr = x**2 + y**2
>>> func = create_function(expr, backend="jax", use_cse=False)
>>> src = get_source_code(func)
>>> print(src)
def _lambdifygenerated(x, y):
    return x**2 + y**2

Submodules and Subpackages