transformers ============ .. py:module:: transformers .. autoapi-nested-parse:: AST Transformation Helpers. Provides logic to reconstruct CST nodes for Infix operators, Inline Lambdas, and Structured Index Selection. Functions --------- .. autoapisummary:: transformers.apply_index_select transformers.rewrite_as_inline_lambda transformers.rewrite_as_macro transformers.rewrite_as_infix Module Contents --------------- .. py:function:: apply_index_select(inner_node: libcst.CSTNode, index: int) -> libcst.Subscript Wraps an expression node with a subscript access for a specific integer index. Safe, structured alternative to string output adapters for tuple destructuring. Transformation: Input node: `func(...)` Output: `func(...)[index]` :param inner_node: The expression node (usually a Call) to slice. :type inner_node: cst.CSTNode :param index: The integer index to access. :type index: int :returns: The wrapped node. :rtype: cst.Subscript .. py:function:: rewrite_as_inline_lambda(lambda_str: str, args: list[libcst.Arg]) -> libcst.Call Wraps arguments in an Immediately Invoked Lambda Expression (IIFE). .. py:function:: rewrite_as_macro(template: str, args_list: list[libcst.Arg], std_arg_names: list[str]) -> libcst.CSTNode Replaces an operation call with a python expression defined in the template. Arguments are substituted into the template string using placeholders matching the standard argument names (e.g. `{x}`). :param template: The macro string (e.g. "{x} * jax.nn.sigmoid({x})"). :type template: str :param args_list: The normalized argument nodes for this call. :type args_list: list[cst.Arg] :param std_arg_names: The names of standard arguments in order. :type std_arg_names: list[str] :returns: The constructed expression logic. :rtype: cst.CSTNode :raises ValueError: If arguments required by the template are missing. :raises cst.ParserSyntaxError: If the resulting string is invalid Python. .. py:function:: rewrite_as_infix(_original_node: libcst.Call, args: List[libcst.Arg], op_symbol: str, std_args: List[str]) -> Union[libcst.BinaryOperation, libcst.UnaryOperation] Transforms a functional call into an infix (binary) or prefix (unary) expression.