torch.tx.pipePatterns
function pipePatterns(...patterns: string[]): <T extends Record<string, TensorOrNumber>>(tensors: T) => AnyTensorPipe multiple patterns together.
Each pattern's result becomes the _ input for the next pattern.
This creates a pipeline of transformations, similar to function composition.
Parameters
patternsstring[]- Patterns to pipe together (first is innermost)
Returns
<T extends Record<string, TensorOrNumber>>(tensors: T) => AnyTensor– A function that evaluates the piped expressionExamples
// Build a two-layer MLP: sigmoid(relu(x @ w1 + b1) @ w2 + b2)
const mlp = $.pipe(
'x @ w1 + b1', // First linear layer
'relu(_)', // ReLU activation
'_ @ w2 + b2', // Second linear layer
'sigmoid(_)' // Output activation
);
const output = mlp({ x, w1, b1, w2, b2 });