Skip to content

ENH: Simplify transpose(solve(transpose(A), transpose(B))) patterns #1894

@aman-coder03

Description

@aman-coder03

Before

Some linear algebra expressions are rewritten into forms like:
`Transpose(Solve(Transpose(A), Transpose(B)))`

These expressions are mathematically correct, and transpose operations are inexpensive views, but they introduce additional graph nodes and complexity
Currently, there does not appear to be a rewrite that simplifies transposesolvetranspose compositions into a more direct or canonical form

After

Introduce a graph rewrite that detects transposesolvetranspose patterns and simplifies them when mathematically valid.

`Transpose(Solve(Transpose(A), Transpose(B)))`
could be simplified into an equivalent but more canonical form without unnecessary transpose layers
This would improve graph readability and consistency with other linear algebra rewrites

Context for the issue:

PyTensor already includes several linear algebra graph rewrites in pytensor/tensor/rewriting/linalg.py, including optimizations involving matrix inverse, solve, and transpose operations.
While transpose operations are inexpensive views, simplifying transpose solve transpose compositions would improve graph clarity and align with the broader goal of optimizing symbolic linear algebra expressions.
This could also enable additional downstream rewrite opportunities and improve overall graph simplification.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions