-
Notifications
You must be signed in to change notification settings - Fork 37
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] Implement @sym/class to return python class name of @sym vars #561
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
%% Copyright (C) 2016 Abhinav Tripathi and Colin B. Macdonald | ||
%% | ||
%% This file is part of Octave-Symbolic-SymPy | ||
%% | ||
%% Octave-Symbolic-SymPy is free software; you can redistribute | ||
%% it and/or modify it under the terms of the GNU General Public | ||
%% License as published by the Free Software Foundation; | ||
%% either version 3 of the License, or (at your option) any | ||
%% later version. | ||
%% | ||
%% This software is distributed in the hope that it will be useful, | ||
%% but WITHOUT ANY WARRANTY; without even the implied warranty | ||
%% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See | ||
%% the GNU General Public License for more details. | ||
%% | ||
%% You should have received a copy of the GNU General Public | ||
%% License along with this software; see the file COPYING. | ||
%% If not, see <http://www.gnu.org/licenses/>. | ||
|
||
%% -*- texinfo -*- | ||
%% @documentencoding UTF-8 | ||
%% @deftypemethod @var{c} = class (@var{x}) | ||
%% @deftypemethodx @var{c} = class (@var{x}, @var{full}) | ||
%% Return class name of the variable x. | ||
%% | ||
%% @var{full} decides if the fully qualified class name will be returned | ||
%% or not. It it true by default. | ||
%% | ||
%% Example: | ||
%% @example | ||
%% @group | ||
%% syms x | ||
%% class(x) | ||
%% @result{} ans = sympy.core.symbol.Symbol | ||
%% @end group | ||
%% @end example | ||
%% | ||
%% @example | ||
%% @group | ||
%% syms x | ||
%% class(x, false) | ||
%% @result{} ans = Symbol | ||
%% @end group | ||
%% @end example | ||
%% | ||
%% @end deftypemethod | ||
|
||
function cname = class(x, full) | ||
|
||
if (nargin > 2 || (nargin == 2 && !islogical(full))) | ||
print_usage (); | ||
end | ||
|
||
if (nargin == 1) | ||
full = true; | ||
end | ||
|
||
% TODO: if the ipc is pytave then return @pyobject instead | ||
cmd = { '(x,f) = _ins' | ||
'return (x.__module__ + "." if f else "") + x.__class__.__name__' | ||
}; | ||
|
||
cname = python_cmd (cmd, x, full); | ||
end | ||
|
||
|
||
%!error <Invalid> class (sym(1), true, 3) | ||
%!error <Invalid> class (sym(1), 2) | ||
|
||
%!test | ||
%! syms x y | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi its possible write instead of this line:
?, to test sym and symfun. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ohk. Or maybe we can have additional tests for symfuncs... This way, just to be sure, both can be tested separately. Will add a few more tests.. |
||
%! assert (class(x), 'sympy.core.symbol.Symbol') | ||
%! assert (class(x), class(x, true)) | ||
%! assert (class(x), class(y)) | ||
|
||
%!assert (class (sym (1)), 'sympy.core.numbers.One') | ||
%!assert (class (sym (1), false), 'One') | ||
|
||
%!assert (class (sym (1000)), 'sympy.core.numbers.Integer') | ||
%!assert (class (cos (sym (1))), 'sympy.functions.elementary.trigonometric.cos') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very very little thing, i think its "It its" or "Its"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops.. Thanks for pointing out, I'll fix the typo.