changeset 6609:30891d1d0c86

[project @ 2007-05-09 02:12:04 by jwe]
author jwe
date Wed, 09 May 2007 02:17:36 +0000
parents 2581a3c23f18
children fb8bddaa07c4
files NEWS scripts/ChangeLog scripts/general/__isequal__.m scripts/set/ismember.m scripts/set/unique.m scripts/statistics/distributions/normcdf.m src/ChangeLog src/oct-map.cc
diffstat 8 files changed, 134 insertions(+), 61 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Tue May 08 01:17:57 2007 +0000
+++ b/NEWS	Wed May 09 02:17:36 2007 +0000
@@ -143,5 +143,7 @@
 
       [status, output] = system (cmd);
 
+ ** For compatibility with Matlab, the third argument to normcdf is
+    now the standard deviation instead of the variance.
 
 See NEWS.2 for old news.
--- a/scripts/ChangeLog	Tue May 08 01:17:57 2007 +0000
+++ b/scripts/ChangeLog	Wed May 09 02:17:36 2007 +0000
@@ -1,3 +1,21 @@
+2007-05-09  G. D. McBain  <geordie.mcbain@aeromech.usyd.edu.au>
+
+	* statistics/distributions/normcdf.m: Use standard deviation
+	instead of variance for compatibility.
+
+2007-05-08  John W. Eaton  <jwe@octave.org>
+
+
+	* set/unique.m, set/ismember.m: Use numel(x) instead of prod(size(x)).
+
+	* set/ismember.m: Always return logical values.
+
+	* set/ismember.m: Return early if no matches are found.  New tests.
+	From: David Grohmann <grohmann@arlut.utexas.edu>.
+
+	* general/__isequal__.m: Allow numeric values of different classes
+	to compare equal.
+
 2007-05-07  David Bateman  <dbateman@free.fr>
 
 	* sparse/spy.m: Reverse Y axis for new graphics code. Make more
--- a/scripts/general/__isequal__.m	Tue May 08 01:17:57 2007 +0000
+++ b/scripts/general/__isequal__.m	Wed May 09 02:17:36 2007 +0000
@@ -58,11 +58,13 @@
     error ("__isequal__: list objects are deprecated and cannot be tested for equality here; use cell arrays instead");
   endif
 
-  ## Test that everything is the same class.
-  ## NOTE: sparse and numeric matrices that are otherwise equal will
-  ## compare as different here.
-  t = all (strcmp (class(x),
-		   cellfun (@class, varargin, "UniformOutput", false)));
+  ## All arguments must either be of the same class or they must be
+  ## numeric values.
+  t = (all (strcmp (class(x),
+		   cellfun (@class, varargin, "UniformOutput", false)))
+       || (isnumeric (x)
+	   && all (cellfun (@isnumeric, varargin, "UniformOutput", true))));
+
   if (t)
     ## Test that everything has the same number of dimensions.
     s_x = size (x);
@@ -138,9 +140,6 @@
     else
       ## Check the numeric types.
 
-      ## NOTE: sparse and nonsparse will compare equally here, but they
-      ## won't compare equally at the class check at the top.
-
       if (issparse (x))
 	f_x = spfind (x);
       else
--- a/scripts/set/ismember.m	Tue May 08 01:17:57 2007 +0000
+++ b/scripts/set/ismember.m	Wed May 09 02:17:36 2007 +0000
@@ -34,7 +34,7 @@
   endif
 
   if (isempty (a) || isempty (S))
-    c = zeros (size (a));
+    c = zeros (size (a), "logical");
   else
     if (iscell (a) && ! iscell (S))
       tmp{1} = S;
@@ -50,16 +50,24 @@
       if (iscell (a) || iscell (S))
         c = cellfun ("length", a) == cellfun ("length", S);
         idx = find (c);
-        c(idx) = all (char (a(idx)) == repmat (char (S), length (idx), 1), 2);
+	if (isempty (idx))
+	  c = zeros (size (a), "logical");
+	else
+	  c(idx) = all (char (a(idx)) == repmat (char (S), length (idx), 1), 2);
+	endif
       else
         c = (a == S);
       endif
-    elseif (prod (size (a)) == 1)
+    elseif (numel (a) == 1)
       if (iscell (a) || iscell (S))
         c = cellfun ("length", a) == cellfun ("length", S);
         idx = find (c);
-        c(idx) = all (repmat (char (a), length (idx), 1) == char (S(idx)), 2);
-        c = any(c);
+	if (isempty (idx))
+	  c = zeros (size (a), "logical");
+	else
+          c(idx) = all (repmat (char (a), length (idx), 1) == char (S(idx)), 2);
+          c = any(c);
+	endif
       else
         c = any (a == S);
       endif
