changeset 8887:6e4a811e58f8

deprecate create_set
author John W. Eaton <jwe@octave.org>
date Fri, 27 Feb 2009 14:49:28 -0500
parents 0c1a9c178fdd
children 0c7b0049c023
files doc/ChangeLog doc/interpreter/set.txi scripts/ChangeLog scripts/deprecated/Makefile.in scripts/deprecated/create_set.m scripts/set/Makefile.in scripts/set/complement.m scripts/set/create_set.m scripts/set/unique.m
diffstat 9 files changed, 113 insertions(+), 93 deletions(-) [+]
line wrap: on
line diff
--- a/doc/ChangeLog	Fri Feb 27 12:56:31 2009 -0500
+++ b/doc/ChangeLog	Fri Feb 27 14:49:28 2009 -0500
@@ -1,3 +1,7 @@
+2009-02-27  John W. Eaton  <jwe@octave.org>
+
+	* interpreter/set.txi (Sets): Don't document create_set.
+
 2009-02-26  John W. Eaton  <jwe@octave.org>
 
 	* interpreter/strings.txi (Manipulating Strings):
--- a/doc/interpreter/set.txi	Fri Feb 27 12:56:31 2009 -0500
+++ b/doc/interpreter/set.txi	Fri Feb 27 14:49:28 2009 -0500
@@ -23,8 +23,6 @@
 set is defined as a collection of unique elements.  In Octave a set is
 represented as a vector of numbers.
 
-@DOCSTRING(create_set)
-
 @DOCSTRING(unique)
 
 @menu
--- a/scripts/ChangeLog	Fri Feb 27 12:56:31 2009 -0500
+++ b/scripts/ChangeLog	Fri Feb 27 14:49:28 2009 -0500
@@ -1,5 +1,12 @@
 2009-02-27  John W. Eaton  <jwe@octave.org>
 
+	* set/complement.m: Call unique, not create_set.
+	* set/unique.m: Style fix for docstring.
+	* deprecated/create_set.m: Move here from set/create_set.m.
+	Always return a row vector, as documented.
+	* set/Makefile.in (SOURCES): Remove create_set.m from the list.
+	* deprecated/Makefile.in (SOURCES): Add create_set.m to the list.
+
 	* general/num2str.m: Call strsplit instead of split.
 
 	* strings/strsplit.m: Style fixes.
--- a/scripts/deprecated/Makefile.in	Fri Feb 27 12:56:31 2009 -0500
+++ b/scripts/deprecated/Makefile.in	Fri Feb 27 14:49:28 2009 -0500
@@ -35,7 +35,8 @@
 SOURCES = beta_cdf.m beta_inv.m beta_pdf.m beta_rnd.m \
   binomial_cdf.m binomial_inv.m binomial_pdf.m binomial_rnd.m \
   chisquare_cdf.m chisquare_inv.m chisquare_pdf.m chisquare_rnd.m \
-  clearplot.m clg.m com2str.m dmult.m exponential_cdf.m exponential_inv.m \
+  clearplot.m clg.m com2str.m create_set.m \
+  dmult.m exponential_cdf.m exponential_inv.m \
   exponential_pdf.m exponential_rnd.m f_cdf.m f_inv.m f_pdf.m \
   f_rnd.m gamma_cdf.m gamma_inv.m gamma_pdf.m gamma_rnd.m \
   geometric_cdf.m geometric_inv.m geometric_pdf.m geometric_rnd.m \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/deprecated/create_set.m	Fri Feb 27 14:49:28 2009 -0500
