Skip to content

Commit 404672b

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

File tree

5 files changed

+100
-31
lines changed

5 files changed

+100
-31
lines changed

inst/@sym/subsasgn.m

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 54 additions & 9 deletions
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

Lines changed: 41 additions & 19 deletions
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
@@ -8,6 +37,7 @@
837
% x is idx.subs{1}
938
% This also gets called for "syms f(x)"
1039

40+
disp('constructor called');
1141
all_syms = true;
1242
for i = 1:length(idx.subs)
1343
all_syms = all_syms && isa(idx.subs{i}, 'sym');
@@ -18,32 +48,18 @@
1848
all_Symbols = python_cmd (cmd, idx.subs);
1949
end
2050
if (all_syms && all_Symbols)
21-
%% Make a symfun
51+
%% Make a symfun
2252
if (~isa(rhs, 'sym'))
2353
% rhs is, e.g., a double, then we call the constructor
2454
rhs = sym(rhs);
2555
end
2656
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));
4357
end
4458

4559
case '.'
46-
60+
assert (isa (rhs, 'symfun'))
61+
assert (~ isa (idx.subs, 'symfun'))
62+
assert (~ isa (val, 'symfun'))
4763
val.(idx.subs) = rhs;
4864
out = val;
4965

@@ -54,4 +70,10 @@
5470
val
5571
error('broken');
5672
end
57-
end
73+
end
74+
75+
76+
%!test
77+
%! syms x;
78+
%! f(x) = x^2;
79+
%! assert (isa (f, 'symfun'))

inst/@symfun/symfun.m

Lines changed: 1 addition & 0 deletions
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)