changeset 18901:589354cf668f gui-release

maint: Periodic merge of stable to gui-release.
author John W. Eaton <jwe@octave.org>
date Fri, 27 Jun 2014 11:55:48 -0400
parents 95b69b880b19 (current diff) c457a84bc7d3 (diff)
children 2b82d2f29a7b 39844e6ccf13
files libinterp/corefcn/data.cc scripts/io/strread.m
diffstat 5 files changed, 65 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/data.cc	Thu Jun 26 14:42:55 2014 -0400
+++ b/libinterp/corefcn/data.cc	Fri Jun 27 11:55:48 2014 -0400
@@ -568,6 +568,9 @@
 %! [f, e] = log2 (complex (zeros (3, 2), [0,-1; 2,-4; Inf,-Inf]));
 %! assert (f, complex (zeros (3, 2), [0,-0.5; 0.5,-0.5; Inf,-Inf]));
 %! assert (e(1:2,:), [0,1; 2,3]);
+
+# bug #42583
+%!assert (all (log2 (pow2 (-1074:1023)) == -1074:1023))
 */
 
 DEFUN (rem, args, ,
--- a/libinterp/corefcn/load-save.cc	Thu Jun 26 14:42:55 2014 -0400
+++ b/libinterp/corefcn/load-save.cc	Fri Jun 27 11:55:48 2014 -0400
@@ -265,9 +265,10 @@
               file.clear ();
               file.seekg (0, std::ios::beg);
 
-              std::string tmp = extract_keyword (file, "name");
+              std::string name_val = extract_keyword (file, "name");
+              std::string type_val = extract_keyword (file, "type");
 
-              if (! tmp.empty ())
+              if (name_val.empty () != true && type_val.empty () != true)
                 retval = LS_ASCII;
               else
                 {
--- a/liboctave/array/Range.cc	Thu Jun 26 14:42:55 2014 -0400
+++ b/liboctave/array/Range.cc	Fri Jun 27 11:55:48 2014 -0400
@@ -387,12 +387,12 @@
 Range
 operator - (const Range& r)
 {
-  return Range (-r.base (), -r.inc (), r.nelem ());
+  return Range (-r.base (), -r.limit (), -r.inc (), r.nelem ());
 }
 
 Range operator + (double x, const Range& r)
 {
-  Range result (x + r.base (), r.inc (), r.nelem ());
+  Range result (x + r.base (), x + r.limit (), r.inc (), r.nelem ());
   if (result.rng_nelem < 0)
     result.cache = x + r.matrix_value ();
 
@@ -401,7 +401,7 @@
 
 Range operator + (const Range& r, double x)
 {
-  Range result (r.base () + x, r.inc (), r.nelem ());
+  Range result (r.base () + x, r.limit () + x, r.inc (), r.nelem ());
   if (result.rng_nelem < 0)
     result.cache = r.matrix_value () + x;
 
@@ -410,7 +410,7 @@
 
 Range operator - (double x, const Range& r)
 {
-  Range result (x - r.base (), -r.inc (), r.nelem ());
+  Range result (x - r.base (), x - r.limit (), -r.inc (), r.nelem ());
   if (result.rng_nelem < 0)
     result.cache = x - r.matrix_value ();
 
@@ -419,7 +419,7 @@
 
 Range operator - (const Range& r, double x)
 {
-  Range result (r.base () - x, r.inc (), r.nelem ());
+  Range result (r.base () - x, r.limit () - x, r.inc (), r.nelem ());
   if (result.rng_nelem < 0)
     result.cache = r.matrix_value () - x;
 
@@ -428,7 +428,7 @@
 
 Range operator * (double x, const Range& r)
 {
-  Range result (x * r.base (), x * r.inc (), r.nelem ());
+  Range result (x * r.base (), x * r.limit (), x * r.inc (), r.nelem ());
   if (result.rng_nelem < 0)
     result.cache = x * r.matrix_value ();
 
@@ -437,7 +437,7 @@
 
 Range operator * (const Range& r, double x)
 {
-  Range result (r.base () * x, r.inc () * x, r.nelem ());
+  Range result (r.base () * x, r.limit () * x, r.inc () * x, r.nelem ());
   if (result.rng_nelem < 0)
     result.cache = r.matrix_value () * x;
 
--- a/liboctave/array/Range.h	Thu Jun 26 14:42:55 2014 -0400
+++ b/liboctave/array/Range.h	Fri Jun 27 11:55:48 2014 -0400
@@ -54,7 +54,7 @@
     : rng_base (b), rng_limit (b + (n-1) * i), rng_inc (i),
       rng_nelem (n), cache ()
   {
-    if (! xfinite (b) || ! xfinite (i))
+    if (! xfinite (b) || ! xfinite (i) | ! xfinite (rng_limit))
       rng_nelem = -2;
   }
 
@@ -145,6 +145,16 @@
 
   void clear_cache (void) const { cache.resize (0, 0); }
 
+protected:
+
+  // For operators' usage (to allow all values to be set directly).
+  Range (double b, double l, double i, octave_idx_type n)
+    : rng_base (b), rng_limit (l), rng_inc (i),
+      rng_nelem (n), cache ()
+  {
+    if (! xfinite (b) || ! xfinite (i) || ! xfinite (l))
+      rng_nelem = -2;
+  }
 };
 
 extern OCTAVE_API Range operator - (const Range& r);
--- a/scripts/io/strread.m	Thu Jun 26 14:42:55 2014 -0400
+++ b/scripts/io/strread.m	Fri Jun 27 11:55:48 2014 -0400
@@ -192,6 +192,10 @@
     error ("strread: STR and FORMAT arguments must be strings");
   endif
 
+  if (strcmp (typeinfo (format), "sq_string"))
+    format = do_string_escapes (format);
+  endif
+
   ## Parse format string to compare number of conversion fields and nargout
   nfields = length (strfind (format, "%")) - length (strfind (format, "%*"));
   ## If str only has numeric fields, a (default) format ("%f") will do.
@@ -391,6 +395,15 @@
     white_spaces = strrep (white_spaces, eol_char, '');
   endif
 
+  ii = numel (fmt_words);
+  while (ii > 0)
+    if (ismember (fmt_words{ii}, delimiter_str)(1))
+      fmt_words(ii) = [];
+      --num_words_per_line;
+    endif
+    --ii;
+  endwhile
+
   pad_out = 0;
   ## Trim whitespace if needed
   if (! isempty (white_spaces))
@@ -974,6 +987,34 @@
 %!test
 %! assert (strread (",2,,4\n5,,7,", "", "delimiter", ","), [NaN; 2; NaN; 4; 5; NaN; 7]);
 
+%% Test #1 bug #42609
+%!test
+%! [a, b, c] = strread ("1 2 3\n4 5 6\n7 8 9\n", "%f %f %f\n");
+%! assert (a, [1; 4; 7]);
+%! assert (b, [2; 5; 8]);
+%! assert (c, [3; 6; 9]);
+
+%% Test #2 bug #42609
+%!test
+%! [a, b, c] = strread ("1 2\n3\n4 5\n6\n7 8\n9\n", "%f %f\n%f");
+%! assert (a, [1;4;7]);
+%! assert (b, [2; 5; 8]);
+%! assert (c, [3; 6; 9]);
+
+%% Test #3 bug #42609
+%!test
+%! [a, b, c] = strread ("1 2 3\n4 5 6\n7 8 9\n", '%f %f %f\n');
+%! assert (a, [1; 4; 7]);
+%! assert (b, [2; 5; 8]);
+%! assert (c, [3; 6; 9]);
+
+%% Test #3 bug #42609
+%!test
+%! [a, b, c] = strread ("1 2\n3\n4 5\n6\n7 8\n9\n", '%f %f\n%f');
+%! assert (a, [1;4;7]);
+%! assert (b, [2; 5; 8]);
+%! assert (c, [3; 6; 9]);
+
 %% Unsupported format specifiers
 %!test
 %!error <format specifiers are not supported> strread ("a", "%c")