Skip to content

Commit b12bfd9

Browse files
authored
tweak lambdify for constants (#527)
* tweak lambdify for constants * adjust * rework
1 parent ef36f84 commit b12bfd9

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "SymPy"
22
uuid = "24249f21-da20-56a4-8eb1-6a02cf4ae2e6"
3-
version = "1.1.13"
3+
version = "1.1.14"
44

55
[deps]
66
CommonEq = "3709ef60-1bee-4518-9f2f-acd86f176c50"

src/lambdify.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ Take a symbolic expression and return a `Julia` function or expression to build
156156
157157
* `ex::Sym` a symbolic expression with 0, 1, or more free symbols
158158
159-
* `vars` a container of symbols to use for the function arguments. The default is `free_symbols` which has a specific ordering. Specifying `vars` allows this default ordering of arguments to be customized.
159+
* `vars` a container of symbols to use for the function arguments. The default is `free_symbols` which has a specific ordering. Specifying `vars` allows this default ordering of arguments to be customized. If `vars` is empty, such as when the symbolic expression has *no* free symbols, a variable arg constant function is returned.
160160
161161
* `fns::Dict`, `vals::Dict`: Dictionaries that allow customization of the function that walks the expression `ex` and creates the corresponding AST for a Julia expression. See `SymPy.fn_map` and `SymPy.val_map` for the default mappings of sympy functions and values into `Julia`'s AST.
162162
@@ -245,7 +245,16 @@ function lambdify(ex::Sym, vars=free_symbols(ex);
245245
fns=Dict(), values=Dict(),
246246
use_julia_code=false,
247247
invoke_latest=true)
248-
248+
if isempty(vars)
249+
# can't call N(ex) here...
250+
v = ex.evalf()
251+
if v.is_real == True
252+
val = convert(Real, v)
253+
else
254+
val = Complex(convert(Real, real(v)), convert(Real, imag(v)))
255+
end
256+
return (ts...) -> val
257+
end
249258
body = convert_expr(ex, fns=fns, values=values, use_julia_code=use_julia_code)
250259
ex = expr_to_function(body, vars)
251260
if invoke_latest

src/plot_recipes.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ using RecipesBase
138138
## A vector field plot can be visualized as an n × n collection of arrows
139139
## over the region xlims × ylims
140140
## These arrows are defined by:
141-
## * fx, fy giving the components of each. These are callbable objects, such as
141+
## * fx, fy giving the components of each. These are callable objects, such as
142142
## (x,y) -> sin(y)
143143
## * Fyx A function F(y,x), useful for visualizing first-order ODE y'=F(y(x),x).
144144
## note reverse order of y and x.

0 commit comments

Comments
 (0)