changeset 4862:a0997c4d1d54

[project @ 2004-04-15 21:14:43 by jwe]
author jwe
date Thu, 15 Apr 2004 21:14:44 +0000
parents fbb15372830c
children c4cefcb802da
files scripts/ChangeLog scripts/general/is_duplicate_entry.m scripts/general/postpad.m scripts/general/prepad.m scripts/general/shift.m scripts/set/create_set.m scripts/signal/unwrap.m scripts/statistics/distributions/exponential_rnd.m scripts/statistics/distributions/logistic_rnd.m src/ChangeLog src/ov-ch-mat.h src/version.h test/octave.test/matrix/shift-3.m test/octave.test/signal/unwrap-1.m
diffstat 14 files changed, 183 insertions(+), 116 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Fri Apr 09 00:06:01 2004 +0000
+++ b/scripts/ChangeLog	Thu Apr 15 21:14:44 2004 +0000
@@ -1,3 +1,15 @@
+2004-04-15  David Bateman  <dbateman@free.fr>
+
+	* set/create_set.m, general/is_duplicate_entry.m: Make N-d array aware.
+
+	* general/shift.m, general/prepad.m, general/postpad.m: Make N-d
+	array aware and and optional argument for the dimension along
+	which to operate.
+
+	* scripts/signal/unwrap.m: Make N-d array aware and fix optional
+	argument for the dimension to be consistent with other N-d array
+	functions.
+
 2004-04-08  David Bateman  <dbateman@free.fr>
 
 	* statistics/distributions/discrete_cdf.m,
--- a/scripts/general/is_duplicate_entry.m	Fri Apr 09 00:06:01 2004 +0000
+++ b/scripts/general/is_duplicate_entry.m	Thu Apr 15 21:14:44 2004 +0000
@@ -29,8 +29,7 @@
 
   if (nargin == 1)
     if (ismatrix (x))
-      [m, n] = size (x);
-      lx = m*n;
+      lx = numel (x);
       lx1 = lx-1;
       x = sort (reshape (x, 1, lx));
       dx = x(1:lx1) - x(2:lx);
--- a/scripts/general/postpad.m	Fri Apr 09 00:06:01 2004 +0000
+++ b/scripts/general/postpad.m	Thu Apr 15 21:14:44 2004 +0000
@@ -25,37 +25,55 @@
 ## Author: Tony Richardson <arichard@stark.cc.oh.us>
 ## Created: June 1994
 
-function y = postpad (x, l, c)
+function y = postpad (x, l, c, dim)
+
+  if (nargin < 2 || nargin > 4)
+    usage ("postpad (x, l, [c, [dim]])");
+  endif
+
+  if (nargin < 3 || isempty (c))
+    c = 0;
+  else
+    if (! isscalar (c))
+      error ("postpad: third argument must be empty or a scalar");
+    endif
+  endif
 
-  if (nargin == 2)
-    c = 0;
-  elseif (nargin < 2 || nargin > 3)
-    usage ("postpad (x, l) or postpad (x, l, c)");
+  nd = ndims (x);
+  sz = size (x);
+  if (nargin < 4)
+    %% Find the first non-singleton dimension
+    dim  = 1;
+    while (dim < nd + 1 && sz (dim) == 1)
+      dim = dim + 1;
+    endwhile
+    if (dim > nd)
+      dim = 1;
+    endif
+  else
+    if (! (isscalar (dim) && dim == round (dim)) && dim > 0 && 
+	dim < (nd + 1))
+      error ("postpad: dim must be an integer and valid dimension");
+    endif
   endif
 
   if (! ismatrix (x))
     error ("first argument must be a vector or matrix");
-  elseif (! isscalar (l))
-    error ("second argument must be a scaler");
-  endif
-
-  if (l < 0)
-    error ("second argument must be non-negative");
+  elseif (! isscalar (l) || l < 0)
+    error ("second argument must be a positive scaler");
   endif
 