@@ -115,3 +123,9 @@
 %!assert (ismember ('', {'abc', 'def'}), false);
 %!fail (ismember ([], {1, 2}), 'error:.*');
 %!fail (ismember ({[]}, {1, 2}), 'error:.*');
+%!assert (ismember ({'foo', 'bar'}, {'foobar'}), logical ([0, 0]))
+%!assert (ismember ({'foo'}, {'foobar'}), false)
+%!assert (ismember ({'bar'}, {'foobar'}), false)
+%!assert (ismember ({'bar'}, {'foobar', 'bar'}), true)
+%!assert (ismember ({'foo', 'bar'}, {'foobar', 'bar'}), logical ([0, 1]))
+%!assert (ismember ({'xfb', 'f', 'b'}, {'fb', 'b'}), logical ([0, 0, 1]))
--- a/scripts/set/unique.m	Tue May 08 01:17:57 2007 +0000
+++ b/scripts/set/unique.m	Wed May 09 02:17:36 2007 +0000
@@ -40,7 +40,7 @@
   endif
 
   if (nargin == 1)
-    n = prod (size (x));
+    n = numel (x);
   else
     n = size (x, 1);
   endif
--- a/scripts/statistics/distributions/normcdf.m	Tue May 08 01:17:57 2007 +0000
+++ b/scripts/statistics/distributions/normcdf.m	Wed May 09 02:17:36 2007 +0000
@@ -18,18 +18,18 @@
 ## 02110-1301, USA.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {} normcdf (@var{x}, @var{m}, @var{v})
+## @deftypefn {Function File} {} normcdf (@var{x}, @var{m}, @var{s})
 ## For each element of @var{x}, compute the cumulative distribution
 ## function (CDF) at @var{x} of the normal distribution with mean
-## @var{m} and variance @var{v}.
+## @var{m} and standard deviation @var{s}.
 ##
-## Default values are @var{m} = 0, @var{v} = 1.
+## Default values are @var{m} = 0, @var{s} = 1.
 ## @end deftypefn
 
 ## Author: TT <Teresa.Twaroch@ci.tuwien.ac.at>
 ## Description: CDF of the normal distribution
 
-function cdf = normcdf (x, m, v)
+function cdf = normcdf (x, m, s)
 
   if (! ((nargin == 1) || (nargin == 3)))
     print_usage ();
@@ -37,37 +37,37 @@
 
   if (nargin == 1)
     m = 0;
-    v = 1;
+    s = 1;
   endif
 
-  if (!isscalar (m) || !isscalar(v))
-    [retval, x, m, v] = common_size (x, m, v);
+  if (!isscalar (m) || !isscalar(s))
+    [retval, x, m, s] = common_size (x, m, s);
     if (retval > 0)
-      error ("normcdf: x, m and v must be of common size or scalar");
+      error ("normcdf: x, m and s must be of common size or scalar");
     endif
   endif
 
   sz = size (x);
   cdf = zeros (sz);
 
-  if (isscalar (m) && isscalar(v))
-    if (find (isinf (m) | isnan (m) | !(v >= 0) | !(v < Inf)))
+  if (isscalar (m) && isscalar(s))
+    if (find (isinf (m) | isnan (m) | !(s >= 0) | !(s < Inf)))
       cdf = NaN * ones (sz);
     else
-      cdf =  stdnormal_cdf ((x - m) ./ sqrt (v));
+      cdf =  stdnormal_cdf ((x - m) ./ s);
     endif
   else
-    k = find (isinf (m) | isnan (m) | !(v >= 0) | !(v < Inf));
+    k = find (isinf (m) | isnan (m) | !(s >= 0) | !(s < Inf));
     if (any (k))
       cdf(k) = NaN;
     endif
 
-    k = find (!isinf (m) & !isnan (m) & (v >= 0) & (v < Inf));
+    k = find (!isinf (m) & !isnan (m) & (s >= 0) & (s < Inf));
     if (any (k))
-      cdf(k) = stdnormal_cdf ((x(k) - m(k)) ./ sqrt (v(k)));
+      cdf(k) = stdnormal_cdf ((x(k) - m(k)) ./ s(k));
     endif
   endif
 
-  cdf((v == 0) & (x == m)) = 0.5;
+  cdf((s == 0) & (x == m)) = 0.5;
 
 endfunction
