Template Function sequant::apply_one_op

Function Documentation

template<meta::can_evaluate Node>
ResultPtr sequant::apply_one_op(Node const &node, ResultPtr const &left, ResultPtr const &right)

The single-op compute kernel.

The raw op applied to already-evaluated operand results, dispatched by node's op type, with the contraction annotation computed from node. Value-in, value-out: it takes the operands’ Result buffers and returns the op’s raw result, touching no cache and no value identity. It is exactly the innermost left->adjoint/sum/prod(...) compute that both the tree-walking evaluate_impl and the value/occurrence-driven ordered executor perform, so both reach the op through this one function. Not handled here (all caller-side): a leaf (a leaf_evaluator fetch, not an op), the shaped-product hook (the caller calls this only when the hook declines), apply_phase + store, the in-place-Sum fast path, and all tally / trace / timing / last_op_flops sentinel.

Note

The traversal is iterative: it maintains its own explicit work stack (a std::deque of frames) rather than recursing, so evaluation depth is bounded by the heap, not the C++ call stack. This keeps deep trees (e.g. a Sum or product chain with thousands of operands) stack-safe. Custom-evaluator interception is preserved exactly: it is consulted when a frame is first visited and a non-null result short-circuits the subtree (its children are never pushed), so subtree pruning &#8212; the mechanism batched eval relies on &#8212; is unaffected.

Template Parameters:
  • EvalTrace – If Trace::On, trace is written to the logger’s stream. Default is to follow Trace::Default, which is itself equal to Trace::On or Trace::Off.

  • Cache – If CacheCache::Checked (default) the root node is looked up in cache before evaluating; a hit short-circuits it. Child nodes are always evaluated Checked. Unchecked skips the lookup for the root only.

Parameters:
  • node – A node that can be evaluated using leaf_evaluator as the leaf evaluator.

  • leaf_evaluator – The leaf evaluator that satisfies meta::leaf_node_evaluator<Node, F>.

  • cache – The cache for common sub-expression elimination.

Returns:

Evaluated result as ResultPtr.