Skip to content

Commit 2c0f2d4

Browse files
committed
support Indexed and IndexedBase
1 parent 937f3c2 commit 2c0f2d4

File tree

2 files changed

+31
-27
lines changed

2 files changed

+31
-27
lines changed

src/lambdify.jl

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -43,34 +43,34 @@ __ZERO__(xs...) = 0
4343
__HEAVISIDE__ = (a...) -> (a[1] < 0 ? 0 : (a[1] > 0 ? 1 : (length(a) > 1 ? a[2] : NaN)))
4444
# __SYMPY__ALL__,
4545
fn_map = Dict(
46-
"Add" => :+,
47-
"Sub" => :-,
48-
"Mul" => :*, # :(SymPy.__PROD__)
49-
"Div" => :/,
50-
"Pow" => :^,
51-
"re" => :real,
52-
"im" => :imag,
53-
"Abs" => :abs,
54-
"Min" => :min,
55-
"Max" => :max,
56-
"Poly" => :identity,
57-
"Piecewise" => :(SymPy._piecewise),
58-
"Order" => :(SymPy.__ZERO__), # :(as...) -> 0,
59-
"And" => :(SymPy.__ALL__), #:((as...) -> all(as)), #:(&),
60-
"Or" => :(SymPy.__ANY__), #:((as...) -> any(as)), #:(|),
61-
"Less" => :(<),
62-
"LessThan" => :(<=),
63-
"StrictLessThan" => :(<),
64-
"Equal" => :(==),
65-
"Equality" => :(==),
66-
"Unequality" => :(!==),
67-
"StrictGreaterThan" => :(>),
68-
"GreaterThan" => :(>=),
69-
"Greater" => :(>),
46+
"Add" => :+,
47+
"Sub" => :-,
48+
"Mul" => :*, # :(SymPy.__PROD__)
49+
"Div" => :/,
50+
"Pow" => :^,
51+
"re" => :real,
52+
"im" => :imag,
53+
"Abs" => :abs,
54+
"Min" => :min,
55+
"Max" => :max,
56+
"Poly" => :identity,
57+
"Piecewise" => :(SymPy._piecewise),
58+
"Order" => :(SymPy.__ZERO__), # :(as...) -> 0,
59+
"And" => :(SymPy.__ALL__), #:((as...) -> all(as)), #:(&),
60+
"Or" => :(SymPy.__ANY__), #:((as...) -> any(as)), #:(|),
61+
"Less" => :(<),
62+
"LessThan" => :(<=),
63+
"StrictLessThan" => :(<),
64+
"Equal" => :(==),
65+
"Equality" => :(==),
66+
"Unequality" => :(!==),
67+
"StrictGreaterThan" => :(>),
68+
"GreaterThan" => :(>=),
69+
"Greater" => :(>),
7070
"conjugate" => :conj,
7171
"atan2" => :atan,
72-
"Heaviside" => :(SymPy.__HEAVISIDE__)
73-
)
72+
"Heaviside" => :(SymPy.__HEAVISIDE__),
73+
)
7474

7575
map_fn(key, fn_map) = haskey(fn_map, key) ? fn_map[key] : Symbol(key)
7676

@@ -89,7 +89,7 @@ function walk_expression(ex; values=Dict(), fns=Dict())
8989
return walk_expression(rhs(ex), values=values, fns=fns)
9090
end
9191

92-
if fn == "Symbol" || fn == "Dummy"
92+
if fn == "Symbol" || fn == "Dummy" || fn == "IndexedBase"
9393
str_ex = string(ex)
9494
return get(vals_map, str_ex, Symbol(str_ex))
9595
elseif fn in ["Integer" , "Float"]
@@ -104,6 +104,8 @@ function walk_expression(ex; values=Dict(), fns=Dict())
104104
return (val, walk_expression(cond, values=values, fns=fns))
105105
elseif fn == "Tuple"
106106
return walk_expression.(Introspection.args(ex), values=values, fns=fns)
107+
elseif fn == "Indexed"
108+
return Expr(:ref, [walk_expression(a, values=values, fns=fns) for a in Introspection.args(ex)]...)
107109
elseif haskey(vals_map, fn)
108110
return vals_map[fn]
109111
end

test/tests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,3 +809,5 @@ end
809809
@test limit(ceil(x), x=>0, dir="+") != limit(ceil(x), x=>0, dir="-")
810810
@test limit(floor(x), x=>0, dir="+") != limit(floor(x), x=>0, dir="-")
811811
end
812+
813+
@test SymPy.convert_expr(sympy.Indexed(sympy.IndexedBase(:x), 1, -2)) == :(x[1, -2])

0 commit comments

Comments
 (0)