@@ -0,0 +1,80 @@
+## Copyright (C) 1994, 1996, 1997, 1999, 2000, 2004, 2005, 2006, 2007, 2008
+##               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} {} create_set (@var{x})
+## @deftypefnx{Function File} {} create_set (@var{x}, "rows")
+## This function has been deprecated.  Use unique instead.
+## @end deftypefn
+
+## Return a row vector containing the unique values in @var{x}, sorted in
+## ascending order.  For example,
+##
+## @example
+## @group
+## create_set ([ 1, 2; 3, 4; 4, 2; 1, 2 ])
+##      @result{} [ 1, 2, 3, 4 ]
+## @end group
+## @end example
+##
+## If the optional second input argument is the string "rows" each row of
+## the matrix @var{x} will be considered an element of set.  For example,
+## @example
+## @group
+## create_set ([ 1, 2; 3, 4; 4, 2; 1, 2 ], "rows")
+##      @result{}  1   2
+##     3   4
+##     4   2
+## @end group
+## @end example
+## @seealso{union, intersect, complement, unique}
+
+## Author: jwe
+
+## Deprecated in version 3.0
+
+function y = create_set (x, rows_opt)
+
+  persistent warned = false;
+  if (! warned)
+    warned = true;
+    warning ("Octave:deprecated-function",
+             "create_set is obsolete and will be removed from a future version of Octave, please use unique instead");
+  endif
+
+  if (nargin < 1 || nargin > 2)
+    print_usage ();
+  endif
+  
+  if (nargin == 1)
+    y = unique (x)(:)';
+  elseif (strcmpi (rows_opt, "rows"))
+    y = unique (x, "rows");
+  else
+    error ("create_set: expecting \"rows\" as second argument");
+  endif
+
+endfunction
+
+%!assert(all (all (create_set ([1, 2, 3, 4, 2, 4]) == [1, 2, 3, 4])));
+%!assert(all (all (create_set ([1, 2; 3, 4; 2, 4]) == [1, 2, 3, 4])));
+%!assert(all (all (create_set ([1; 2; 3; 4; 2; 4]) == [1, 2, 3, 4])));
+%!assert(isempty (create_set ([])));
+%!error create_set (1, 2);
+
--- a/scripts/set/Makefile.in	Fri Feb 27 12:56:31 2009 -0500
+++ b/scripts/set/Makefile.in	Fri Feb 27 14:49:28 2009 -0500
@@ -33,7 +33,7 @@
 INSTALL_PROGRAM = @INSTALL_PROGRAM@
 INSTALL_DATA = @INSTALL_DATA@
 
-SOURCES = complement.m create_set.m intersect.m ismember.m \
+SOURCES = complement.m intersect.m ismember.m \
   setdiff.m setxor.m union.m unique.m
 
 DISTFILES = $(addprefix $(srcdir)/, Makefile.in $(SOURCES))
--- a/scripts/set/complement.m	Fri Feb 27 12:56:31 2009 -0500
+++ b/scripts/set/complement.m	Fri Feb 27 14:49:28 2009 -0500
@@ -40,12 +40,12 @@
   endif
 
   if (isempty (a))
-    y = create_set(b);
+    y = unique (b);
   elseif (isempty (b))
     y = [];
   else
-    a = create_set (a);
-    b = create_set (b);
+    a = unique (a);
+    b = unique (b);
     yindex = 1;
     y = zeros (1, length (b));
     for index = 1:length (b)