--- a/src/ChangeLog	Tue May 08 01:17:57 2007 +0000
+++ b/src/ChangeLog	Wed May 09 02:17:36 2007 +0000
@@ -3,6 +3,14 @@
 	* DLD-FUNCTIONS/symrcm.cc: New function for Reverse Cuthill-McKee
 	permutation.
 	
+2007-05-07  John W. Eaton  <jwe@octave.org>
+
+	* oct-map.cc (Octave_map::resize): Handle case of no keys.
+	(keys_ok): Rename from equiv_keys.  Return value is now status.
+	Pass key names as string_vector reference arg.
+	(Octave_map::assign (const octave_value_list&, const Octave_map&)):
+	Call keys_ok, not equiv_keys.  Handle case of no keys.
+
 2007-04-30  John W. Eaton  <jwe@octave.org>
 
 	* Makefile.in (%.df : %.cc): Use mv instead of
--- a/src/oct-map.cc	Tue May 08 01:17:57 2007 +0000
+++ b/src/oct-map.cc	Wed May 09 02:17:36 2007 +0000
@@ -155,18 +155,23 @@
 {
   if (dv != dims ())
     {
-      for (const_iterator p = begin (); p != end (); p++)
+      if (empty ())
+	dimensions = dv;
+      else
 	{
-	  Cell tmp = contents(p);
+	  for (const_iterator p = begin (); p != end (); p++)
+	    {
+	      Cell tmp = contents(p);
 
-	  if (fill)
-	    tmp.resize(dv, Cell::resize_fill_value ());
-	  else
-	    tmp.resize(dv);
+	      if (fill)
+		tmp.resize(dv, Cell::resize_fill_value ());
+	      else
+		tmp.resize(dv);
 
-	  dimensions = dv;
+	      dimensions = dv;
 
-	  assign (key(p), tmp);
+	      assign (key(p), tmp);
+	    }
 	}
     }
 }
@@ -198,28 +203,40 @@
   return retval;
 }
 
-static string_vector
-equiv_keys (const Octave_map& a, const Octave_map& b)
+static bool
+keys_ok (const Octave_map& a, const Octave_map& b, string_vector& keys)
 {
-  string_vector retval;
+  bool retval = false;
+
+  keys = string_vector ();
 
-  string_vector a_keys = a.keys().qsort ();
-  string_vector b_keys = b.keys().qsort ();
-
-  octave_idx_type a_len = a_keys.length ();
-  octave_idx_type b_len = b_keys.length ();
+  if (a.empty ())
+    {
+      keys = b.keys ();
+      retval = true;
+    }
+  else
+    {
+      string_vector a_keys = a.keys().qsort ();
+      string_vector b_keys = b.keys().qsort ();
 
-  if (a_len == b_len)
-    {
-      for (octave_idx_type i = 0; i < a_len; i++)
+      octave_idx_type a_len = a_keys.length ();
+      octave_idx_type b_len = b_keys.length ();
+
+      if (a_len == b_len)
 	{
-	  if (a_keys[i] != b_keys[i])
-	    return retval;
-	}
+	  for (octave_idx_type i = 0; i < a_len; i++)
+	    {
+	      if (a_keys[i] != b_keys[i])
+		goto done;
+	    }
 
-      retval = a_keys;
+	  keys = a_keys;
+	  retval = true;
+	}
     }
-  
+
+ done:
   return retval;
 }
 
@@ -251,22 +268,37 @@
 Octave_map&
 Octave_map::assign (const octave_value_list& idx, const Octave_map& rhs)
 {
-  string_vector t_keys = empty () ? rhs.keys () : equiv_keys (*this, rhs);
+  string_vector t_keys;
 
-  if (! t_keys.empty ())
+  if (keys_ok (*this, rhs, t_keys))
     {
       octave_idx_type len = t_keys.length ();
 
-      for (octave_idx_type i = 0; i < len; i++)
+      if (len == 0)
 	{
-	  std::string k = t_keys[i];
+	  Cell tmp_lhs (dims ());
+	  Cell tmp_rhs (rhs.dims ());
+
+	  tmp_lhs.assign (idx, tmp_rhs, Matrix ());
 
-	  Cell t_rhs = rhs.contents (k);
+	  if (! error_state)
+	    resize (tmp_lhs.dims ());
+	  else
+	    error ("size mismatch in structure assignment");
+	}
+      else
+	{
+	  for (octave_idx_type i = 0; i < len; i++)
+	    {
+	      std::string k = t_keys[i];
 
-	  assign (idx, k, t_rhs);
+	      Cell t_rhs = rhs.contents (k);
+
+	      assign (idx, k, t_rhs);
 
-	  if (error_state)
-	    break;
+	      if (error_state)
+		break;
+	    }
 	}
     }
   else