Mercurial > hg > octave-jordi
changeset 18817:bc52657a7d29
Convert isscalar from an m-file to a built-in function (bug #42422).
* libinterp/corefcn/data.cc: add isscalar built-in function
* scripts/general/isscalar.m: delete file
* scripts/general/module.mk: remove isscalar.m from build system
* doc/interpreter/contributors.in: Add Jason Alan Palmer to list.
author | Jason Alan Palmer <jalanpalmer@gmail.com> |
---|---|
date | Sun, 08 Jun 2014 18:43:36 -0400 |
parents | 9ac2357f19bc |
children | 4f0e4f20a33f |
files | doc/interpreter/contributors.in libinterp/corefcn/data.cc scripts/general/isscalar.m scripts/general/module.mk |
diffstat | 4 files changed, 37 insertions(+), 55 deletions(-) [+] |
line wrap: on
line diff
--- a/doc/interpreter/contributors.in +++ b/doc/interpreter/contributors.in @@ -224,6 +224,7 @@ Carl Osterwisch Janne Olavi Paanajärvi Scott Pakin +Jason Alan Palmer Gabriele Pannocchia Sylvain Pelissier Per Persson
--- a/libinterp/corefcn/data.cc +++ b/libinterp/corefcn/data.cc @@ -3650,6 +3650,42 @@ %!assert (isnumeric (sparse ([true, false])), false) */ +DEFUN (isscalar, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} isscalar (@var{x})\n\ +Return true if @var{x} is a scalar.\n\ +@seealso{isvector, ismatrix}\n\ +@end deftypefn") +{ + octave_value retval; + + if (args.length () == 1) + retval = args(0).numel () == 1; + else + print_usage (); + + return retval; +} + +/* +%!assert (isscalar (1)) +%!assert (isscalar ([1, 2]), false) +%!assert (isscalar ([]), false) +%!assert (isscalar ([1, 2; 3, 4]), false) + +%!assert (isscalar ("t")) +%!assert (isscalar ("test"), false) +%!assert (isscalar (["test"; "ing"]), false) + +%!test +%! s.a = 1; +%! assert (isscalar (s)); + +%% Test input validation +%!error isscalar () +%!error isscalar (1, 2) +*/ + DEFUN (ismatrix, args, , "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} ismatrix (@var{a})\n\
deleted file mode 100644 --- a/scripts/general/isscalar.m +++ /dev/null @@ -1,54 +0,0 @@ -## Copyright (C) 1996-2013 John W. Eaton -## -## This file is part of Octave. -## -## Octave 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. -## -## Octave 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 Octave; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} isscalar (@var{x}) -## Return true if @var{x} is a scalar. -## @seealso{isvector, ismatrix} -## @end deftypefn - -## Author: jwe - -function retval = isscalar (x) - - if (nargin != 1) - print_usage (); - endif - - retval = numel (x) == 1; - -endfunction - - -%!assert (isscalar (1)) -%!assert (isscalar ([1, 2]), false) -%!assert (isscalar ([]), false) -%!assert (isscalar ([1, 2; 3, 4]), false) - -%!assert (isscalar ("t")) -%!assert (isscalar ("test"), false) -%!assert (isscalar (["test"; "ing"]), false) - -%!test -%! s.a = 1; -%! assert (isscalar (s)); - -%% Test input validation -%!error isscalar () -%!error isscalar (1, 2) -