# HG changeset patch # User Jason Alan Palmer # Date 1402267416 14400 # Node ID bc52657a7d29457a41ab8ccc148f1b8ec9f08ccb # Parent 9ac2357f19bcf9076529903be61d1eff610b9b41 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. diff --git a/doc/interpreter/contributors.in b/doc/interpreter/contributors.in --- 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 diff --git a/libinterp/corefcn/data.cc b/libinterp/corefcn/data.cc --- 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\ diff --git a/scripts/general/isscalar.m b/scripts/general/isscalar.m 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 -## . - -## -*- 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) - diff --git a/scripts/general/module.mk b/scripts/general/module.mk --- a/scripts/general/module.mk +++ b/scripts/general/module.mk @@ -44,7 +44,6 @@ general/isequal.m \ general/isequaln.m \ general/isrow.m \ - general/isscalar.m \ general/issquare.m \ general/isvector.m \ general/loadobj.m \