Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bool3 #546

Merged
merged 4 commits into from
May 24, 2024
Merged

Bool3 #546

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,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
1 change: 0 additions & 1 deletion src/SymPy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ include(joinpath(core_src_path, "gen_methods_sympy.jl"))
include(joinpath(core_src_path, "additional_methods_sympy.jl"))
include(joinpath(core_src_path, "show_sympy.jl"))


include("python_connection.jl")

end # module
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
Loading