On this page

TensorEvaluator

symbolica.community.spenso Class

TensorEvaluator()

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]])

Member details

evaluate

Method
#
evaluate(inputs: Sequence[Sequence[float]]) -> list[Tensor]

Evaluate the tensor expression for multiple real-valued parameter inputs.

Returns

list of Tensor

List 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]])

Parameters

NameTypeDefaultDescription
inputsSequence[Sequence[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

evaluate_complex

Method
#
evaluate_complex(inputs: Sequence[Sequence[complex]]) -> list[Tensor]

Evaluate the expression for multiple inputs and return the results.

Parameters

NameTypeDefaultDescription
inputsSequence[Sequence[complex]]

compile

Method
#
compile(function_name: str, filename: str, library_name: str, inline_asm: str = 'default', optimization_level: int = 3, compiler_path: Optional[str] = None, custom_header: Optional[str] = None) -> CompiledTensorEvaluator

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.

Returns

CompiledTensorEvaluator

A 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]])

Parameters

NameTypeDefaultDescription
function_namestr

Name for the generated C++ function

filenamestr

Path for the generated C++ source file

library_namestr

Name for the compiled shared library

inline_asmstr'default'

Type of inline assembly optimization ("default", "x64", "aarch64", "none")

optimization_levelint3

Compiler optimization level 0-3 (default: 3)

compiler_pathOptional[str]None

Path to specific C++ compiler (default: system default)

custom_headerOptional[str]None

Additional C++ header code to include