Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SymPyPythonCall"
uuid = "bc8888f7-b21e-4b7c-a06a-5d9c9496438c"
authors = ["jverzani <jverzani@gmail.com> and contributors"]
version = "0.2.6"
version = "0.3.0"


[deps]
Expand All @@ -28,7 +28,7 @@ PythonCall = "0.9"
SpecialFunctions = "0.8, 0.9, 0.10, 1.0, 2"
Symbolics = "5"
SymbolicUtils = "1"
SymPyCore = "0.1.6, 1"
SymPyCore = "0.2, 1"
julia = "1.6.1"


Expand Down
20 changes: 18 additions & 2 deletions src/python_connection.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
## PythonCall specific usage
Base.convert(::Type{S}, x::Sym{T}) where {T <: PythonCall.Py, S<:Sym} = x
Base.convert(::Type{S}, x::Sym{T}) where {T <: PythonCall.Py,
S<:Sym{PythonCall.Py}} = x
Base.convert(::Type{S}, x::T) where {T<:PythonCall.Py, S <: SymbolicObject} = Sym(x)

SymPyCore._convert(::Type{T}, x) where {T} = pyconvert(T, x)
function SymPyCore._convert(::Type{Bool}, x::Py)
pyconvert(Bool, x == _sympy_.logic.boolalg.BooleanTrue) && return true
pyconvert(Bool, x == _sympy_.logic.boolalg.BooleanFalse) && return false
pyisinstance(x, _sympy_.logic.boolalg.BooleanTrue) && return true
pyisinstance(x, _sympy_.logic.boolalg.BooleanFalse) && return false
pyconvert(Bool, pybool(x))
end

function SymPyCore.Bool3(x::Sym{T}) where {T <: PythonCall.Py}
y = ↓(x)
isnothing(y) && return nothing
if hasproperty(y, "is_Boolean")
if pyconvert(Bool, y.is_Boolean)
return SymPyCore._convert(Bool, y)
end
elseif hasproperty(y, "__bool__")
if pyconvert(Bool, y.__bool__ != ↓(Sym(nothing)))
return pyconvert(Bool, y.__bool__())
end
end
return nothing
end

## Modifications for ↓, ↑
Sym(x::Nothing) = Sym(pybuiltins.None)
Expand Down