Skip to content

Commit

Permalink
add 2-arg hash leveraging PyCall and PythonCall approaches (#522)
Browse files Browse the repository at this point in the history
* add 2-arg hash leveraging PyCall and PythonCall approaches

* doc adjustments due to change in hashing

* docs

* documenter 1.0, address missing docs

* add \itQ

* hit n hope

* adjust

* switch itQ Q for documenter

* oops

* oops

* try to hide Q from documenter
  • Loading branch information
jverzani committed Sep 24, 2023
1 parent d34a8af commit 95178f8
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 24 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.12"
version = "1.1.13"

[deps]
CommonEq = "3709ef60-1bee-4518-9f2f-acd86f176c50"
Expand Down
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"

[compat]
Documenter = "0.24"
Documenter = "0.24, 1"
2 changes: 1 addition & 1 deletion docs/src/Tutorial/matrices.md
Original file line number Diff line number Diff line change
Expand Up @@ -974,9 +974,9 @@ julia> M = Sym[3 -2 4 -2; 5 3 -3 -2; 5 -2 2 -2; 5 -2 -3 3]
julia> M.eigenvals()
Dict{Any, Any} with 3 entries:
-2 => 1
3 => 1
5 => 2
-2 => 1
```

Expand Down
2 changes: 1 addition & 1 deletion docs/src/Tutorial/solvers.md
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,8 @@ julia> solveset(x^3 - 6*x^2 + 9*x, x)
```jldoctest solvers
julia> roots(x^3 - 6*x^2 + 9*x, x) |> d -> convert(Dict{Sym, Any}, d) # prettier priting
Dict{Sym, Any} with 2 entries:
3 => 2
0 => 1
3 => 2
```

----
Expand Down
4 changes: 2 additions & 2 deletions docs/src/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -1210,8 +1210,8 @@ julia> v = solveset(x^2 ~ 4, x)
julia> collect(Set(v...))
2-element Vector{Any}:
-2
2
-2
```

Expand All @@ -1220,8 +1220,8 @@ This composition is done in the `elements` function:
```jldoctest introduction
julia> elements(v)
2-element Vector{Sym}:
-2
2
-2
```

Expand Down
3 changes: 2 additions & 1 deletion docs/src/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ end
```

```@autodocs
Modules = [SymPy]
Modules = [SymPy, SymPy.𝑄, SymPy.Introspection]
Order = [:function, :constant, :macro, :type, :module]
```
32 changes: 16 additions & 16 deletions src/assumptions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export ask
𝑄
SymPy.Q
Documentation for the `SymPy.Q` module, exported as `𝑄`.
The`SymPy.𝑄` module adds features of the `sympy.Q` module. Also accesible through `SymPy.Q`.
SymPy allows for
[assumptions](https://docs.sympy.org/latest/modules/assumptions/index.html)
Expand All @@ -71,7 +71,7 @@ julia> @vars y real=true positive=true
(y,)
```
The `Q` module exposes a means to *q*uery the assumptions on a
The `𝑄` module exposes a means to *q*uery the assumptions on a
variable. For example,
```jldoctest 𝑄
Expand Down Expand Up @@ -104,12 +104,15 @@ The above use `&` as an infix operation for the binary operator
`And`. Values can also be combined with `Or`, `Not`, `Xor`, `Nand`,
`Nor`, `Implies`, `Equivalent`, and `satisfiable`.
!!! note "typing `𝑄`"
𝑄 is entered as [slash]itQ[tab]) or `SymPy.Q.query(value)` *but not* as `sympy.Q.query(value)`
!!! note "Matrix predicates"
As `SymPy.jl` converts symbolic matrices into Julia's `Array`
type and not as matrices within Python, the predicate functions from SymPy for
matrices are not used, though a replacement is given.
"""
module Q
module 𝑄
import SymPy
import PyCall
import LinearAlgebra: det, norm
Expand Down Expand Up @@ -253,7 +256,7 @@ function positive_definite(M::Array{T,2}) where {T <: SymPy.Sym}
no_false = 0
no_nothing = 0
for i in 1:m
a = SymPy.ask(Q.positive(det(M[1:i, 1:i])))
a = SymPy.ask(𝑄.positive(det(M[1:i, 1:i])))
if a == nothing no_nothing += 1 end
if a == false no_false += 1 end
end
Expand Down Expand Up @@ -345,23 +348,20 @@ end


end
export 𝑄

## Issue #354; request to *not* export Q
## export
#export Q

const 𝑄 = Q

"""
𝑄
Exported symbol for [`SymPy.Q`](@ref), a Julia module implementing `sympy.Q`. "Questions" can be asked through the patterns
`𝑄.query(value)` (𝑄 is entered as [slash]itQ[tab]) or `SymPy.Q.query(value)` *but not* as `sympy.Q.query(value)`
# """
# Q

!!! note
At one time, the symbol `Q` was exported for this. To avoid namespace clutter, the unicode alternative is now used. Legacy code would need a definition like `const Q = SymPy.Q` to work.
# Unexported symbol for [`SymPy.𝑄`](@ref), a Julia module implementing `sympy.Q`. "Questions" can be asked through the patterns
# `𝑄.query(value)`

"""
𝑄
export 𝑄
# !!! note
# At one time, the symbol `Q` was exported. To avoid namespace clutter, the unicode alternative is now used. Legacy code would need a definition like `import SymPy: Q` to work.

# """
const Q = 𝑄
7 changes: 6 additions & 1 deletion src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ export Lambda
## this allows most things to flow though PyCall
PyCall.PyObject(x::SymbolicObject) = x.__pyobject__
## Override this so that using symbols as keys in a dict works
hash(x::SymbolicObject) = hash(PyObject(x))
function Base.hash(x::SymbolicObject, h::UInt)
o = PyObject(x)
px = ccall((PyCall.@pysym :PyObject_Hash), PyCall.Py_hash_t, (PyCall.PyPtr,), o) # from PyCall.jl
reinterpret(UInt, Int(px)) - 3h # from PythonCall.jl
end
#hash(x::SymbolicObject) = hash(PyObject(x))
==(x::SymbolicObject, y::SymbolicObject) = PyObject(x) == PyObject(y)

##################################################
Expand Down

2 comments on commit 95178f8

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

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.13 -m "<description of version>" 95178f84183fe3006b29ce96671bc4b67843364d
git push origin v1.1.13

Please sign in to comment.