changeset 20065:91e1da1d1918

linsolve.m: Calculate solution in a BLAS-optimized way (bug #44722). * linsolve.m: When transpose option is given, forward the transpose flag to BLAS rather than calculating the transpose in Octave and then forwarding the left-division operator to BLAS. Fixes inconsistency in BIST tests.
author Rik <rik@octave.org>
date Mon, 06 Apr 2015 04:18:47 -0700
parents 7cefb9e7bc9f
children c66909c234e6
files scripts/linear-algebra/linsolve.m
diffstat 1 files changed, 13 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/linear-algebra/linsolve.m	Mon Apr 06 09:42:15 2015 +0200
+++ b/scripts/linear-algebra/linsolve.m	Mon Apr 06 04:18:47 2015 -0700
@@ -87,28 +87,24 @@
     trans_A = false;
     if (isfield (opts, "TRANSA") && opts.TRANSA)
       trans_A = true;
-      A = A';
     endif
     if (isfield (opts, "POSDEF") && opts.POSDEF)
       A = matrix_type (A, "positive definite");
     endif
     if (isfield (opts, "LT") && opts.LT)
-      if (trans_A)
-        A = matrix_type (A, "upper");
-      else
-        A = matrix_type (A, "lower");
-      endif
-    endif
-    if (isfield (opts, "UT") && opts.UT)
-      if (trans_A)
-        A = matrix_type (A, "lower");
-      else
-        A = matrix_type (A, "upper");
-      endif
+      A = matrix_type (A, "lower");
+    elseif (isfield (opts, "UT") && opts.UT)
+      A = matrix_type (A, "upper");
     endif
   endif
 
-  x = A \ b;
+  ## This way is faster as the transpose is not calculated in Octave,
+  ## but forwarded as a flag option to BLAS.
+  if (trans_A)
+    x = A' \ b;
+  else
+    x = A \ b;
+  endif
 
   if (nargout > 1)
     if (issquare (A))
@@ -117,12 +113,13 @@
       R = 0;
     endif
   endif
+
 endfunction
 
 
 %!test
-%! n = 4;
-%! A = triu (rand (n));
+%! n = 10;
+%! A = triu (gallery ("condex", n));
 %! x = rand (n, 1);
 %! b = A' * x;
 %! opts.UT = true;