-  [nr, nc] = size (x);
-  if (nr == 1)
-    if (nc >= l)
-      y = x(1:l);
-    else
-      y = [x, c*ones(1,l-nc)];
-    endif
+  d = sz (dim);
+  if (d >= l)
+    idx = cell ();
+    for i = 1:nd
+      idx {i} = 1:sz(i);
+    endfor
+    idx {dim} = 1:l;
+    y = x (idx {:});
   else
-    if (nr >= l)
-      y = x(1:l,:);
-    else
-      y = [x ; c*ones(l-nr,nc)];
-    endif
+    sz (dim) = l - d;
+    y = cat (dim, x, c * ones (sz));
   endif
 
 endfunction
--- a/scripts/general/prepad.m	Fri Apr 09 00:06:01 2004 +0000
+++ b/scripts/general/prepad.m	Thu Apr 15 21:14:44 2004 +0000
@@ -34,37 +34,56 @@
 ## Author: Tony Richardson <arichard@stark.cc.oh.us>
 ## Created: June 1994
 
-function y = prepad (x, l, c)
+function y = prepad (x, l, c, dim)
+
+  if (nargin < 2 || nargin > 4)
+    usage ("prepad (x, l, [c, [dim]])");
+  endif
+
+  if (nargin < 3 || isempty (c))
+    c = 0;
+  else
+    if (! isscalar (c))
+      error ("prepad: third argument must be empty or a scalar");
+    endif
+  endif
 
-  if (nargin == 2)
-    c = 0;
-  elseif (nargin < 2 || nargin > 3)
-    usage ("prepad (x, l) or prepad (x, l, c)");
+  nd = ndims (x);
+  sz = size (x);
+  if (nargin < 4)
+    %% Find the first non-singleton dimension
+    dim  = 1;
+    while (dim < nd + 1 && sz (dim) == 1)
+      dim = dim + 1;
+    endwhile
+    if (dim > nd)
+      dim = 1;
+    endif
+  else
+    if (! (isscalar (dim) && dim == round (dim)) && dim > 0 && 
+	dim < (nd + 1))
+      error ("prepad: dim must be an integer and valid dimension");
+    endif
   endif
 
   if (! ismatrix (x))
     error ("first argument must be a vector or matrix");
-  elseif (! isscalar (l))
-    error ("second argument must be a scaler");
-  endif
-
-  if (l < 0)
-    error ("second argument must be non-negative");
+  elseif (! isscalar (l) || l < 0)
+    error ("second argument must be a positive scaler");
   endif
 
-  [nr, nc] = size (x);
-  if (nr == 1)
-    if (nc >= l)
-      y = x(nc-l+1:nc);
-    else
-      y = [c*ones(1,l-nc), x];
-    endif
+  d = sz (dim);
+
+  if (d >= l)
+    idx = cell ();
+    for i = 1:nd
+      idx {i} = 1:sz(i);
+    endfor
+    idx {dim} = d-l+1:d;
+    y = x (idx {:});
   else
-    if (nr >= l)
-      y = x(nr-l+1:nr,:);
-    else
-      y = [c*ones(l-nr,nc); x];
-    endif
+    sz (dim) = l - d;
+    y = cat (dim, c * ones (sz), x);
   endif
 
 endfunction
--- a/scripts/general/shift.m	Fri Apr 09 00:06:01 2004 +0000
+++ b/scripts/general/shift.m	Thu Apr 15 21:14:44 2004 +0000
@@ -19,58 +19,73 @@
 
 ## -*- texinfo -*-
 ## @deftypefn {Function File} {} shift (@var{x}, @var{b})
+## @deftypefnx {Function File} {} shift (@var{x}, @var{b}, @var{dim})
 ## If @var{x} is a vector, perform a circular shift of length @var{b} of
 ## the elements of @var{x}.
 ##
 ## If @var{x} is a matrix, do the same for each column of @var{x}.
