Skip to content

Commit a5e0b11

Browse files
committed
WIP
1 parent 072ad2d commit a5e0b11

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

ext/SymPyPythonCallSymbolicsExt.jl

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,69 +3,83 @@ module SymPyPythonCallSymbolicsExt
33
# from https://github.com/JuliaSymbolics/Symbolics.jl/pull/957/
44
# by @jClugstor
55
import SymPyPythonCall
6-
const sp = SymPyPythonCall.sympy.py
6+
#const sp = SymPyPythonCall.sympy.py
77
const PythonCall = SymPyPythonCall.PythonCall
8-
import PythonCall: Py, pyisinstance, pyconvert
8+
import PythonCall: pyconvert
99

1010
import Symbolics
1111
import Symbolics: @variables
1212

1313
# rule functions
14-
function pyconvert_rule_sympy_symbol(::Type{Symbolics.Num}, x::Py)
14+
function pyconvert_rule_sympy_symbol(::Type{Symbolics.Num}, x)
15+
#=
1516
if !pyisinstance(x,sp.Symbol)
1617
return PythonCall.pyconvert_unconverted()
1718
end
19+
=#
1820
name = PythonCall.pyconvert(Symbol,x.name)
1921
return PythonCall.pyconvert_return(Symbolics.variable(name))
2022
end
2123

22-
function pyconvert_rule_sympy_pow(::Type{Symbolics.Num}, x::Py)
24+
function pyconvert_rule_sympy_pow(::Type{Symbolics.Num}, x)
25+
#=
2326
if !pyisinstance(x,sp.Pow)
2427
return PythonCall.pyconvert_unconverted()
2528
end
29+
=#
2630
expbase = pyconvert(Symbolics.Num,x.base)
2731
exp = pyconvert(Symbolics.Num,x.exp)
2832
return PythonCall.pyconvert_return(expbase^exp)
2933
end
3034

31-
function pyconvert_rule_sympy_mul(::Type{Symbolics.Num}, x::Py)
35+
function pyconvert_rule_sympy_mul(::Type{Symbolics.Num}, x)
36+
#=
3237
if !pyisinstance(x,sp.Mul)
3338
return PythonCall.pyconvert_unconverted()
3439
end
40+
=#
3541
mult = reduce(*,PythonCall.pyconvert.(Symbolics.Num,x.args))
3642
return PythonCall.pyconvert_return(mult)
3743
end
3844

39-
function pyconvert_rule_sympy_add(::Type{Symbolics.Num}, x::Py)
45+
function pyconvert_rule_sympy_add(::Type{Symbolics.Num}, x)
46+
#=
4047
if !pyisinstance(x,sp.Add)
4148
return PythonCall.pyconvert_unconverted()
4249
end
50+
=#
4351
sum = reduce(+, PythonCall.pyconvert.(Symbolics.Num,x.args))
4452
return PythonCall.pyconvert_return(sum)
4553
end
4654

47-
function pyconvert_rule_sympy_equality(::Type{Symbolics.Equation}, x::Py)
55+
function pyconvert_rule_sympy_equality(::Type{Symbolics.Equation}, x)
56+
#=
4857
if !pyisinstance(x,sp.Equality)
4958
return PythonCall.pyconvert_unconverted()
5059
end
60+
=#
5161
rhs = pyconvert(Symbolics.Num,x.rhs)
5262
lhs = pyconvert(Symbolics.Num,x.lhs)
5363
return PythonCall.pyconvert_return(rhs ~ lhs)
5464
end
55-
function pyconvert_rule_sympy_derivative(::Type{Symbolics.Num}, x::Py)
65+
function pyconvert_rule_sympy_derivative(::Type{Symbolics.Num}, x)
66+
#=
5667
if !pyisinstance(x,sp.Derivative)
5768
return PythonCall.pyconvert_unconverted()
5869
end
70+
=#
5971
variables = pyconvert.(Symbolics.Num,x.variables)
6072
derivatives = prod(var -> Differential(var), variables)
6173
expr = pyconvert(Symbolics.Num, x.expr)
6274
return PythonCall.pyconvert_return(derivatives(expr))
6375
end
6476

65-
function pyconvert_rule_sympy_function(::Type{Symbolics.Num}, x::Py)
77+
function pyconvert_rule_sympy_function(::Type{Symbolics.Num}, x)
78+
#=
6679
if !pyisinstance(x,sp.Function)
6780
return PythonCall.pyconvert_unconverted()
6881
end
82+
=#
6983
name = pyconvert(Symbol,x.name)
7084
args = pyconvert.(Symbolics.Num,x.args)
7185
func = @variables $name(..)

0 commit comments

Comments
 (0)