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

subs: use make_matrix_or_array and use 2-d indexing #1227

Merged
merged 3 commits into from
Sep 6, 2022
Merged
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
2 changes: 1 addition & 1 deletion inst/@sym/private/mat_rclist_asgn.m
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
' elif i < nrows_A and j < ncols_A:'
' return AA[i][j]'
' else:'
' return 0'
' return S.Zero'
'n = max(max(rr) + 1, nrows_A)'
'm = max(max(cc) + 1, ncols_A)'
'MM = [[entry(i, j) for j in range(m)] for i in range(n)]'
Expand Down
9 changes: 5 additions & 4 deletions inst/@sym/reshape.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%% Copyright (C) 2014, 2016, 2019 Colin B. Macdonald
%% Copyright (C) 2014, 2016, 2019, 2022 Colin B. Macdonald
%%
%% This file is part of OctSymPy.
%%
Expand Down Expand Up @@ -75,9 +75,10 @@

cmd = {
'(A, n, m) = _ins'
'if A is not None and A.is_Matrix:'
' #sympy is row-based'
' return A.T.reshape(m,n).T'
'if isinstance(A, (MatrixBase, NDimArray)):'
' #sympy is row-based, but Array does not have .T'
' #return A.T.reshape(m,n).T'
' return transpose(transpose(A).reshape(m, n))'
'else:'
' if n != 1 or m != 1:'
' raise ValueError("cannot reshape scalar to non-1x1 size")'
Expand Down
16 changes: 8 additions & 8 deletions inst/@sym/subs.m
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,14 @@
'sizes = {(a.shape if a.is_Matrix else (1, 1)) for a in yy}'
'sizes.discard((1, 1))'
'assert len(sizes) == 1, "all substitions must be same size or scalar"'
'size = sizes.pop()'
'numel = prod(size)'
'g = [0]*numel'
'for i in range(len(g)):'
' yyy = [y[i] if y.is_Matrix else y for y in yy]'
' sublist = list(zip(xx, yyy))'
' g[i] = f.subs(sublist, simultaneous=True).doit()'
'return Matrix(*size, g)'
'm, n = sizes.pop()'
'g = [[0]*n for i in range(m)]'
'for i in range(m):'
' for j in range(n):'
' yyy = [y[i, j] if y.is_Matrix else y for y in yy]'
' sublist = list(zip(xx, yyy))'
' g[i][j] = f.subs(sublist, simultaneous=True).doit()'
'return make_matrix_or_array(g)'
};

g = pycall_sympy__ (cmd, f, in, out);
Expand Down