Mercurial > hg > octave-lyh
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 | 8 files changed, 47 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -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 +++ b/doc/interpreter/set.txi @@ -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 +++ b/scripts/ChangeLog @@ -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 +++ b/scripts/deprecated/Makefile.in @@ -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 \
rename from scripts/set/create_set.m rename to scripts/deprecated/create_set.m --- a/scripts/set/create_set.m +++ b/scripts/deprecated/create_set.m @@ -20,6 +20,9 @@ ## -*- 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, ## @@ -41,18 +44,26 @@ ## @end group ## @end example ## @seealso{union, intersect, complement, unique} -## @end deftypefn ## 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).'; + y = unique (x)(:)'; elseif (strcmpi (rows_opt, "rows")) y = unique (x, "rows"); else @@ -61,11 +72,9 @@ 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 +++ b/scripts/set/Makefile.in @@ -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 +++ b/scripts/set/complement.m @@ -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/unique.m +++ b/scripts/set/unique.m @@ -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)