torch.tx.NamedExpression
export interface NamedExpression<T extends Record<string, TensorOrNumber>> {
/** The name of this expression */
readonly name: string;
/** The pattern string */
readonly pattern: string;
/** Variable names in the pattern */
readonly variables: string[];
/** Evaluate the expression */
(tensors: T): AnyTensor;
}Textends Record<string, TensorOrNumber>- readonly
name(string) - – The name of this expression
- readonly
pattern(string) - – The pattern string
- readonly
variables(string[]) - – Variable names in the pattern
Create a named expression that can be inspected and composed.
Unlike regular functions, named expressions preserve their pattern string and variable names, enabling introspection and further composition.
Examples
const attention = $.named('scaled_dot_product_attention',
'softmax(q @ mT(k) / scale, -1) @ v'
);
console.log(attention.name); // 'scaled_dot_product_attention'
console.log(attention.pattern); // 'softmax(q @ mT(k) / scale, -1) @ v'
console.log(attention.variables); // ['q', 'k', 'scale', 'v']