torch.tx.composePatterns
function composePatterns(pattern1: string, pattern2: string): <T extends Record<string, TensorOrNumber>>(tensors: T) => AnyTensorCompose two patterns together.
The _ placeholder in the second pattern is replaced with the first pattern.
This allows building complex expressions from simpler building blocks.
Parameters
pattern1string- The inner pattern (replaces
_in pattern2) pattern2string- The outer pattern (contains
_placeholder)
Returns
<T extends Record<string, TensorOrNumber>>(tensors: T) => AnyTensor– A function that evaluates the composed expressionExamples
const linear = $.compose('x @ w + b', 'relu(_)');
const result = linear({ x, w, b });
// Equivalent to: relu(x @ w + b)