Skip to content

Commit

Permalink
Bool3, bump
Browse files Browse the repository at this point in the history
  • Loading branch information
jverzani committed May 24, 2024
1 parent 4b4db36 commit 97c13ca
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
4 changes: 2 additions & 2 deletions 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 = "2.0.1"
version = "2.1.0"

[deps]
CommonEq = "3709ef60-1bee-4518-9f2f-acd86f176c50"
Expand All @@ -17,7 +17,7 @@ LinearAlgebra = "<0.0.1, 1.6"
PyCall = "1.96.2"
SpecialFunctions = "0.7, 0.8, 0.8, 0.10, 1, 2"
SymbolicUtils = "1"
SymPyCore = "0.1.6, 1"
SymPyCore = "0.2, 1"
julia = "1.6"

[extras]
Expand Down
23 changes: 16 additions & 7 deletions src/python_connection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
# PyObject are needed for that.

Base.convert(::Type{S}, x::Sym{T}) where {T<:PyObject, S<:Sym} = x
Base.convert(::Type{S}, x::Sym{T}) where {T<:PyObject, S<:Sym{PyObject}} = x
Base.convert(::Type{S}, x::T) where {T<:PyObject, S <: SymbolicObject} = Sym(x)

SymPyCore._convert(::Type{T}, x) where {T} = convert(T, x)

function SymPyCore._convert(::Type{Bool}, x::PyObject)
x == _sympy_.logic.boolalg.BooleanTrue && return true
x == _sympy_.logic.boolalg.BooleanFalse && return false
Expand All @@ -22,13 +24,20 @@ function SymPyCore._convert(::Type{Bool}, x::PyObject)
error("Can't convert $x to boolean")
end


## Modifications for ↓, ↑
Sym(x::Nothing) = Sym(PyObject(nothing))
Sym(x::Bool) = Sym(PyObject(x))
Sym(x::Integer) = Sym(_sympy_.Integer(x)) # slight improvement over sympify
Sym(x::AbstractFloat) = Sym(_sympy_.Float(x))

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

SymPyCore.:(x::PyObject) = x
SymPyCore.:(d::Dict) = Dict((k) => (v) for (k,v) pairs(d))
Expand Down

0 comments on commit 97c13ca

Please sign in to comment.