Skip to content

Commit 95178f8

Browse files
authored
add 2-arg hash leveraging PyCall and PythonCall approaches (#522)
* 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
1 parent d34a8af commit 95178f8

File tree

8 files changed

+30
-24
lines changed

8 files changed

+30
-24
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.12"
3+
version = "1.1.13"
44

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

β€Ždocs/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
44
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
55

66
[compat]
7-
Documenter = "0.24"
7+
Documenter = "0.24, 1"

β€Ždocs/src/Tutorial/matrices.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,9 +974,9 @@ julia> M = Sym[3 -2 4 -2; 5 3 -3 -2; 5 -2 2 -2; 5 -2 -3 3]
974974
975975
julia> M.eigenvals()
976976
Dict{Any, Any} with 3 entries:
977-
-2 => 1
978977
3 => 1
979978
5 => 2
979+
-2 => 1
980980
981981
```
982982

β€Ždocs/src/Tutorial/solvers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,8 @@ julia> solveset(x^3 - 6*x^2 + 9*x, x)
519519
```jldoctest solvers
520520
julia> roots(x^3 - 6*x^2 + 9*x, x) |> d -> convert(Dict{Sym, Any}, d) # prettier priting
521521
Dict{Sym, Any} with 2 entries:
522-
3 => 2
523522
0 => 1
523+
3 => 2
524524
```
525525

526526
----

β€Ždocs/src/introduction.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,8 +1210,8 @@ julia> v = solveset(x^2 ~ 4, x)
12101210
12111211
julia> collect(Set(v...))
12121212
2-element Vector{Any}:
1213-
-2
12141213
2
1214+
-2
12151215
12161216
```
12171217

@@ -1220,8 +1220,8 @@ This composition is done in the `elements` function:
12201220
```jldoctest introduction
12211221
julia> elements(v)
12221222
2-element Vector{Sym}:
1223-
-2
12241223
2
1224+
-2
12251225
12261226
```
12271227

β€Ždocs/src/reference.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ end
1313
```
1414

1515
```@autodocs
16-
Modules = [SymPy]
16+
Modules = [SymPy, SymPy.𝑄, SymPy.Introspection]
17+
Order = [:function, :constant, :macro, :type, :module]
1718
```

β€Žsrc/assumptions.jl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export ask
5353
𝑄
5454
SymPy.Q
5555
56-
Documentation for the `SymPy.Q` module, exported as `𝑄`.
56+
The`SymPy.𝑄` module adds features of the `sympy.Q` module. Also accesible through `SymPy.Q`.
5757
5858
SymPy allows for
5959
[assumptions](https://docs.sympy.org/latest/modules/assumptions/index.html)
@@ -71,7 +71,7 @@ julia> @vars y real=true positive=true
7171
(y,)
7272
```
7373
74-
The `Q` module exposes a means to *q*uery the assumptions on a
74+
The `𝑄` module exposes a means to *q*uery the assumptions on a
7575
variable. For example,
7676
7777
```jldoctest 𝑄
@@ -104,12 +104,15 @@ The above use `&` as an infix operation for the binary operator
104104
`And`. Values can also be combined with `Or`, `Not`, `Xor`, `Nand`,
105105
`Nor`, `Implies`, `Equivalent`, and `satisfiable`.
106106
107+
!!! note "typing `𝑄`"
108+
𝑄 is entered as [slash]itQ[tab]) or `SymPy.Q.query(value)` *but not* as `sympy.Q.query(value)`
109+
107110
!!! note "Matrix predicates"
108111
As `SymPy.jl` converts symbolic matrices into Julia's `Array`
109112
type and not as matrices within Python, the predicate functions from SymPy for
110113
matrices are not used, though a replacement is given.
111114
"""
112-
module Q
115+
module 𝑄
113116
import SymPy
114117
import PyCall
115118
import LinearAlgebra: det, norm
@@ -253,7 +256,7 @@ function positive_definite(M::Array{T,2}) where {T <: SymPy.Sym}
253256
no_false = 0
254257
no_nothing = 0
255258
for i in 1:m
256-
a = SymPy.ask(Q.positive(det(M[1:i, 1:i])))
259+
a = SymPy.ask(𝑄.positive(det(M[1:i, 1:i])))
257260
if a == nothing no_nothing += 1 end
258261
if a == false no_false += 1 end
259262
end
@@ -345,23 +348,20 @@ end
345348

346349

347350
end
351+
export 𝑄
348352

349353
## Issue #354; request to *not* export Q
350354
## export
351355
#export Q
352356

353-
const 𝑄 = Q
354-
355-
"""
356-
𝑄
357-
358-
Exported symbol for [`SymPy.Q`](@ref), a Julia module implementing `sympy.Q`. "Questions" can be asked through the patterns
359-
`𝑄.query(value)` (𝑄 is entered as [slash]itQ[tab]) or `SymPy.Q.query(value)` *but not* as `sympy.Q.query(value)`
357+
# """
358+
# Q
360359

361-
!!! note
362-
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.
360+
# Unexported symbol for [`SymPy.𝑄`](@ref), a Julia module implementing `sympy.Q`. "Questions" can be asked through the patterns
361+
# `𝑄.query(value)`
363362

364-
"""
365-
𝑄
366-
export 𝑄
363+
# !!! note
364+
# 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.
367365

366+
# """
367+
const Q = 𝑄

β€Žsrc/types.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@ export Lambda
6161
## this allows most things to flow though PyCall
6262
PyCall.PyObject(x::SymbolicObject) = x.__pyobject__
6363
## Override this so that using symbols as keys in a dict works
64-
hash(x::SymbolicObject) = hash(PyObject(x))
64+
function Base.hash(x::SymbolicObject, h::UInt)
65+
o = PyObject(x)
66+
px = ccall((PyCall.@pysym :PyObject_Hash), PyCall.Py_hash_t, (PyCall.PyPtr,), o) # from PyCall.jl
67+
reinterpret(UInt, Int(px)) - 3h # from PythonCall.jl
68+
end
69+
#hash(x::SymbolicObject) = hash(PyObject(x))
6570
==(x::SymbolicObject, y::SymbolicObject) = PyObject(x) == PyObject(y)
6671

6772
##################################################

0 commit comments

Comments
Β (0)