Skip to content

Commit

Permalink
inst/@sym/{rdivide,times}: Use workaround for sympy <1.9.
Browse files Browse the repository at this point in the history
Otherwise, we use "hadamard_product".

Closes gnu-octave#1109.

* inst/@sym/rdivide.m: Fix it.
* inst/@sym/times.m: Fix it.
  • Loading branch information
Alex Vong authored and Alex Vong committed Jun 22, 2022
1 parent 877bfc3 commit 5c536d1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
11 changes: 10 additions & 1 deletion inst/@sym/rdivide.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
%% Copyright (C) 2014, 2016, 2018-2019 Colin B. Macdonald
%% Copyright (C) 2022 Alex Vong
%%
%% This file is part of OctSymPy.
%%
Expand Down Expand Up @@ -92,10 +93,18 @@
return
end

%% 2022-06: TODO cannot simply call hadamard_product for sympy <1.9,
%% see upstream: https://github.com/sympy/sympy/issues/8557

cmd = { '(x,y) = _ins'
'if x.is_Matrix and y.is_Matrix:'
' return x.multiply_elementwise(y.applyfunc(lambda a: 1/a)),'
' y_eltwise_recip = y.applyfunc(lambda a: 1/a)'
' if Version(spver) < Version("1.9"):'
' try:'
' return x.multiply_elementwise(y_eltwise_recip)'
' except:'
' pass'
' return hadamard_product(x, y_eltwise_recip)'
'if not x.is_Matrix and y.is_Matrix:'
' return y.applyfunc(lambda a: x/a),'
'else:'
Expand Down
15 changes: 9 additions & 6 deletions inst/@sym/times.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
%% Copyright (C) 2014, 2016, 2018-2019, 2022 Colin B. Macdonald
%% Copyright (C) 2022 Alex Vong
%%
%% This file is part of OctSymPy.
%%
Expand Down Expand Up @@ -58,17 +59,19 @@
return
end

% 2018-01: TODO cannot simply call hadamard_product, see upstream:
% https://github.com/sympy/sympy/issues/8557
%% 2022-06: TODO cannot simply call hadamard_product for sympy <1.9,
%% see upstream: https://github.com/sympy/sympy/issues/8557

cmd = { '(x,y) = _ins'
'if x is None or y is None:'
' return x*y'
'if x.is_Matrix and y.is_Matrix:'
' try:'
' return x.multiply_elementwise(y)'
' except (AttributeError, TypeError):'
' return hadamard_product(x, y)'
' if Version(spver) < Version("1.9"):'
' try:'
' return x.multiply_elementwise(y)'
' except (AttributeError, TypeError):'
' pass'
' return hadamard_product(x, y)'
'return x*y' };

z = pycall_sympy__ (cmd, sym(x), sym(y));
Expand Down

0 comments on commit 5c536d1

Please sign in to comment.