changeset 14491:5bd9e47e9277

maint: periodic merge of stable to default
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Thu, 22 Mar 2012 11:50:51 -0400
parents f36301ea650f (current diff) 3959f3f81e33 (diff)
children 7ce925166af6
files doc/interpreter/octave.texi scripts/linear-algebra/logm.m scripts/miscellaneous/edit.m scripts/strings/base2dec.m scripts/strings/bin2dec.m src/data.cc
diffstat 6 files changed, 91 insertions(+), 52 deletions(-) [+]
line wrap: on
line diff
--- a/doc/interpreter/install.txi	Thu Mar 22 11:32:15 2012 -0400
+++ b/doc/interpreter/install.txi	Thu Mar 22 11:50:51 2012 -0400
@@ -65,16 +65,19 @@
 yourself.
 
 @menu
-* Tips for Specific Systems::
+* Obtaining the Depencies Automatically::
 * Build Tools::
 * External Packages::
 @end menu
 
-@node Tips for Specific Systems
-@subsection Tips for Specific Systems
+@node Obtaining the Depencies Automatically
+@subsection Obtaining the Depencies Automatically
 
-The names of pre-compiled packages vary by system and do not always
-match exactly the names listed above.
+On some systems you can obtain many of Octave's build dependencies
+automatically. The commands for doing this vary by system. Similarly,
+the names of pre-compiled packages vary by system and do not always
+match exactly the names listed in @ref{Build Tools} and @ref{External
+Packages}.
 
 You will usually need the development version of an external dependency
 so that you get the libraries and header files for building software,
--- a/doc/interpreter/octave.texi	Thu Mar 22 11:32:15 2012 -0400
+++ b/doc/interpreter/octave.texi	Thu Mar 22 11:50:51 2012 -0400
@@ -890,7 +890,7 @@
 
 Build Dependencies
 
-* Tips for Specific Systems::
+* Obtaining the Depencies Automatically::
 * Build Tools::
 * External Packages::
 
--- a/scripts/miscellaneous/edit.m	Thu Mar 22 11:32:15 2012 -0400
+++ b/scripts/miscellaneous/edit.m	Thu Mar 22 11:50:51 2012 -0400
@@ -132,8 +132,8 @@
 ## @item mode
 ## This value determines whether the editor should be started in async mode
 ## (editor is started in the background and Octave continues) or sync mode
-## (Octave waits until the editor exits).  Set it to "async" to start the editor
-## in async mode.  The default is "sync" (see also "system").
+## (Octave waits until the editor exits).  Set it to "sync" to start the editor
+## in sync mode.  The default is "async" (see also "system").
 ##
 ## @item editinplace
 ## Determines whether files should be edited in place, without regard to
--- a/scripts/strings/base2dec.m	Thu Mar 22 11:32:15 2012 -0400
+++ b/scripts/strings/base2dec.m	Thu Mar 22 11:50:51 2012 -0400
@@ -81,8 +81,27 @@
     s = toupper (s);
   endif
 
-  ## Right justify the values before anything else.
-  s = strjust (s, "right");
+  ## Right justify the values and squeeze out any spaces.
+  ## This looks complicated, but indexing solution is very fast
+  ## compared to alternatives which use cellstr or cellfun or looping.
+  [nr, nc] = size (s);
+  if (nc > 1)   # Bug #35621
+    s = s.';
+    nonbl = s != " ";
+    num_nonbl = sum (nonbl);
+    nc = max (num_nonbl);
+    num_blank = nc - num_nonbl;
+    R = repmat ([1 2; 0 0], 1, nr);
+    R(2, 1:2:2*nr) = num_blank;
+    R(2, 2:2:2*nr) = num_nonbl;
+    idx = repelems ([false, true], R);
+    idx = reshape (idx, nc, nr);
+    
+    ## Create a blank matrix and position the nonblank characters.
+    s2 = repmat (" ", nc, nr);
+    s2(idx) = s(nonbl);
+    s = s2.';
+  endif
 
   ## Lookup value of symbols in symbol table, with invalid symbols
   ## evaluating to NaN and space evaluating to 0.