+## If the optional @var{dim} argument is given, operate along this 
+## dimension
 ## @end deftypefn
 
 ## Author: AW <Andreas.Weingessel@ci.tuwien.ac.at>
 ## Created: 14 September 1994
 ## Adapted-By: jwe
 
-function y = shift (x, b)
-
-  if (nargin != 2)
-    usage ("shift (X, b)");
-  endif
+function y = shift (x, b, dim)
 
-  [nr, nc] = size (x);
-
-  if (nr == 0 || nc == 0)
-    error ("shift: x must not be empty");
-  elseif (nr == 1)
-    x = x.';
-    nr = nc;
-    nc = 0;
+  if (nargin != 2 && nargin != 3)
+    usage ("shift (X, b, dim)");
   endif
 
   if (! (isscalar (b) && b == round (b)))
     error ("shift: b must be an integer");
   endif
 
+  nd = ndims (x);
+  sz = size (x);
+
+  if (nargin == 3)
+    if (! (isscalar (dim) && dim == round (dim)) && dim > 0 && 
+	dim < (nd + 1))
+      error ("shift: dim must be an integer and valid dimension");
+    endif
+  else
+    %% Find the first non-singleton dimension
+    dim  = 1;
+    while (dim < nd + 1 && sz (dim) == 1)
+      dim = dim + 1;
+    endwhile
+    if (dim > nd)
+      dim = 1;
+    endif
+  endif
+
+  if (numel (x) < 1)
+    error ("shift: x must not be empty");
+  endif
+
+  d = sz (dim);
+
   save_warn_empty_list_elements = warn_empty_list_elements;
   unwind_protect
     warn_empty_list_elements = 0;
 
+    idx = cell ();
+    for i = 1:nd
+      idx {i} = 1:sz(i);
+    endfor
     if (b >= 0)
-      b = rem (b, nr);
-      t1 = x (nr-b+1:nr, :);
-      t2 = x (1:nr-b, :);
-      y = [t1; t2];
+      b = rem (b, d);
+      idx {dim} = [d-b+1:d, 1:d-b];
     elseif (b < 0)
-      b = rem (abs (b), nr);
-      t1 = x (b+1:nr, :);
-      t2 = x (1:b, :);
-      y = [t1; t2];
+      b = rem (abs (b), d);
+      idx {dim} = [b+1:d, 1:b];
     endif
+    y = x (idx {:});
 
   unwind_protect_cleanup
     warn_empty_list_elements = save_warn_empty_list_elements;
   end_unwind_protect
 
-  if (nc == 0)
-    y = reshape (y, 1, nr);
-  endif
-
 endfunction
--- a/scripts/set/create_set.m	Fri Apr 09 00:06:01 2004 +0000
+++ b/scripts/set/create_set.m	Thu Apr 15 21:14:44 2004 +0000
@@ -42,10 +42,9 @@
   if (isempty(x))
     y = [];
   else
-    [nrx, ncx] = size (x);
-    nelx = nrx * ncx;
-    y = sort (reshape (x, 1, nelx));
-    els = find (y(1:nelx-1) != y(2:nelx));
+    nel = numel (x);
+    y = sort (reshape (x, 1, nel));
+    els = find (y(1:nel-1) != y(2:nel));
     if (isempty (els));
       y = y(1);
     else
--- a/scripts/signal/unwrap.m	Fri Apr 09 00:06:01 2004 +0000
+++ b/scripts/signal/unwrap.m	Thu Apr 15 21:14:44 2004 +0000
@@ -23,9 +23,9 @@
 ## Unwrap radian phases by adding multiples of 2*pi as appropriate to
 ## remove jumps greater than @var{tol}.  @var{tol} defaults to pi.
 ##
-## Unwrap will unwrap along the columns of @var{a} unless the row
-## dimension of @var{a} is 1 or @var{dim} is given with a
-## value of 1, when it will unwrap along the row(s).
+## Unwrap will unwrap along the first non-singleton dimension of
+## @var{a}, unless the optional argument @var{dim} is given, in 
+## which case the data will be unwrapped along this dimension
 ## @end deftypefn
 
 ## Author: Bill Lash <lash@tellabs.com>
