Skip to content

Commit 336eddf

Browse files
Add proper copyright info and rewrite parts of code.
1 parent ba12a0e commit 336eddf

File tree

5 files changed

+99
-31
lines changed

5 files changed

+99
-31
lines changed

inst/@sym/subsasgn.m

+3-3
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@
101101
end
102102

103103
case '.'
104-
% assert( isa(rhs, 'sym') || isa(rhs, 'symfun'))
105-
% assert( ~isa(idx.subs, 'sym'))
106-
% assert( ~isa(val, 'sym'))
104+
assert( isa(rhs, 'sym'))
105+
assert( ~isa(idx.subs, 'sym'))
106+
assert( ~isa(val, 'sym'))
107107
val.(idx.subs) = rhs;
108108
out = val;
109109

inst/@sym/sym.m

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
%% Copyright (C) 2014-2016 Colin B. Macdonald
22
%% Copyright (C) 2016 Lagu
3+
%% Copyright (C) 2017 Abhinav Tripathi
34
%%
45
%% This file is part of OctSymPy.
56
%%

inst/@symfun/isequal.m

+54-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,56 @@
1-
function t = isequal(x, y)
1+
%% Copyright (C) 2017 Abhinav Tripathi
2+
%%
3+
%% This file is part of OctSymPy.
4+
%%
5+
%% OctSymPy is free software; you can redistribute it and/or modify
6+
%% it under the terms of the GNU General Public License as published
7+
%% by the Free Software Foundation; either version 3 of the License,
8+
%% or (at your option) any later version.
9+
%%
10+
%% This software is distributed in the hope that it will be useful,
11+
%% but WITHOUT ANY WARRANTY; without even the implied warranty
12+
%% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13+
%% the GNU General Public License for more details.
14+
%%
15+
%% You should have received a copy of the GNU General Public
16+
%% License along with this software; see the file COPYING.
17+
%% If not, see <http://www.gnu.org/licenses/>.
218

3-
if (isa (x, 'symfun'))
4-
x = x.sym;
5-
end
6-
if (isa (y, 'symfun'))
7-
y = y.sym;
8-
end
19+
%% -*- texinfo -*-
20+
%% @documentencoding UTF-8
21+
%% @defmethod @@sym isequal (@var{f}, @var{g})
22+
%% @defmethodx @@sym isequal (@var{f}, @var{g}, @dots{})
23+
%% Test if contents of two or more symfuns are equal.
24+
%%
25+
%% Example:
26+
%% @example
27+
%% @group
28+
%% syms x
29+
%% f(x) = x;
30+
%% isequal (f(x), x)
31+
%% @result{} 1
32+
%% @end group
33+
%% @end example
34+
%%
35+
%% @seealso{@@sym/isequal}
36+
%% @end defmethod
937

10-
t = isequal(x, y);
11-
end
38+
function t = isequal (x, y, varargin)
39+
40+
t = isequal@sym (x, y, varargin{:});
41+
42+
end
43+
44+
45+
%!test
46+
%! syms x;
47+
%! f(x) = x^2;
48+
%! g(x) = x^2;
49+
%! assert (isequal (f(x), g(x)))
50+
%! assert (isequal (f(x), x^2))
51+
52+
%!test
53+
%! syms x y;
54+
%! f(x) = x^2;
55+
%! g(y) = y^2;
56+
%! assert (isequal (f(x), g(x)))

inst/@symfun/subsasgn.m

+40-19
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
1+
%% Copyright (C) 2017 Abhinav Tripathi
2+
%%
3+
%% This file is part of OctSymPy.
4+
%%
5+
%% OctSymPy is free software; you can redistribute it and/or modify
6+
%% it under the terms of the GNU General Public License as published
7+
%% by the Free Software Foundation; either version 3 of the License,
8+
%% or (at your option) any later version.
9+
%%
10+
%% This software is distributed in the hope that it will be useful,
11+
%% but WITHOUT ANY WARRANTY; without even the implied warranty
12+
%% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13+
%% the GNU General Public License for more details.
14+
%%
15+
%% You should have received a copy of the GNU General Public
16+
%% License along with this software; see the file COPYING.
17+
%% If not, see <http://www.gnu.org/licenses/>.
18+
19+
%% -*- texinfo -*-
20+
%% @documentencoding UTF-8
21+
%% @deftypeop Method @@sym {@var{f} =} subsasgn (@var{f}, @var{idx}, @var{rhs})
22+
%% @deftypeopx Operator @@sym {} {@var{f}(@var{i}) = @var{rhs}} {}
23+
%% @deftypeopx Operator @@sym {} {@var{f}(@var{i}, @var{j}) = @var{rhs}} {}
24+
%% @deftypeopx Operator @@sym {} {@var{f}(@var{i}:@var{j}) = @var{rhs}} {}
25+
%% @deftypeopx Operator @@sym {} {@var{f}(@var{x}) = @var{symexpr}} {}
26+
%% Assign value to a symbolic function [constructor].
27+
%%
28+
%% @end deftypeop
29+
130
function out = subsasgn (val, idx, rhs)
231

332
switch idx.type
@@ -18,32 +47,18 @@
1847
all_Symbols = python_cmd (cmd, idx.subs);
1948
end
2049
if (all_syms && all_Symbols)
21-
%% Make a symfun
50+
%% Make a symfun
2251
if (~isa(rhs, 'sym'))
2352
% rhs is, e.g., a double, then we call the constructor
2453
rhs = sym(rhs);
2554
end
2655
out = symfun(rhs, idx.subs);
27-
28-
else
29-
%% Not symfun: e.g., f(double) = ..., f(sym(2)) = ...,
30-
% convert any sym subs to double and do array assign
31-
for i = 1:length(idx.subs)
32-
if (isa(idx.subs{i}, 'sym'))
33-
idx.subs{i} = double(idx.subs{i});
34-
end
35-
end
36-
for i = 1:length(idx.subs)
37-
if (~ sym.is_valid_index (idx.subs{i}))
38-
error('OctSymPy:subsref:invalidIndices', ...
39-
'invalid indices: should be integers or boolean');
40-
end
41-
end
42-
out = sym.mat_replace (val, idx.subs, sym(rhs));
4356
end
4457

4558
case '.'
46-
59+
assert (isa (rhs, 'symfun'))
60+
assert (~ isa (idx.subs, 'symfun'))
61+
assert (~ isa (val, 'symfun'))
4762
val.(idx.subs) = rhs;
4863
out = val;
4964

@@ -54,4 +69,10 @@
5469
val
5570
error('broken');
5671
end
57-
end
72+
end
73+
74+
75+
%!test
76+
%! syms x;
77+
%! f(x) = x^2;
78+
%! assert (isa (f, 'symfun'))

inst/@symfun/symfun.m

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
%% Copyright (C) 2014-2016 Colin B. Macdonald
2+
%% Copyright (C) 2017 Abhinav Tripathi
23
%%
34
%% This file is part of OctSymPy.
45
%%

0 commit comments

Comments
 (0)