%!shared n, k, A, u, s, v, opts, rand_state, randn_state, tol
%! n = 100;
%! k = 7;
%! A = sparse ([3:n,1:n,1:(n-2)],[1:(n-2),1:n,3:n],[ones(1,n-2),0.4*n*ones(1,n),ones(1,n-2)]);
%! [u,s,v] = svd (full (A));
%! s = diag (s);
%! [~, idx] = sort (abs (s));
%! s = s(idx);
%! u = u(:, idx);
%! v = v(:, idx);
%! rand_state = rand ("state");
%! rand ("state", 42);
%! opts.v0 = rand (2*n,1);  # Initialize eigs ARPACK starting vector
%!                          # to guarantee reproducible results

%!testif HAVE_ARPACK
%! [u2,s2,v2,flag] = svds (A,k);
%! s2 = diag (s2);
%! assert (flag, ! 1);
%! tol = 10 * eps() * norm(s2, 1);
%! assert (s2, s(end:-1:end-k+1), tol);
