Skip to content

Commit

Permalink
add heaviside to lambdify (#412)
Browse files Browse the repository at this point in the history
  • Loading branch information
jverzani authored Feb 28, 2021
1 parent d3fd8ef commit d32b3aa
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 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.0.40"
version = "1.0.41"


[deps]
Expand Down
4 changes: 3 additions & 1 deletion src/lambdify.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ fn_map = Dict(
"StrictGreaterThan" => :(>),
"GreaterThan" => :(>=),
"Greater" => :(>),
"conjugate" => :conj
"conjugate" => :conj,
# not quite a match; NaN not θ(0) when evaluated at 0 w/o second argument
"Heaviside" => :((a...) -> (a[1] < 0 ? 0.0 : (a[1] > 0 ? 1.0 : (length(a) > 1 ? a[2] : NaN))))
)

map_fn(key, fn_map) = haskey(fn_map, key) ? fn_map[key] : Symbol(key)
Expand Down
10 changes: 10 additions & 0 deletions test/tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -718,4 +718,14 @@ end
@vars n integer=true positive=true
A = sympy.MatrixSymbol("A", n, n)
@test inv(A) == A.I

## issue #411 with Heaviside
@vars t
u = Heaviside(t)
λ = lambdify(u)
@test all((iszero(λ(-1)), isnan(λ(0)), isone(λ(1))))
u = Heaviside(t, 1)
λ = lambdify(u)
@test all((iszero(λ(-1)), isone(λ(0)), isone(λ(1))))

end

2 comments on commit d32b3aa

@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/30988

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.0.41 -m "<description of version>" d32b3aad29694a7b8b07598529228bd6b72b05c4
git push origin v1.0.41

Please sign in to comment.