TensorFunctionLibrary
Symbolica documentation for getting started, symbolic expressions, numerical evaluation, pattern matching, and APIs in Python and Rust.
TensorFunctionLibrary
class TensorFunctionLibraryNumerical implementations of unary elementwise tensor functions.
Use with network execution to evaluate BroadcastFunction calls on numeric components. Complex conjugation is included by default. Symbolic function calls whose arguments are not numeric can remain symbolic.
Examples
from symbolica.community.tensor import TensorFunctionLibrary, BroadcastFunction
functions = TensorFunctionLibrary()
functions.register(BroadcastFunction("square"), lambda x: x * x)Methods
| Name | Description |
|---|---|
__new__ |
Create a numerical function library with built-in conjugation. |
__repr__ |
Return a summary of the registered elementwise tensor functions. |
register |
Register a numerical implementation for an elementwise function. |
__new__
TensorFunctionLibrary.__new__() -> TensorFunctionLibraryCreate a numerical function library with built-in conjugation.
Returns
TensorFunctionLibraryMutable library for BroadcastFunction implementations.
Examples
from symbolica.community.tensor import TensorFunctionLibrary
functions = TensorFunctionLibrary()__repr__
TensorFunctionLibrary.__repr__() -> builtins.strReturn a summary of the registered elementwise tensor functions.
Examples
from symbolica.community import tensor as sp
functions = sp.TensorFunctionLibrary()
text = repr(functions)register
TensorFunctionLibrary.register(
function: BroadcastFunction,
callback: typing.Callable[[float | complex], float | complex],
) -> NoneRegister a numerical implementation for an elementwise function.
Parameters
function(BroadcastFunction) Function to implement; an existing implementation is replaced.callback(callable) Receives one float or complex value and returns a float or complex value. Results determine the numerical output type.
Returns
NoneUpdates this function library.
Examples
from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import TensorFunctionLibrary, BroadcastFunction
square = BroadcastFunction("numeric_square")
functions = TensorFunctionLibrary()
functions.register(square, lambda value: value * value)
square(tensor).to_tensor(function_library=functions)[0, 1]
4.0