torch.tx.TypedTensorExprWithHelpers
export interface TypedTensorExprWithHelpers extends TypedTensorExpr {
/**
* Type-safe expression evaluation with pattern string.
*
* Uses a pattern string with named placeholders for full compile-time
* shape checking. Variable names in the pattern must match object keys.
*
* @example
* ```typescript
* // Linear layer - catches shape errors at compile time!
* const output = $.e('input @ weights + bias', { input, weights, bias });
*
* // GRU cell
* const h_next = $.e('(-z_gate + 1) * candidate + z_gate * h_prev', {
* z_gate, candidate, h_prev
* });
*
* // Attention
* const attended = $.e('scores @ values', { scores, values });
* ```
*/
e: <const Pattern extends string, Tensors extends Record<string, TensorOrNumber>>(
pattern: Pattern,
tensors: Tensors
) => PatternExprResult<Pattern, Tensors>;
/** Debug template - evaluates with logging enabled */
debug: TypedTensorExpr & { enabled: boolean };
/** Trace template - returns result and execution trace */
trace: <const Strings extends readonly string[], Tensors extends readonly TensorOrNumber[]>(
strings: TemplateStringsArray & { readonly raw: Strings },
...tensors: Tensors
) => _TraceResult;
/** Parse without evaluating */
parse: <Tensors extends readonly TensorOrNumber[]>(
strings: TemplateStringsArray,
...tensors: Tensors
) => _ParseResult;
/** Convert expression to method chain representation */
toMethodChain: (strings: TemplateStringsArray, tensorNames?: string[]) => string;
/** Register a custom function for use in expressions */
registerFunction: (name: string, def: unknown) => void;
/** Register a custom binary operator */
registerOperator: (name: string, def: unknown) => void;
/** Add an overload for a built-in operator */
overloadOperator: (op: string, overload: unknown) => void;
/** Check if a function is registered */
hasFunction: (name: string) => boolean;
/** Check if an operator is registered */
hasOperator: (name: string) => boolean;
/** Clear the AST cache */
clearCache: () => void;
/** Current AST cache size */
readonly cacheSize: number;
}e(<const Pattern extends string, Tensors extends Record<string, TensorOrNumber>>( pattern: Pattern, tensors: Tensors ) => PatternExprResult<Pattern, Tensors>)- – Type-safe expression evaluation with pattern string. Uses a pattern string with named placeholders for full compile-time shape checking. Variable names in the pattern must match object keys.
debug(TypedTensorExpr & { enabled: boolean })- – Debug template - evaluates with logging enabled
trace(<const Strings extends readonly string[], Tensors extends readonly TensorOrNumber[]>( strings: TemplateStringsArray & { readonly raw: Strings }, ...tensors: Tensors ) => _TraceResult)- – Trace template - returns result and execution trace
parse(<Tensors extends readonly TensorOrNumber[]>( strings: TemplateStringsArray, ...tensors: Tensors ) => _ParseResult)- – Parse without evaluating
toMethodChain((strings: TemplateStringsArray, tensorNames?: string[]) => string)- – Convert expression to method chain representation
registerFunction((name: string, def: unknown) => void)- – Register a custom function for use in expressions
registerOperator((name: string, def: unknown) => void)- – Register a custom binary operator
overloadOperator((op: string, overload: unknown) => void)- – Add an overload for a built-in operator
hasFunction((name: string) => boolean)- – Check if a function is registered
hasOperator((name: string) => boolean)- – Check if an operator is registered
clearCache(() => void)- – Clear the AST cache
- readonly
cacheSize(number) - – Current AST cache size
Full tensorExpr interface including utilities.
Shape errors from the type system propagate automatically. Invalid operations produce error types that cause compile-time failures.