@@ -36,22 +36,26 @@
     usage ("unwrap (a [, tol [, dim]])")
   endif
 
-  if (nargin < 3)
-    if (rows (a) == 1)
-      ## Row vector, go along the row.
+  nd = ndims (a);
+  sz = size (a);
+
+  if (nargin == 3)
+    if (! (isscalar (dim) && dim == round (dim)) && dim > 0 && 
+	dim < (nd + 1))
+      error ("unwrap: dim must be an integer and valid dimension");
+    endif
+  else
+    ## Find the first non-singleton dimension
+    dim  = 1;
+    while (dim < nd + 1 && sz (dim) == 1)
+      dim = dim + 1;
+    endwhile
+    if (dim > nd)
       dim = 1;
-    else
-      ## Otherwise go along the columns.
-      dim = 2;
     endif
   endif
 
-  if (nargin < 2)
-    tol = pi;
-  endif
-
-  ## If TOL is not provided but dim is, handle it.
-  if (isempty (tol))
+  if (nargin < 2 || isempty (tol))
     tol = pi;
   endif
 
@@ -59,15 +63,7 @@
   tol = abs (tol);
   
   rng = 2*pi;
-  
-  ## Put data in a form so that we can unwrap each column.
-  if (dim == 1)
-    ra = a.';
-  else
-    ra = a;
-  endif
-  n = columns (ra);
-  m = rows (ra);
+  m = sz (dim);
 
   ## Handle case where we are trying to unwrap a scalar, or only have
   ## one sample in the specified dimension.
@@ -78,7 +74,12 @@
 
   ## Take first order difference to see so that wraps will show up
   ## as large values, and the sign will show direction.
-  d = [ zeros(1,n); ra(1:m-1,:)-ra(2:m,:) ];
+  idx = cell ();
+  for i = 1:nd
+    idx {i} = 1:sz(i);
+  endfor
+  idx {dim} = [1,1:m-1];
+  d = a (idx {:}) - a;
 
   ## Find only the peaks, and multiply them by the range so that there
   ## are kronecker deltas at each wrap point multiplied by the range
@@ -86,14 +87,10 @@
   p =  rng * (((d > tol) > 0) - ((d < -tol) > 0));
 
   ## Now need to "integrate" this so that the deltas become steps.
-  r = cumsum (p);
+  r = cumsum (p, dim);
 
   ## Now add the "steps" to the original data and put output in the
   ## same shape as originally.
-  if (dim == 1)
-    retval = (ra + r).';
-  else
-    retval = (ra + r);
-  endif
+  retval = a + r;
 
 endfunction
--- a/scripts/statistics/distributions/exponential_rnd.m	Fri Apr 09 00:06:01 2004 +0000
+++ b/scripts/statistics/distributions/exponential_rnd.m	Thu Apr 15 21:14:44 2004 +0000
@@ -19,7 +19,7 @@
 
 ## -*- texinfo -*-
 ## @deftypefn {Function File} {} exponential_rnd (@var{lambda}, @var{r}, @var{c})
-## @deftypefn {Function File} {} exponential_rnd (@var{lambda}, @var{sz})
+## @deftypefnx {Function File} {} exponential_rnd (@var{lambda}, @var{sz})
 ## Return an @var{r} by @var{c} matrix of random samples from the
 ## exponential distribution with parameter @var{lambda}, which must be a
 ## scalar or of size @var{r} by @var{c}. Or if @var{sz} is a vector, 
--- a/scripts/statistics/distributions/logistic_rnd.m	Fri Apr 09 00:06:01 2004 +0000
+++ b/scripts/statistics/distributions/logistic_rnd.m	Thu Apr 15 21:14:44 2004 +0000
@@ -19,7 +19,7 @@
 
 ## -*- texinfo -*-
 ## @deftypefn {Function File} {} logistic_rnd (@var{r}, @var{c})
