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

[wip] Change @sym to a classdef. #590

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
%% If not, see <http://www.gnu.org/licenses/>.

function t = assert_same_shape(x,y)
if ~(is_same_shape(x,y))
if ~(sym.is_same_shape (x, y))
error('array inputs must have same size and shape');
end

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
% not strictly necessary if sym calls this but maybe neater this way:
item = L{i};
if iscell (item)
s{i} = cell_array_to_sym (item, varargin{:});
s{i} = sym.cell_array_to_sym (item, varargin{:});
else
s{i} = sym (item, varargin{:});
end
Expand Down
2 changes: 1 addition & 1 deletion inst/@sym/charpoly.m
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
'else:'
' return _ins[0].charpoly(_ins[1]).as_expr(),'};

y = python_cmd(cmd , sym(varargin){:});
y = python_cmd(cmd , sym.symarray (varargin){:});

if (nargin == 1)
y = cell2sym(y);
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion inst/@sym/coeffs.m
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
if (nargin == 1)
[c, t] = python_cmd (cmd, sym(p), {});
else
[c, t] = python_cmd (cmd, sym(p), sym(x));
[c, t] = python_cmd (cmd, sym(p), sym.symarray (x));
end

%% matlab SMT bug?
Expand Down
2 changes: 1 addition & 1 deletion inst/@sym/diff.m
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
'args = _ins[1:]'
'return f.diff(*args),' };

varargin = sym(varargin);
varargin = sym.symarray (varargin);
z = python_cmd (cmd, sym(f), varargin{:});

end
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions inst/@sym/eye.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@
end

if (isa (varargin{nargin}, 'char'))
y = eye (cell2nosyms (varargin){:});
y = eye (sym.cell2nosyms (varargin){:});
return
end

if nargin > 1 %%Sympy don't support eye(A, B)
y = sym(eye (cell2nosyms (varargin){:}));
y = sym(eye (sym.cell2nosyms (varargin){:}));
else
y = python_cmd ('return eye(*_ins)', sym(varargin){:});
y = python_cmd ('return eye(*_ins)', sym.symarray (varargin){:});
end

end
Expand Down
2 changes: 1 addition & 1 deletion inst/@sym/factor.m
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
function [p, m] = factor(f, varargin)

f = sym(f);
varargin = sym(varargin);
varargin = sym.symarray (varargin);

if ((nargin > 1) || (~isempty (findsymbols (f))))
%% have symbols, do polynomial factorization
Expand Down
2 changes: 1 addition & 1 deletion inst/@sym/horzcat.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
'return sp.MatrixBase.hstack(*_proc),'
};

varargin = sym(varargin);
varargin = sym.symarray (varargin);
h = python_cmd (cmd, varargin{:});

end
Expand Down
2 changes: 1 addition & 1 deletion inst/@sym/hypergeom.m
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
' return z.applyfunc(lambda x: hyper(a, b, x))'
'return hyper(a, b, z)' };

F = python_cmd (cmd, sym(a), sym(b), sym(z));
F = python_cmd (cmd, sym.symarray (a), sym.symarray (b), sym(z));

end

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion inst/@sym/interval.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
print_usage();
end

varargin = sym(varargin);
varargin = sym.symarray (varargin);

I = python_cmd ('return Interval(*_ins),', varargin{:});

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@
% To run these in the test suite, you could move this mfile up to @sym.
% However, note these are generally tested elsewhere indirectly.

%!shared A,B
%! B = [1 2 3 4; 5 6 7 9; 10 11 12 13];
%! A = sym(B);
%%!shared A,B
%%! B = [1 2 3 4; 5 6 7 9; 10 11 12 13];
%%! A = sym(B);

%!assert (isequal (mat_rccross_access(A,[1 3],[2 3]), B([1 3], [2 3]) ))
%!assert (isequal (mat_rccross_access(A,1,[2 3]), B(1,[2 3]) ))
%!assert (isequal (mat_rccross_access(A,[1 2],4), B([1 2],4) ))
%!assert (isequal (mat_rccross_access(A,[2 1],[4 2]), B([2 1],[4 2]) ))
%!assert (isequal (mat_rccross_access(A,[],[]), B([],[]) ))
%%!assert (isequal (mat_rccross_access(A,[1 3],[2 3]), B([1 3], [2 3]) ))
%%!assert (isequal (mat_rccross_access(A,1,[2 3]), B(1,[2 3]) ))
%%!assert (isequal (mat_rccross_access(A,[1 2],4), B([1 2],4) ))
%%!assert (isequal (mat_rccross_access(A,[2 1],[4 2]), B([2 1],[4 2]) ))
%%!assert (isequal (mat_rccross_access(A,[],[]), B([],[]) ))
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
% To run these in the test suite, you could move this mfile up to @sym.
% However, note these are generally tested elsewhere indirectly.

%!test
%! B = [1 2 3; 5 6 7];
%! A = sym(B);
%! assert (isequal (mat_rclist_access(A,[1 2],[2 3]), [B(1,2); B(2,3)]))
%%!test
%%! B = [1 2 3; 5 6 7];
%%! A = sym(B);
%%! assert (isequal (mat_rclist_access(A,[1 2],[2 3]), [B(1,2); B(2,3)]))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I commented out the tests in all the private function files because I use runtests command to run the tests in a directory and it tries to run the tests in these files too resulting in error. I hope it's ok.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think this is unavoidable if we move them out of private/. This is b/c runtests and doctest are currently based on directory listings not methods calls.

