TensorEvaluator
TensorEvaluator
TensorEvaluator()An optimized evaluator for symbolic tensor expressions.
An optimized evaluator for symbolic tensor expressions.
This class provides efficient numerical evaluation of symbolic tensor expressions after optimization. It supports both real and complex-valued evaluations.
Create instances using the Tensor.evaluator() method rather than directly.
Examples
evaluator = my_tensor.evaluator(constants={}, funs={}, params=[x, y])
results = evaluator.evaluate([[1.0, 2.0], [3.0, 4.0]])Methods
| Name | Description |
|---|---|
compile |
Compile the evaluator to a shared library using C++ for maximum performance |
evaluate |
Evaluate the tensor expression for multiple real-valued parameter inputs. |
evaluate_complex |
Evaluate the expression for multiple inputs and return the results. |
compile
TensorEvaluator.compile(
function_name: builtins.str,
filename: builtins.str,
library_name: builtins.str,
inline_asm: builtins.str = ...,
optimization_level: builtins.int = ...,
compiler_path: typing.Optional[builtins.str] = None,
custom_header: typing.Optional[builtins.str] = None,
) -> CompiledTensorEvaluatorCompile the evaluator to a shared library using C++ for maximum performance.
Compile the evaluator to a shared library using C++ for maximum performance.
Generates optimized C++ code with optional inline assembly and compiles it into a shared library that can be loaded for extremely fast evaluation.
Parameters
function_name(str) Name for the generated C++ functionfilename(str) Path for the generated C++ source filelibrary_name(str) Name for the compiled shared libraryinline_asm(str, optional) Type of inline assembly optimization (“default”, “x64”, “aarch64”, “none”)optimization_level(int, optional) Compiler optimization level 0-3 (default: 3)compiler_path(str, optional) Path to specific C++ compiler (default: system default)custom_header(str, optional) Additional C++ header code to include
Returns
CompiledTensorEvaluatorA compiled evaluator for maximum performance evaluation
Examples
compiled = evaluator.compile(
function_name="fast_eval",
filename="tensor_eval.cpp",
library_name="tensor_lib",
optimization_level=3,
)
results = compiled.evaluate_complex([[1.0, 2.0], [3.0, 4.0]])evaluate
TensorEvaluator.evaluate(inputs: typing.Sequence[typing.Sequence[builtins.float]]) -> builtins.list[Tensor]Evaluate the tensor expression for multiple real-valued parameter inputs.
Parameters
inputs(list of list of float) List of parameter value lists, where each inner list contains numerical values for all parameters in the same order as specified when creating the evaluator
Returns
list of TensorList of evaluated tensors, one for each input parameter set
Raises
ValueError: If the evaluator contains complex coefficients
Examples
results = evaluator.evaluate([[1.0, 2.0], [3.0, 4.0]])evaluate_complex
TensorEvaluator.evaluate_complex(inputs: typing.Sequence[typing.Sequence[builtins.complex]]) -> builtins.list[Tensor]Evaluate the expression for multiple inputs and return the results.