torch.tx.CompiledExpression
class CompiledExpressionnew CompiledExpression(pattern: string, originalAST: ASTNode, optimizedAST: ASTNode, internalExpression: string, variables: string[], varToIndex: Map<string, number>, optimizations: string[], bindings: Record<string, TensorOrNumber> = {}, name?: string)
- readonly
pattern(string) - – The original pattern string
- readonly
name(string | undefined) - – Optional name for debugging
- readonly
variables(string[]) - – Variable names extracted from the pattern
- readonly
bindings(Record<string, TensorOrNumber>) - – Currently bound variables
- readonly
optimizations(string[]) - – Optimizations applied during compilation
- readonly
unboundVariables(string[]) - – Get the unbound variables.
- readonly
isComplete(boolean) - – Check if all variables are bound.
- readonly
isOptimized(boolean) - – Check if any optimizations were applied.
A fully compiled expression with advanced features.
CompiledExpression combines the benefits of:
- Pre-parsed AST (zero parsing overhead)
- Static optimizations applied at compile time
- Incremental variable binding (like lazy evaluation)
- Output buffer support (like efficient evaluation)
- Full introspection capabilities
Examples
// Compile an expression
const linear = $.compileAdvanced('relu(x @ w + b)');
// Check what was optimized
console.log(linear.optimizations);
// Bind some variables (like lazy)
const withParams = linear.bind({ w: weights, b: bias });
// Run with remaining variables and output buffer (like efficient)
const out = torch.empty(batch_size, hidden_dim);
for (const batch of batches) {
withParams.run({ x: batch }, { out });
process(out);
}