42 changes: 21 additions & 21 deletions inst/@sym/private/mat_rclist_asgn.m → inst/@sym/mat_rclist_asgn.m
Original file line number Diff line number Diff line change
Expand Up @@ -89,27 +89,27 @@
% To run these in the test suite, you could move this mfile up to @sym.
% However, note these are generally tested elsewhere indirectly.

%!shared A, B
%! B = [1 2 3; 4 5 6];
%! A = sym(B);
%!test
%! C = B; C([1 6]) = [8 9];
%! assert (isequal (mat_rclist_asgn(A,[1 2],[1 3],sym([8 9])), C))
%%!shared A, B
%%! B = [1 2 3; 4 5 6];
%%! A = sym(B);
%%!test
%%! C = B; C([1 6]) = [8 9];
%%! assert (isequal (mat_rclist_asgn(A,[1 2],[1 3],sym([8 9])), C))

%!test
%! % rhs scalar
%! C = B; C([1 6]) = 88;
%! assert (isequal (mat_rclist_asgn(A,[1 2],[1 3],sym(88)), C))
%%!test
%%! % rhs scalar
%%! C = B; C([1 6]) = 88;
%%! assert (isequal (mat_rclist_asgn(A,[1 2],[1 3],sym(88)), C))

%!test
%! % If rhs is not a vector, make sure col-based access works
%! rhs = [18 20; 19 21];
%! C = B; C([1 2 3 4]) = rhs;
%! D = mat_rclist_asgn(A,[1 2 1 2],[1 1 2 2],sym(rhs));
%! assert (isequal (D, C))
%%!test
%%! % If rhs is not a vector, make sure col-based access works
%%! rhs = [18 20; 19 21];
%%! C = B; C([1 2 3 4]) = rhs;
%%! D = mat_rclist_asgn(A,[1 2 1 2],[1 1 2 2],sym(rhs));
%%! assert (isequal (D, C))

%!test
%! % Growth
%! C = B; C(1,5) = 10;
%! D = mat_rclist_asgn(A,1,5,sym(10));
%! assert (isequal (D, C))
%%!test
%%! % Growth
%%! C = B; C(1,5) = 10;
%%! D = mat_rclist_asgn(A,1,5,sym(10));
%%! assert (isequal (D, C))
File renamed without changes.
4 changes: 2 additions & 2 deletions inst/@sym/ones.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@
end

if (isa (varargin{nargin}, 'char'))
y = ones (cell2nosyms (varargin){:});
y = ones (sym.cell2nosyms (varargin){:});
return
end

y = python_cmd ('return ones(*_ins)', sym(varargin){:});
y = python_cmd ('return ones(*_ins)', sym.symarray (varargin){:});

end

Expand Down
2 changes: 1 addition & 1 deletion inst/@sym/size.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@

% Note: symbolic sized matrices should return double, not sym/string.

n = x.size;
n = x.symsize;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was required. Because if I used size as property in the sym class then too (weirdly) octave called the size function and did not use the property..

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that because @sym/subsref explicitly forbids public access of x.size?


% FIXME: for now, we artificially force symbolic sized objects
% (where one or more dimension is recorded as NaN) to be 1x1.
Expand Down
6 changes: 3 additions & 3 deletions inst/@sym/subs.m
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@
%% In general
% We build a list of of pairs of substitutions.

in = sym(in);
out = sym(out);
in = sym.symarray (in);
out = sym.symarray (out);



if ( (iscell(in)) || (numel(in) >= 2) )
assert_same_shape(in,out)
sym.assert_same_shape (in, out)
sublist = cell(1, numel(in));
for i = 1:numel(in)
% not really Bug #17, but I doubt if I'd have done it this
Expand Down
10 changes: 5 additions & 5 deletions inst/@sym/subsasgn.m
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,18 @@
end
end
for i = 1:length(idx.subs)
if (~ is_valid_index(idx.subs{i}))
if (~ sym.is_valid_index (idx.subs{i}))
error('OctSymPy:subsref:invalidIndices', ...
'invalid indices: should be integers or boolean');
end
end
out = mat_replace(val, idx.subs, sym(rhs));
out = sym.mat_replace (val, idx.subs, sym(rhs));
end

case '.'
assert( isa(rhs, 'sym'))
assert( ~isa(idx.subs, 'sym'))
assert( ~isa(val, 'sym'))
% assert( isa(rhs, 'sym') || isa(rhs, 'symfun'))
% assert( ~isa(idx.subs, 'sym'))
% assert( ~isa(val, 'sym'))
val.(idx.subs) = rhs;
out = val;

Expand Down
6 changes: 4 additions & 2 deletions inst/@sym/subsref.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@
end
end
for i = 1:length(idx.subs)
if (~ is_valid_index(idx.subs{i}))
if (~ sym.is_valid_index (idx.subs{i}))
error('OctSymPy:subsref:invalidIndices', ...
'invalid indices: should be integers or boolean');
end
end
out = mat_access(f, idx.subs);
out = sym.mat_access (f, idx.subs);

case '.'
fld = idx.subs;
Expand All @@ -78,6 +78,8 @@
out = f.ascii;
elseif (strcmp (fld, 'unicode'))
out = f.unicode;
elseif (strcmp (fld, 'symsize'))
out = f.symsize;
%elseif (strcmp (fld, 'extra'))
% out = f.extra;
% not part of the interface
Expand Down
Loading