# HG changeset patch # User Rik # Date 1428319127 25200 # Node ID 91e1da1d19183c23cfae2807c2448e131a665ec1 # Parent 7cefb9e7bc9ff0263e32d2a65d60d882797eb989 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. diff -r 7cefb9e7bc9f -r 91e1da1d1918 scripts/linear-algebra/linsolve.m --- 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;