--- a/scripts/strings/bin2dec.m	Thu Mar 22 11:32:15 2012 -0400
+++ b/scripts/strings/bin2dec.m	Thu Mar 22 11:50:51 2012 -0400
@@ -24,7 +24,17 @@
 ## @example
 ## @group
 ## bin2dec ("1110")
-##       @result{} 14
+##      @result{} 14
+## @end group
+## @end example
+##
+## Spaces are ignored during conversion and may be used to make the binary
+## number more readable.
+##
+## @example
+## @group
+## bin2dec ("1000 0001")
+##      @result{} 129
 ## @end group
 ## @end example
 ##
@@ -50,10 +60,12 @@
 endfunction
 
 
-%!assert (bin2dec ("0000"), 0)
-%!assert (bin2dec ("1110"), 14)
-%!assert (bin2dec ("11111111111111111111111111111111111111111111111111111"), 2^53-1)
-%!assert (bin2dec ({"1110", "1111"}), [14; 15])
+%!assert(bin2dec ("0000"), 0)
+%!assert(bin2dec ("1110"), 14)
+%!assert(bin2dec ("11111111111111111111111111111111111111111111111111111"), 2^53-1)
+%!assert(bin2dec ({"1110", "1111"}), [14; 15])
+%!assert (bin2dec ("1 0 1"), 5)
+%!assert (bin2dec (char ("1 0 1", "   1111")), [5; 15])
 
 %%Test input validation
 %!error bin2dec ()
--- a/src/data.cc	Thu Mar 22 11:32:15 2012 -0400
+++ b/src/data.cc	Thu Mar 22 11:50:51 2012 -0400
@@ -1285,7 +1285,7 @@
         {
           octave_idx_type m = args(1).int_value (), n = args(2).int_value ();
           if (! error_state)
-            retval = arg0.diag ().resize (dim_vector (m, n));
+            retval = arg0.diag ().resize (dim_vector (m, n), true);
           else
             error ("diag: invalid dimensions");
         }