--- a/scripts/set/create_set.m	Fri Feb 27 12:56:31 2009 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,71 +0,0 @@
-## Copyright (C) 1994, 1996, 1997, 1999, 2000, 2004, 2005, 2006, 2007, 2008
-##               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} {} create_set (@var{x})
-## @deftypefnx{Function File} {} create_set (@var{x}, "rows")
-## Return a row vector containing the unique values in @var{x}, sorted in
-## ascending order.  For example,
-##
-## @example
-## @group
-## create_set ([ 1, 2; 3, 4; 4, 2; 1, 2 ])
-##      @result{} [ 1, 2, 3, 4 ]
-## @end group
-## @end example
-##
-## If the optional second input argument is the string "rows" each row of
-## the matrix @var{x} will be considered an element of set.  For example,
-## @example
-## @group
-## create_set ([ 1, 2; 3, 4; 4, 2; 1, 2 ], "rows")
-##      @result{}  1   2
-##     3   4
-##     4   2
-## @end group
-## @end example
-## @seealso{union, intersect, complement, unique}
-## @end deftypefn
-
-## Author: jwe
-
-function y = create_set (x, rows_opt)
-
-  if (nargin < 1 || nargin > 2)
-    print_usage ();
-  endif
-  
-  if (nargin == 1)
-    y = unique (x).';
-  elseif (strcmpi (rows_opt, "rows"))
-    y = unique (x, "rows");
-  else
-    error ("create_set: expecting \"rows\" as second argument");
-  endif
-
-endfunction
-
-%!assert(all (all (create_set ([1, 2; 3, 4; 2, 4]) == [1, 2, 3, 4])));
-
-%!assert(all (all (create_set ([1; 2; 3; 4; 2; 4]) == [1, 2, 3, 4])));
-
-%!assert(isempty (create_set ([])));
-
-%!error create_set (1, 2);
-
--- a/scripts/set/unique.m	Fri Feb 27 12:56:31 2009 -0500
+++ b/scripts/set/unique.m	Fri Feb 27 14:49:28 2009 -0500
@@ -19,23 +19,24 @@
 
 ## -*- texinfo -*-
 ## @deftypefn {Function File} {} unique (@var{x})
-##
+## @deftypefnx {Function File} {} unique (@var{x}, "rows")
+## @deftypefnx {Function File} {} unique (@dots{}, "first")
+## @deftypefnx {Function File} {} unique (@dots{}, "last")
+## @deftypefnx {Function File} {[@var{y}, @var{i}, @var{j}] =} unique (@dots{})
 ## Return the unique elements of @var{x}, sorted in ascending order.
 ## If @var{x} is a row vector, return a row vector, but if @var{x}
 ## is a column vector or a matrix return a column vector.
 ##
-## @deftypefnx {Function File} {} unique (@var{A}, 'rows')
-##
-## Return the unique rows of @var{A}, sorted in ascending order.
-##
-## @deftypefnx {Function File} {[@var{y}, @var{i}, @var{j}] =} unique (@var{x})
+## If the optional argument @code{"rows"} is supplied, return the unique
+## rows of @var{x}, sorted in ascending order.
 ##
-## Return index vectors @var{i} and @var{j} such that @code{x(i)==y} and
-## @code{y(j)==x}.
-## 
-## Additionally, one of 'first' or 'last' can be given as an argument.
-## 'last' (default) specifies that the highest possible indices are returned
-## in @var{i}, while 'first' means the lowest.
+## If requested, return index vectors @var{i} and @var{j} such that
+## @code{x(i)==y} and @code{y(j)==x}.
+##
+## Additionally, one of @code{"first"} or @code{"last"} may be given as
+## an argument.  If @code{"last"} is specified, return the highest
+## possible indices in @var{i}, otherwise, if @code{"first"} is
+## specified, return the lowest.  The default is @code{"last"}.
 ## @seealso{union, intersect, setdiff, setxor, ismember}
 ## @end deftypefn
 
@@ -50,9 +51,9 @@
     ## parse options
     if (iscellstr (varargin))
       varargin = unique (varargin);
-      optfirst = strmatch ('first', varargin) > 0;
-      optlast = strmatch ('last', varargin) > 0;
-      optrows = strmatch ('rows', varargin) > 0 && size (x, 2) > 1;
+      optfirst = strmatch ("first", varargin) > 0;
+      optlast = strmatch ("last", varargin) > 0;
+      optrows = strmatch ("rows", varargin) > 0 && size (x, 2) > 1;
       if (optfirst && optlast)
         error ("unique: cannot specify both \"last\" and \"first\"");
       elseif (optfirst + optlast + optrows != nargin-1)