@@ -4,19 +4,24 @@ using ..UtilsModule: deprecate_varmap
4
4
using .. OperatorEnumModule: AbstractOperatorEnum
5
5
using .. NodeModule: AbstractExpressionNode, tree_mapreduce
6
6
7
- function dispatch_op_name (:: Val{deg} , :: Nothing , idx):: Vector{Char} where {deg}
8
- if deg == 1
9
- return vcat (collect (" unary_operator[" ), collect (string (idx)), [' ]' ])
10
- else
11
- return vcat (collect (" binary_operator[" ), collect (string (idx)), [' ]' ])
12
- end
7
+ function dispatch_op_name (
8
+ :: Val{deg} , :: Nothing , idx, pretty:: Bool
9
+ ):: Vector{Char} where {deg}
10
+ return vcat (
11
+ collect (deg == 1 ? " unary_operator[" : " binary_operator[" ),
12
+ collect (string (idx)),
13
+ [' ]' ],
14
+ )
13
15
end
14
- function dispatch_op_name (:: Val{deg} , operators:: AbstractOperatorEnum , idx) where {deg}
15
- if deg == 1
16
- return collect (get_op_name (operators. unaops[idx]):: String )
16
+ function dispatch_op_name (
17
+ :: Val{deg} , operators:: AbstractOperatorEnum , idx, pretty:: Bool
18
+ ) where {deg}
19
+ op = if deg == 1
20
+ operators. unaops[idx]
17
21
else
18
- return collect ( get_op_name ( operators. binops[idx]) :: String )
22
+ operators. binops[idx]
19
23
end
24
+ return collect ((pretty ? get_pretty_op_name (op) : get_op_name (op)):: String )
20
25
end
21
26
22
27
const OP_NAME_CACHE = (; x= Dict {UInt64,String} (), lock= Threads. SpinLock ())
@@ -47,6 +52,9 @@ function get_op_name(op::F) where {F}
47
52
unlock (OP_NAME_CACHE. lock)
48
53
end
49
54
end
55
+ function get_pretty_op_name (op:: F ) where {F}
56
+ return get_op_name (op)
57
+ end
50
58
51
59
@inline function strip_brackets (s:: Vector{Char} ):: Vector{Char}
52
60
if first (s) == ' (' && last (s) == ' )'
@@ -145,8 +153,9 @@ function string_tree(
145
153
raw:: Union{Bool,Nothing} = nothing ,
146
154
varMap= nothing ,
147
155
):: String where {T,F1<: Function ,F2<: Function }
148
- ! isnothing (raw) &&
156
+ if ! isnothing (raw)
149
157
Base. depwarn (" `raw` is deprecated; use `pretty` instead" , :string_tree )
158
+ end
150
159
pretty = @something (pretty, _not (raw), false )
151
160
variable_names = deprecate_varmap (variable_names, varMap, :string_tree )
152
161
raw_output = tree_mapreduce (
@@ -162,9 +171,9 @@ function string_tree(
162
171
end ,
163
172
let operators = operators
164
173
(branch,) -> if branch. degree == 1
165
- dispatch_op_name (Val (1 ), operators, branch. op):: Vector{Char}
174
+ dispatch_op_name (Val (1 ), operators, branch. op, pretty ):: Vector{Char}
166
175
else
167
- dispatch_op_name (Val (2 ), operators, branch. op):: Vector{Char}
176
+ dispatch_op_name (Val (2 ), operators, branch. op, pretty ):: Vector{Char}
168
177
end
169
178
end ,
170
179
combine_op_with_inputs,
0 commit comments