Mercurial > octave
changeset 31880:b8205aa00a05 stable
bicg: Allow variable number of input arguments in functions (bug #63860).
* scripts/sparse/private/__alltohandles__.m: Allow variable number of arguments
in function handles created for bicg.
* scripts/sparse/bicg.m: Add BIST with additional input argument.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Thu, 02 Mar 2023 16:07:12 +0100 |
parents | 942ca5f2c71c |
children | 95e06f13fde3 436f771403bc 75b1efe727d4 |
files | scripts/sparse/bicg.m scripts/sparse/private/__alltohandles__.m |
diffstat | 2 files changed, 22 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/sparse/bicg.m Thu Mar 02 21:42:42 2023 -0500 +++ b/scripts/sparse/bicg.m Thu Mar 02 16:07:12 2023 +0100 @@ -546,3 +546,16 @@ %! ## b has two columns! %! [y, flag] = bicg (M1 \ A / M2, [M1 \ b, M2' \ b], [], 1); %! assert (x, M2 \ y, 8 * eps); + +%!test <*63860> +%! ## additional input argument +%! n = 10; +%! s = 1e-3; +%! tol = 1e-6; +%! a = ones (n, 1); +%! a = a / norm (a); +%! y = zeros (n, 1); +%! y(1:2:n) = 1; +%! Amat = @(x, type, s) x + (s * a) * (a' * x); +%! [x, flag] = bicg (Amat, y, tol, [], [], [], y, s); +%! assert (y, Amat (x, [], s), tol * norm (y));
--- a/scripts/sparse/private/__alltohandles__.m Thu Mar 02 21:42:42 2023 -0500 +++ b/scripts/sparse/private/__alltohandles__.m Thu Mar 02 16:07:12 2023 +0100 @@ -80,8 +80,8 @@ ## methods which do not require the transpose M1fcn = @(x) x; case {"bicg"} - ## methods which do require the transpose - M1fcn = @(x, ~) x; + ## methods allow a variable number of arguments + M1fcn = @(x, varargin) x; otherwise error (["__alltohandles__: unknown method: ", solver_name]); endswitch @@ -103,8 +103,8 @@ ## methods which do not require the transpose M2fcn = @(x) x; case {"bicg"} - ## methods which do require the transpose - M2fcn = @(x, ~) x; + ## methods allow a variable number of arguments + M2fcn = @(x, varargin) x; otherwise error (["__alltohandles__: unknown method: ", solver_name]); endswitch @@ -133,15 +133,16 @@ M2fcn = @(x) M2 \ x; endif case {"bicg"} - ## methods which do require the transpose + ## methods which require the transpose and allow a variable number of + ## arguments if (A_is_numeric) - Afcn = @(x, trans) A_sub (A, x, trans); + Afcn = @(x, trans, varargin) A_sub (A, x, trans); endif if (M1_is_numeric) - M1fcn = @(x, trans) M_sub (M1, x, trans); + M1fcn = @(x, trans, varargin) M_sub (M1, x, trans); endif if (M2_is_numeric) - M2fcn = @(x, trans) M_sub (M2, x, trans); + M2fcn = @(x, trans, varargin) M_sub (M2, x, trans); endif otherwise error (["__alltohandles__: unknown method: ", solver_name]);