Skip to content

Commit

Permalink
Use a SymPy Array not a Matrix for non-Expr
Browse files Browse the repository at this point in the history
It has mostly the same semantics as Matrix but can contain more general
things.  There might be some issues about different shapes of empties
though...  WIP on a fix for #1052.
  • Loading branch information
cbm755 authored and Alex Vong committed Aug 29, 2022
1 parent 62ff091 commit a7c44c0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 6 additions & 3 deletions inst/@sym/private/elementwise_op.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%% Copyright (C) 2014, 2016, 2018-2019, 2022 Colin B. Macdonald
%% Copyright (C) 2014, 2016, 2018-2019, 2021-2022 Colin B. Macdonald
%% Copyright (C) 2016 Lagu
%%
%% This file is part of OctSymPy.
Expand Down Expand Up @@ -84,7 +84,7 @@
% Make sure all matrices in the input are the same size, and set q to one of them
'q = None'
'for A in _ins:'
' if isinstance(A, MatrixBase):'
' if isinstance(A, (MatrixBase, NDimArray)):'
' if q is None:'
' q = A'
' else:'
Expand All @@ -97,7 +97,10 @@
'elements = []'
'for i in range(0, len(q)):'
' elements.append(_op(*[k[i] if isinstance(k, MatrixBase) else k for k in _ins]))'
'return Matrix(*q.shape, elements)' ];
'if all(isinstance(x, Expr) for x in elements):'
' return Matrix(*q.shape, elements)'
'dbout(f"elementwise_op: returning an Array not a Matrix")'
'return Array(elements, shape=q.shape)' ];

z = pycall_sympy__ (cmd, varargin{:});

Expand Down
5 changes: 4 additions & 1 deletion inst/private/python_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def octoutput(x, et):
f.text = str(OCTCODE_BOOL)
f = ET.SubElement(a, "f")
f.text = str(x)
elif x is None or isinstance(x, (sp.Basic, sp.MatrixBase)):
elif x is None or isinstance(x, (sp.Basic, sp.MatrixBase, sp.NDimArray)):
# FIXME: is it weird to pretend None is a SymPy object?
if isinstance(x, (sp.Matrix, sp.ImmutableMatrix)):
_d = x.shape
Expand All @@ -161,6 +161,9 @@ def octoutput(x, et):
_d = [float(r) if (isinstance(r, sp.Basic) and r.is_Integer)
else float('nan') if isinstance(r, sp.Basic)
else r for r in x.shape]
elif isinstance(x, sp.NDimArray):
_d = x.shape
dbout(f"I am here with an array with shape {_d}")
elif x is None:
_d = (1,1)
else:
Expand Down

0 comments on commit a7c44c0

Please sign in to comment.