Skip to content

Commit

Permalink
order return value of free_symbols (#288)
Browse files Browse the repository at this point in the history
* order return value of free_symbols

* version bump [ci skip]
  • Loading branch information
jverzani authored Jul 17, 2019
1 parent 7af3cd4 commit 3e7bcca
Show file tree
Hide file tree
Showing 3 changed files with 17 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.0.4"
version = "1.0.5"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
15 changes: 13 additions & 2 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,23 @@ end



##
"""
free_symbols(ex)
Return free symbols of expression or vector of expressions. The results are orderded by
`sortperm(string.(fs))`.
```
@vars x y z a
free_symbols(2*x + a*y) # [a, x, y]
```
"""
function free_symbols(ex::Union{T, Vector{T}}) where {T<:SymbolicObject}
pex = PyObject(ex)
#fs.__class__.__name__ == "set"
if PyCall.hasproperty(pex, :free_symbols)
convert(Vector{Sym}, collect(pex.free_symbols))
fs = convert(Vector{Sym}, collect(pex.free_symbols))
fs[sortperm(string.(fs))] # some sorting order to rely on
else
Sym[]
end
Expand Down
4 changes: 3 additions & 1 deletion test/tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ import PyCall


## extract symbols
ex = x*y
@vars z
ex = x*y*z
@test isa(free_symbols(ex), Vector{Sym})
@test free_symbols(ex) == [x, y, z]

## number conversions
@test Sym(2) == 2
Expand Down

2 comments on commit 3e7bcca

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

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 Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v1.0.5 -m "<description of version>" 3e7bccad8549574f7b57154ee9118c0504348445
git push origin v1.0.5

Please sign in to comment.