|
1 | 1 | module Code |
2 | 2 |
|
3 | 3 | using StaticArrays, LabelledArrays, SparseArrays, LinearAlgebra |
4 | | -using TermInterface |
5 | 4 |
|
6 | 5 | export toexpr, Assignment, (←), Let, Func, DestructuredArgs, LiteralExpr, |
7 | 6 | SetArray, MakeArray, MakeSparseArray, MakeTuple, AtIndex, |
8 | 7 | SpawnFetch, Multithreaded, cse |
9 | 8 |
|
10 | 9 | import ..SymbolicUtils |
11 | 10 | import ..SymbolicUtils.Rewriters |
12 | | -import SymbolicUtils: @matchable, BasicSymbolic, Sym, Term, istree, operation, arguments, |
13 | | - symtype, similarterm, unsorted_arguments, metadata |
| 11 | +import SymbolicUtils: @matchable, BasicSymbolic, Sym, Term, istree, operation, arguments, issym, |
| 12 | + symtype, similarterm, unsorted_arguments, metadata, isterm, term |
14 | 13 |
|
15 | 14 | ##== state management ==## |
16 | 15 |
|
@@ -134,7 +133,7 @@ function function_to_expr(::typeof(SymbolicUtils.ifelse), O, st) |
134 | 133 | end |
135 | 134 |
|
136 | 135 | function function_to_expr(x::BasicSymbolic, O, st) |
137 | | - TermInterface.issym(x) ? get(st.symbolify, O, nothing) : nothing |
| 136 | + issym(x) ? get(st.symbolify, O, nothing) : nothing |
138 | 137 | end |
139 | 138 |
|
140 | 139 | toexpr(O::Expr, st) = O |
|
693 | 692 |
|
694 | 693 |
|
695 | 694 | function _cse(exprs::AbstractArray) |
696 | | - letblock = cse(Term{Any}(tuple, exprs)) |
697 | | - letblock.pairs, arguments(letblock.body) |
| 695 | + letblock = cse(Term{Any}(tuple, vec(exprs))) |
| 696 | + letblock.pairs, reshape(arguments(letblock.body), size(exprs)) |
698 | 697 | end |
699 | 698 |
|
700 | 699 | function cse(x::MakeArray) |
@@ -738,8 +737,13 @@ function cse_block!(assignments, counter, names, name, state, x) |
738 | 737 | end |
739 | 738 | elseif istree(x) |
740 | 739 | args = map(a->cse_block!(assignments, counter, names, name, state,a), unsorted_arguments(x)) |
741 | | - return similarterm(x, operation(x), args, symtype(x), |
742 | | - metadata=metadata(x)) |
| 740 | + if isterm(x) |
| 741 | + return term(operation(x), args...) |
| 742 | + else |
| 743 | + return similarterm(x, operation(x), |
| 744 | + args, symtype(x), |
| 745 | + metadata=metadata(x)) |
| 746 | + end |
743 | 747 | else |
744 | 748 | return x |
745 | 749 | end |
|
0 commit comments