torch.tx.LazyExpression
class LazyExpressionnew LazyExpression(pattern: string, ast: ASTNode, internalExpression: string, variables: string[], varToIndex: Map<string, number>, bindings: Record<string, TensorOrNumber> = {})
- readonly
pattern(string) - – The original pattern string
- readonly
variables(string[]) - – Variable names extracted from the pattern
- readonly
bindings(Record<string, TensorOrNumber>) - – Currently bound variables
- readonly
unboundVariables(string[]) - – Get the unbound variables (variables without bindings).
- readonly
isComplete(boolean) - – Check if all variables are bound.
A lazy expression that defers evaluation until explicitly executed.
Lazy expressions allow building computation graphs without immediate execution, enabling variable substitution, optimization, and controlled evaluation.
Examples
// Create a lazy expression
const expr = $.lazy('x @ w + b');
// Bind some variables
const withWeights = expr.with({ w: weights, b: bias });
// Execute later with remaining variables
for (const batch of batches) {
const result = withWeights.with({ x: batch }).execute();
}
// Or execute all at once
const result = expr.execute({ x: input, w: weights, b: bias });