@@ -1299,44 +1299,49 @@
 }
 
 /*
-%!assert (full (diag ([1; 2; 3])), [1, 0, 0; 0, 2, 0; 0, 0, 3])
-%!assert (diag ([1; 2; 3], 1), [0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0])
-%!assert (diag ([1; 2; 3], 2), [0, 0, 1, 0, 0; 0, 0, 0, 2, 0; 0, 0, 0, 0, 3; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0])
-%!assert (diag ([1; 2; 3],-1), [0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0])
-%!assert (diag ([1; 2; 3],-2), [0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 1, 0, 0, 0, 0; 0, 2, 0, 0, 0; 0, 0, 3, 0, 0])
-
-%!assert (diag ([1, 0, 0; 0, 2, 0; 0, 0, 3]), [1; 2; 3])
-%!assert (diag ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0], 1), [1; 2; 3])
-%!assert (diag ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0], -1), [1; 2; 3])
-%!assert (diag (ones (1, 0), 2), zeros (2))
-%!assert (diag (1:3, 4, 2), [1, 0; 0, 2; 0, 0; 0, 0])
-
-%!assert (full (diag (single ([1; 2; 3]))), single ([1, 0, 0; 0, 2, 0; 0, 0, 3]))
-%!assert (diag (single ([1; 2; 3]), 1), single ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]))
-%!assert (diag (single ([1; 2; 3]), 2), single ([0, 0, 1, 0, 0; 0, 0, 0, 2, 0; 0, 0, 0, 0, 3; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0]))
-%!assert (diag (single ([1; 2; 3]),-1), single ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]))
-%!assert (diag (single ([1; 2; 3]),-2), single ([0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 1, 0, 0, 0, 0; 0, 2, 0, 0, 0; 0, 0, 3, 0, 0]))
-
-%!assert (diag (single ([1, 0, 0; 0, 2, 0; 0, 0, 3])), single ([1; 2; 3]))
-%!assert (diag (single ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]), 1), single ([1; 2; 3]))
-%!assert (diag (single ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]), -1), single ([1; 2; 3]))
-
-%!assert (diag (int8 ([1; 2; 3])), int8 ([1, 0, 0; 0, 2, 0; 0, 0, 3]))
-%!assert (diag (int8 ([1; 2; 3]), 1), int8 ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]))
-%!assert (diag (int8 ([1; 2; 3]), 2), int8 ([0, 0, 1, 0, 0; 0, 0, 0, 2, 0; 0, 0, 0, 0, 3; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0]))
-%!assert (diag (int8 ([1; 2; 3]),-1), int8 ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]))
-%!assert (diag (int8 ([1; 2; 3]),-2), int8 ([0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 1, 0, 0, 0, 0; 0, 2, 0, 0, 0; 0, 0, 3, 0, 0]))
-
-%!assert (diag (int8 ([1, 0, 0; 0, 2, 0; 0, 0, 3])), int8 ([1; 2; 3]))
-%!assert (diag (int8 ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]), 1), int8 ([1; 2; 3]))
-%!assert (diag (int8 ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]), -1), int8 ([1; 2; 3]))
-
-## Test input validation
-%!error diag ()
-%!error diag (1,2,3,4)
+
+%!assert(full (diag ([1; 2; 3])), [1, 0, 0; 0, 2, 0; 0, 0, 3])
+%!assert(diag ([1; 2; 3], 1), [0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0])
+%!assert(diag ([1; 2; 3], 2), [0, 0, 1, 0, 0; 0, 0, 0, 2, 0; 0, 0, 0, 0, 3; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0])
+%!assert(diag ([1; 2; 3],-1), [0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0])
+%!assert(diag ([1; 2; 3],-2), [0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 1, 0, 0, 0, 0; 0, 2, 0, 0, 0; 0, 0, 3, 0, 0])
+
+%!assert(diag ([1, 0, 0; 0, 2, 0; 0, 0, 3]), [1; 2; 3])
+%!assert(diag ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0], 1), [1; 2; 3])
+%!assert(diag ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0], -1), [1; 2; 3])
+%!assert(diag (ones(1, 0), 2), zeros (2))
+%!assert(diag (1:3, 4, 2), [1, 0; 0, 2; 0, 0; 0, 0])
+
+%!assert(full (diag (single([1; 2; 3]))), single([1, 0, 0; 0, 2, 0; 0, 0, 3]))
+%!assert(diag (single([1; 2; 3]), 1), single([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]))
+%!assert(diag (single([1; 2; 3]), 2), single([0, 0, 1, 0, 0; 0, 0, 0, 2, 0; 0, 0, 0, 0, 3; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0]))
+%!assert(diag (single([1; 2; 3]),-1), single([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]))
+%!assert(diag (single([1; 2; 3]),-2), single([0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 1, 0, 0, 0, 0; 0, 2, 0, 0, 0; 0, 0, 3, 0, 0]))
+
+%!assert(diag (single([1, 0, 0; 0, 2, 0; 0, 0, 3])), single([1; 2; 3]))
+%!assert(diag (single([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]), 1), single([1; 2; 3]))
+%!assert(diag (single([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]), -1), single([1; 2; 3]))
+
+%!assert(diag (int8([1; 2; 3])), int8([1, 0, 0; 0, 2, 0; 0, 0, 3]))
+%!assert(diag (int8([1; 2; 3]), 1), int8([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]))
+%!assert(diag (int8([1; 2; 3]), 2), int8([0, 0, 1, 0, 0; 0, 0, 0, 2, 0; 0, 0, 0, 0, 3; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0]))
+%!assert(diag (int8([1; 2; 3]),-1), int8([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]))
+%!assert(diag (int8([1; 2; 3]),-2), int8([0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 1, 0, 0, 0, 0; 0, 2, 0, 0, 0; 0, 0, 3, 0, 0]))
+
+%!assert(diag (int8([1, 0, 0; 0, 2, 0; 0, 0, 3])), int8([1; 2; 3]))
+%!assert(diag (int8([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]), 1), int8([1; 2; 3]))
+%!assert(diag (int8([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]), -1), int8([1; 2; 3]))
+
+## Test non-square size
+%!assert(diag ([1,2,3], 6, 3), [1 0 0; 0 2 0; 0 0 3; 0 0 0; 0 0 0; 0 0 0])
+
+%% Test input validation
+%!error <Invalid call to diag> diag ()
+%!error <Invalid call to diag> diag (1,2,3,4)
 %!error diag (ones (2), 3, 3)
 %!error diag (1:3, -4, 3)
-*/
+
+ */
 
 DEFUN (prod, args, ,
   "-*- texinfo -*-\n\