Commit c54a34a
Luca Citi
Implemented allow_cast in PatternNodeRewriter
to allow rewrites that would otherwise fail when the new and old dtype differ.
Example:
`np.array(1., "float64") - sigmoid(x)` cannot be rewritten as
`sigmoid(-x)` (where x is an fmatrix) because the type would change.
This commit allows an automatic cast to be added so the expression
is rewritten as `cast(sigmoid(-x), "float64")`.
Relevant tests added.1 parent 0bb15f9 commit c54a34a
File tree
2 files changed
+38
-12
lines changed- pytensor/graph/rewriting
- tests/tensor/rewriting
2 files changed
+38
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1550 | 1550 | | |
1551 | 1551 | | |
1552 | 1552 | | |
| 1553 | + | |
1553 | 1554 | | |
1554 | 1555 | | |
1555 | 1556 | | |
| |||
1572 | 1573 | | |
1573 | 1574 | | |
1574 | 1575 | | |
| 1576 | + | |
| 1577 | + | |
| 1578 | + | |
| 1579 | + | |
1575 | 1580 | | |
1576 | 1581 | | |
1577 | 1582 | | |
| |||
1586 | 1591 | | |
1587 | 1592 | | |
1588 | 1593 | | |
| 1594 | + | |
1589 | 1595 | | |
1590 | 1596 | | |
1591 | 1597 | | |
| |||
1653 | 1659 | | |
1654 | 1660 | | |
1655 | 1661 | | |
1656 | | - | |
1657 | | - | |
1658 | | - | |
| 1662 | + | |
| 1663 | + | |
| 1664 | + | |
| 1665 | + | |
1659 | 1666 | | |
1660 | 1667 | | |
1661 | | - | |
1662 | | - | |
1663 | | - | |
| 1668 | + | |
| 1669 | + | |
| 1670 | + | |
| 1671 | + | |
| 1672 | + | |
| 1673 | + | |
| 1674 | + | |
| 1675 | + | |
1664 | 1676 | | |
1665 | 1677 | | |
1666 | 1678 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| 52 | + | |
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
| |||
4115 | 4116 | | |
4116 | 4117 | | |
4117 | 4118 | | |
| 4119 | + | |
4118 | 4120 | | |
4119 | 4121 | | |
4120 | 4122 | | |
4121 | 4123 | | |
4122 | 4124 | | |
4123 | 4125 | | |
4124 | | - | |
| 4126 | + | |
4125 | 4127 | | |
4126 | 4128 | | |
4127 | 4129 | | |
4128 | 4130 | | |
4129 | | - | |
| 4131 | + | |
4130 | 4132 | | |
4131 | 4133 | | |
4132 | | - | |
4133 | | - | |
4134 | | - | |
4135 | | - | |
| 4134 | + | |
| 4135 | + | |
| 4136 | + | |
| 4137 | + | |
| 4138 | + | |
| 4139 | + | |
| 4140 | + | |
| 4141 | + | |
| 4142 | + | |
| 4143 | + | |
| 4144 | + | |
| 4145 | + | |
| 4146 | + | |
| 4147 | + | |
| 4148 | + | |
| 4149 | + | |
4136 | 4150 | | |
4137 | 4151 | | |
4138 | 4152 | | |
| |||
0 commit comments