Skip to content

Commit c15658c

Browse files
Alex Vongcbm755
authored andcommitted
Python header: Rename 'make_matrix_or_array' -> 'make_2d_sym'.
Generalises 'make_matrix_or_array' so that we can choose to represent non-Matrix 2D sym to be something other than an Array in the future. For example, we could use TableForm. WIP: Run 'grep -r make_matrix_or_array' to check if change is complete. Not sure if this is needed anymore as TableForm was shown to be lacking various features such as indexing and taking transpose. No other candidates are being considered at the moment. * inst/private/{python_header.py,python_ipc_native.m}: Rename function 'make_matrix_or_array' -> 'make_2d_sym', variable 'dbg_no_array' -> 'dbg_matrix_only' and adjust accordingly. * inst/@sym/private/mat_rclist_{access,asgn}.m: Adjust accordingly. * inst/@sym/vertcat.m: Adjust accordingly.
1 parent 48ddaaf commit c15658c

File tree

5 files changed

+23
-23
lines changed

5 files changed

+23
-23
lines changed

inst/@sym/private/mat_rclist_access.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
cmd = {'(A, rr, cc) = _ins'
3737
'AA = A.tolist() if isinstance(A, (MatrixBase, NDimArray)) else [[A]]'
3838
'MM = [[AA[i][j]] for i, j in zip(rr, cc)]'
39-
'M = make_matrix_or_array(MM)'
39+
'M = make_2d_sym(MM)'
4040
'return M,'};
4141

4242
rr = num2cell(int32(r-1));

inst/@sym/private/mat_rclist_asgn.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
'n = max(max(rr) + 1, nrows_A)'
8484
'm = max(max(cc) + 1, ncols_A)'
8585
'MM = [[entry(i, j) for j in range(m)] for i in range(n)]'
86-
'M = make_matrix_or_array(MM)'
86+
'M = make_2d_sym(MM)'
8787
'return M,'};
8888

8989
rr = num2cell(int32(r-1));

inst/@sym/vertcat.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
' raise ShapeError(msg)'
6161
'CCC = [as_list_of_list(x) for x in args]'
6262
'CC = flatten(CCC, levels=1)'
63-
'return make_matrix_or_array(CC)'};
63+
'return make_2d_sym(CC)'};
6464

6565
args = cellfun (@sym, varargin, 'UniformOutput', false);
6666
h = pycall_sympy__ (cmd, args{:});

inst/private/python_header.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -241,27 +241,27 @@ def octoutput(x, et):
241241

242242

243243
try:
244-
def make_matrix_or_array(it_of_it, dbg_no_array=False):
244+
def make_2d_sym(it_of_it, dbg_matrix_only=False):
245245
# should be kept in sync with the same function
246246
# defined in inst/private/python_ipc_native.m
247-
# FIXME: dbg_no_array is currently used for debugging,
248-
# remove it once sympy drops non-Expr supp in Matrix
247+
# FIXME: dbg_matrix_only is used for debugging, remove
248+
# it once sympy drops non-Expr support in Matrix
249249
"""
250-
Given an iterable of iterables of syms IT_OF_IT
251-
If all elements of IT_OF_IT are Expr,
252-
construct the corresponding Matrix.
253-
Otherwise, construct the corresponding 2D array.
250+
Given an iterable of iterables of syms IT_OF_IT.
251+
If all elements of IT_OF_IT are Expr, construct the
252+
corresponding Matrix. Otherwise, construct the
253+
corresponding non-Matrix 2D sym.
254254
"""
255255
ls_of_ls = [[elt for elt in it] for it in it_of_it]
256256
elts = flatten(ls_of_ls, levels=1)
257257
if Version(spver) <= Version("1.11.1"):
258258
# never use Array on older SymPy
259-
dbg_no_array = True
260-
if (dbg_no_array
259+
dbg_matrix_only = True
260+
if (dbg_matrix_only
261261
or all(isinstance(elt, Expr) for elt in elts)):
262262
return Matrix(ls_of_ls)
263263
else:
264-
dbout(f"make_matrix_or_array: making 2D Array...")
264+
dbout(f"make_2d_sym: constructing 2D sym...")
265265
return Array(ls_of_ls)
266266
except:
267267
echo_exception_stdout("in python_header defining fcns block 5")

inst/private/python_ipc_native.m

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,27 +111,27 @@
111111
' # should be kept in sync with the same function'
112112
' # defined in inst/private/python_header.py'
113113
' sys.stderr.write("pydebug: " + str(l) + "\n")'
114-
'def make_matrix_or_array(it_of_it, dbg_no_array=False):'
114+
'def make_2d_sym(it_of_it, dbg_matrix_only=False):'
115115
' # should be kept in sync with the same function'
116116
' # defined in inst/private/python_header.py'
117-
' # FIXME: dbg_no_array is currently used for debugging,'
118-
' # remove it once sympy drops non-Expr supp in Matrix'
117+
' # FIXME: dbg_matrix_only is used for debugging, remove'
118+
' # it once sympy drops non-Expr support in Matrix'
119119
' """'
120-
' Given an iterable of iterables of syms IT_OF_IT'
121-
' If all elements of IT_OF_IT are Expr,'
122-
' construct the corresponding Matrix.'
123-
' Otherwise, construct the corresponding 2D array.'
120+
' Given an iterable of iterables of syms IT_OF_IT.'
121+
' If all elements of IT_OF_IT are Expr, construct the'
122+
' corresponding Matrix. Otherwise, construct the'
123+
' corresponding non-Matrix 2D sym.'
124124
' """'
125125
' ls_of_ls = [[elt for elt in it] for it in it_of_it]'
126126
' elts = flatten(ls_of_ls, levels=1)'
127127
' if Version(spver) <= Version("1.11.1"):'
128128
' # never use Array on older SymPy'
129-
' dbg_no_array = True'
130-
' if (dbg_no_array'
129+
' dbg_matrix_only = True'
130+
' if (dbg_matrix_only'
131131
' or all(isinstance(elt, Expr) for elt in elts)):'
132132
' return Matrix(ls_of_ls)'
133133
' else:'
134-
' dbout(f"make_matrix_or_array: making 2D Array...")'
134+
' dbout(f"make_2d_sym: constructing 2D sym...")'
135135
' return Array(ls_of_ls)'
136136
}, newl))
137137
have_headers = true;

0 commit comments

Comments
 (0)