Mercurial > hg > octave-jordi
changeset 18818:4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
* data.cc (Fisvector, Fisrow, Fiscolumn, Fissquare): Functions promoted from
m-files to C++ implementations.
module.mk: Remove isvector.m, isrow.m, iscolumn.m, issquare.m from
build system.
* iscolumn.m, isrow.m, issquare.m, isvector.m: Deleted m-files.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 08 Jun 2014 22:29:44 -0700 |
parents | bc52657a7d29 |
children | 19a140e93b1f |
files | libinterp/corefcn/data.cc scripts/general/iscolumn.m scripts/general/isrow.m scripts/general/issquare.m scripts/general/isvector.m scripts/general/module.mk |
diffstat | 6 files changed, 163 insertions(+), 236 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/data.cc +++ b/libinterp/corefcn/data.cc @@ -3686,6 +3686,128 @@ %!error isscalar (1, 2) */ +DEFUN (isvector, args, , + "-*- texinfo -*-\n\ +@deftypefn {Function File} {} isvector (@var{x})\n\ +Return true if @var{x} is a vector.\n\ +\n\ +A vector is a 2-D array where one of the dimensions is equal to 1. As a\n\ +consequence a 1x1 array, or scalar, is also a vector.\n\ +@seealso{isscalar, ismatrix, size, rows, columns, length}\n\ +@end deftypefn") +{ + octave_value retval; + + if (args.length () == 1) + { + dim_vector sz = args(0).dims (); + retval = sz.length () == 2 && (sz(0) == 1 || sz(1) == 1); + } + else + print_usage (); + + return retval; +} + +/* +%!assert (isvector (1)) +%!assert (isvector ([1; 2; 3])) +%!assert (isvector ([]), false) +%!assert (isvector ([1, 2; 3, 4]), false) + +%!assert (isvector ("t")) +%!assert (isvector ("test")) +%!assert (isvector (["test"; "ing"]), false) + +%!test +%! s.a = 1; +%! assert (isvector (s)); + +%% Test input validation +%!error isvector () +%!error isvector ([1, 2], 2) +*/ + +DEFUN (isrow, args, , + "-*- texinfo -*-\n\ +@deftypefn {Function File} {} isrow (@var{x})\n\ +Return true if @var{x} is a row vector.\n\ +@seealso{iscolumn, isscalar, isvector, ismatrix}\n\ +@end deftypefn") +{ + octave_value retval; + + if (args.length () == 1) + { + dim_vector sz = args(0).dims (); + retval = sz.length () == 2 && sz(0) == 1; + } + else + print_usage (); + + return retval; +} + +/* +%!assert (isrow ([1, 2, 3])) +%!assert (isrow ([1; 2; 3]), false) +%!assert (isrow (1)) +%!assert (isrow ([]), false) +%!assert (isrow ([1, 2; 3, 4]), false) + +%!assert (isrow ("t")) +%!assert (isrow ("test")) +%!assert (isrow (["test"; "ing"]), false) + +%!test +%! s.a = 1; +%! assert (isrow (s)); + +%% Test input validation +%!error isrow () +%!error isrow ([1, 2], 2) +*/ + +DEFUN (iscolumn, args, , + "-*- texinfo -*-\n\ +@deftypefn {Function File} {} iscolumn (@var{x})\n\ +Return true if @var{x} is a column vector.\n\ +@seealso{isrow, isscalar, isvector, ismatrix}\n\ +@end deftypefn") +{ + octave_value retval; + + if (args.length () == 1) + { + dim_vector sz = args(0).dims (); + retval = sz.length () == 2 && sz(1) == 1; + } + else + print_usage (); + + return retval; +} + +/* +%!assert (iscolumn ([1, 2, 3]), false) +%!assert (iscolumn ([1; 2; 3])) +%!assert (iscolumn (1)) +%!assert (iscolumn ([]), false) +%!assert (iscolumn ([1, 2; 3, 4]), false) + +%!assert (iscolumn ("t")) +%!assert (iscolumn ("test"), false) +%!assert (iscolumn (["test"; "ing"]), false) + +%!test +%! s.a = 1; +%! assert (iscolumn (s)); + +%% Test input validation +%!error iscolumn () +%!error iscolumn ([1, 2], 2) +*/ + DEFUN (ismatrix, args, , "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} ismatrix (@var{a})\n\ @@ -3736,6 +3858,47 @@ %!error ismatrix ([1, 2; 3, 4], 2) */ +DEFUN (issquare, args, , + "-*- texinfo -*-\n\ +@deftypefn {Function File} {} issquare (@var{x})\n\ +Return true if @var{x} is a square matrix.\n\ +@seealso{isscalar, isvector, ismatrix, size}\n\ +@end deftypefn") +{ + octave_value retval; + + if (args.length () == 1) + { + dim_vector sz = args(0).dims (); + retval = sz.length () == 2 && sz(0) == sz(1); + } + else + print_usage (); + + return retval; +} + +/* +%!assert (issquare ([])) +%!assert (issquare (1)) +%!assert (! issquare ([1, 2])) +%!assert (issquare ([1, 2; 3, 4])) +%!assert (! issquare ([1, 2; 3, 4; 5, 6])) +%!assert (! issquare (ones (3,3,3))) +%!assert (issquare ("t")) +%!assert (! issquare ("test")) +%!assert (issquare (["test"; "ing"; "1"; "2"])) +%!test +%! s.a = 1; +%! assert (issquare (s)); +%!assert (issquare ({1, 2; 3, 4})) +%!assert (sparse (([1, 2; 3, 4]))) + +%% Test input validation +%!error issquare () +%!error issquare ([1, 2; 3, 4], 2) +*/ + static octave_value fill_matrix (const octave_value_list& args, int val, const char *fcn) {
deleted file mode 100644 --- a/scripts/general/iscolumn.m +++ /dev/null @@ -1,56 +0,0 @@ -## Copyright (C) 2012-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} {} iscolumn (@var{x}) -## Return true if @var{x} is a column vector. -## @seealso{isrow, isscalar, isvector, ismatrix} -## @end deftypefn - -## Author: Rik Wehbring - -function retval = iscolumn (x) - - if (nargin != 1) - print_usage (); - endif - - sz = size (x); - retval = (ndims (x) == 2 && (sz(2) == 1)); - -endfunction - - -%!assert (iscolumn ([1, 2, 3]), false) -%!assert (iscolumn ([1; 2; 3])) -%!assert (iscolumn (1)) -%!assert (iscolumn ([]), false) -%!assert (iscolumn ([1, 2; 3, 4]), false) - -%!assert (iscolumn ("t")) -%!assert (iscolumn ("test"), false) -%!assert (iscolumn (["test"; "ing"]), false) - -%!test -%! s.a = 1; -%! assert (iscolumn (s)); - -%% Test input validation -%!error iscolumn () -%!error iscolumn ([1, 2], 2) -
deleted file mode 100644 --- a/scripts/general/isrow.m +++ /dev/null @@ -1,56 +0,0 @@ -## Copyright (C) 2012-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} {} isrow (@var{x}) -## Return true if @var{x} is a row vector. -## @seealso{iscolumn, isscalar, isvector, ismatrix} -## @end deftypefn - -## Author: Rik Wehbring - -function retval = isrow (x) - - if (nargin != 1) - print_usage (); - endif - - sz = size (x); - retval = (ndims (x) == 2 && (sz(1) == 1)); - -endfunction - - -%!assert (isrow ([1, 2, 3])) -%!assert (isrow ([1; 2; 3]), false) -%!assert (isrow (1)) -%!assert (isrow ([]), false) -%!assert (isrow ([1, 2; 3, 4]), false) - -%!assert (isrow ("t")) -%!assert (isrow ("test")) -%!assert (isrow (["test"; "ing"]), false) - -%!test -%! s.a = 1; -%! assert (isrow (s)); - -%% Test input validation -%!error isrow () -%!error isrow ([1, 2], 2) -
deleted file mode 100644 --- a/scripts/general/issquare.m +++ /dev/null @@ -1,63 +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} {} issquare (@var{x}) -## Return true if @var{x} is a square matrix. -## @seealso{isscalar, isvector, ismatrix, size} -## @end deftypefn - -## Author: A. S. Hodel <scotte@eng.auburn.edu> -## Created: August 1993 -## Adapted-By: jwe - -function retval = issquare (x) - - if (nargin != 1) - print_usage (); - endif - - if (ndims (x) == 2) - [r, c] = size (x); - retval = r == c; - else - retval = false; - endif - -endfunction - - -%!assert (issquare ([])) -%!assert (issquare (1)) -%!assert (! issquare ([1, 2])) -%!assert (issquare ([1, 2; 3, 4])) -%!assert (! issquare ([1, 2; 3, 4; 5, 6])) -%!assert (! issquare (ones (3,3,3))) -%!assert (issquare ("t")) -%!assert (! issquare ("test")) -%!assert (issquare (["test"; "ing"; "1"; "2"])) -%!test -%! s.a = 1; -%! assert (issquare (s)); -%!assert (issquare ({1, 2; 3, 4})) -%!assert (sparse (([1, 2; 3, 4]))) - -%% Test input validation -%!error issquare () -%!error issquare ([1, 2; 3, 4], 2) -
deleted file mode 100644 --- a/scripts/general/isvector.m +++ /dev/null @@ -1,57 +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} {} isvector (@var{x}) -## Return true if @var{x} is a vector. A vector is a 2-D array -## where one of the dimensions is equal to 1. As a consequence a -## 1x1 array, or scalar, is also a vector. -## @seealso{isscalar, ismatrix, size, rows, columns, length} -## @end deftypefn - -## Author: jwe - -function retval = isvector (x) - - if (nargin != 1) - print_usage (); - endif - - sz = size (x); - retval = (ndims (x) == 2 && (sz(1) == 1 || sz(2) == 1)); - -endfunction - - -%!assert (isvector (1)) -%!assert (isvector ([1; 2; 3])) -%!assert (isvector ([]), false) -%!assert (isvector ([1, 2; 3, 4]), false) - -%!assert (isvector ("t")) -%!assert (isvector ("test")) -%!assert (isvector (["test"; "ing"]), false) - -%!test -%! s.a = 1; -%! assert (isvector (s)); - -%% Test input validation -%!error isvector () -%!error isvector ([1, 2], 2) -
--- a/scripts/general/module.mk +++ b/scripts/general/module.mk @@ -39,13 +39,9 @@ general/interp3.m \ general/interpn.m \ general/interpft.m \ - general/iscolumn.m \ general/isdir.m \ general/isequal.m \ general/isequaln.m \ - general/isrow.m \ - general/issquare.m \ - general/isvector.m \ general/loadobj.m \ general/logspace.m \ general/methods.m \