File: spqr_repeatable.m

package info (click to toggle)
suitesparse 1%3A7.10.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 254,920 kB
  • sloc: ansic: 1,134,743; cpp: 46,133; makefile: 4,875; fortran: 2,087; java: 1,826; sh: 996; ruby: 725; python: 495; asm: 371; sed: 166; awk: 44
file content (31 lines) | stat: -rw-r--r-- 1,188 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function private_stream = spqr_repeatable (seed)
%SPQR_REPEATABLE ensure repeatable results, or use the default random stream.
% Uses RandStream for repeatable results, which is not available on MATLAB 7.6
% or earlier (R2008a).  For that version of MATLAB (or earlier), the seed is
% ignored and the default random stream is always used.
% Not user-callable.

% spqr_rank, Copyright (c) 2012, Leslie Foster and Timothy A Davis.
% All Rights Reserved.
% SPDX-License-Identifier: BSD-3-clause

% Since this code is called very often, use 'version', which is perhaps 100
% times faster than 'verLessThan'.
v = sscanf (version, '%d.%d.%d') ;
v = 10.^(0:-1:-(length(v)-1)) * v ;

if (v < 7.7)
    % MATLAB 7.6 and earlier do not have RandStream, so spqr_rank ignores
    % the opts.repeatable option and just uses the default random stream.
    private_stream = [ ] ;
elseif (seed == 1)
    % use a new strearm with the default random seed
    private_stream = RandStream ('mt19937ar') ;
elseif (seed > 1)
    % use a new stream with a specific random seed
    private_stream = RandStream ('mt19937ar', 'seed', seed) ;
else
    % do not use the private stream
    private_stream = [ ] ;
end