Skip to content

Commit

Permalink
tweak lambdify for constants (#527)
Browse files Browse the repository at this point in the history
* tweak lambdify for constants

* adjust

* rework
  • Loading branch information
jverzani committed Sep 27, 2023
1 parent ef36f84 commit b12bfd9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "SymPy"
uuid = "24249f21-da20-56a4-8eb1-6a02cf4ae2e6"
version = "1.1.13"
version = "1.1.14"

[deps]
CommonEq = "3709ef60-1bee-4518-9f2f-acd86f176c50"
Expand Down
13 changes: 11 additions & 2 deletions src/lambdify.jl
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ Take a symbolic expression and return a `Julia` function or expression to build
* `ex::Sym` a symbolic expression with 0, 1, or more free symbols
* `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.
* `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.
* `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.
Expand Down Expand Up @@ -245,7 +245,16 @@ function lambdify(ex::Sym, vars=free_symbols(ex);
fns=Dict(), values=Dict(),
use_julia_code=false,
invoke_latest=true)

if isempty(vars)
# can't call N(ex) here...
v = ex.evalf()
if v.is_real == True
val = convert(Real, v)
else
val = Complex(convert(Real, real(v)), convert(Real, imag(v)))
end
return (ts...) -> val
end
body = convert_expr(ex, fns=fns, values=values, use_julia_code=use_julia_code)
ex = expr_to_function(body, vars)
if invoke_latest
Expand Down
2 changes: 1 addition & 1 deletion src/plot_recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ using RecipesBase
## A vector field plot can be visualized as an n × n collection of arrows
## over the region xlims × ylims
## These arrows are defined by:
## * fx, fy giving the components of each. These are callbable objects, such as
## * fx, fy giving the components of each. These are callable objects, such as
## (x,y) -> sin(y)
## * Fyx A function F(y,x), useful for visualizing first-order ODE y'=F(y(x),x).
## note reverse order of y and x.
Expand Down

2 comments on commit b12bfd9

@jverzani
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/92361

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.1.14 -m "<description of version>" b12bfd92dcfb3d3c7226deeda1eaa84006904185
git push origin v1.1.14

Please sign in to comment.