-## @deftypefn {Function File} {} logistic_rnd (@var{sz})
+## @deftypefnx {Function File} {} logistic_rnd (@var{sz})
 ## Return an @var{r} by @var{c} matrix of random numbers from the
 ## logistic distribution. Or is @var{sz} is a vector, create a matrix of
 ## @var{sz}.
--- a/src/ChangeLog	Fri Apr 09 00:06:01 2004 +0000
+++ b/src/ChangeLog	Thu Apr 15 21:14:44 2004 +0000
@@ -1,3 +1,11 @@
+2004-04-15  David Bateman  <dbateman@free.fr>
+
+	* src/ov-ch-mat.h: convert_to_str_interal returns charNDArray.
+
+2004-04-12  John W. Eaton  <jwe@octave.org>
+
+	* version.h (OCTAVE_BUGS_STATEMENT): Bug list is now bug@octave.org.
+
 2004-04-08  John W. Eaton  <jwe@octave.org>
 
 	* ov-base-mat.cc (octave_base_matrix<MT>::do_index_op): Quit early
--- a/src/ov-ch-mat.h	Fri Apr 09 00:06:01 2004 +0000
+++ b/src/ov-ch-mat.h	Thu Apr 15 21:14:44 2004 +0000
@@ -118,7 +118,7 @@
     { return matrix; }
 
   octave_value convert_to_str_internal (bool, bool) const
-    { return octave_value (matrix.matrix_value (), true); }
+    { return octave_value (matrix, true); }
 
   void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
 
--- a/src/version.h	Fri Apr 09 00:06:01 2004 +0000
+++ b/src/version.h	Thu Apr 15 21:14:44 2004 +0000
@@ -48,7 +48,7 @@
 For more information, visit http://www.octave.org/help-wanted.html"
 
 #define OCTAVE_BUGS_STATEMENT \
-  "Report bugs to <bug-octave@bevo.che.wisc.edu> (but first, please read\n\
+  "Report bugs to <bug@octave.org> (but first, please read\n\
 http://www.octave.org/bugs.html to learn how to write a helpful report)."
 
 #define OCTAVE_NAME_VERSION_AND_COPYRIGHT \
--- a/test/octave.test/matrix/shift-3.m	Fri Apr 09 00:06:01 2004 +0000
+++ b/test/octave.test/matrix/shift-3.m	Thu Apr 15 21:14:44 2004 +0000
@@ -1,1 +1,1 @@
-shift (1, 2, 3)
+shift (1, 2, 3, 4)
--- a/test/octave.test/signal/unwrap-1.m	Fri Apr 09 00:06:01 2004 +0000
+++ b/test/octave.test/signal/unwrap-1.m	Thu Apr 15 21:14:44 2004 +0000
@@ -28,11 +28,11 @@
 t(++i) = assert(r, unwrap(w), tol);               #unwrap single row
 t(++i) = assert(r', unwrap(w'), tol);             #unwrap single column
 t(++i) = assert([r',r'], unwrap([w',w']), tol);   #unwrap 2 columns
-t(++i) = assert([r;r], unwrap([w;w],[],1), tol);  #verify that dim works
+t(++i) = assert([r;r], unwrap([w;w],[],2), tol);  #verify that dim works
 t(++i) = assert(r+10, unwrap(10+w), tol);         #verify that r(1)>pi works
 
-t(++i) = assert(w', unwrap(w',[],1));  #unwrap col by rows should not change it
-t(++i) = assert(w, unwrap(w,[],2));    #unwrap row by cols should not change it
+t(++i) = assert(w', unwrap(w',[],2));  #unwrap col by rows should not change it
+t(++i) = assert(w, unwrap(w,[],1));    #unwrap row by cols should not change it
 t(++i) = assert([w;w], unwrap([w;w])); #unwrap 2 rows by cols should not change them
 
 ## verify that setting tolerance too low will cause bad results.