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] Implement @sym/class to return python class name of @sym vars #561

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
80 changes: 80 additions & 0 deletions inst/@sym/class.m
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.
Copy link
Contributor

@latot latot Sep 20, 2016

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"

Copy link
Contributor Author

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.

%%
%% 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
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi its possible write instead of this line:

syms f(x, y)

?, to test sym and symfun.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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')