-
Notifications
You must be signed in to change notification settings - Fork 8
/
halroption.m
92 lines (80 loc) · 2.33 KB
/
halroption.m
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
function opt = halroption(key, value)
%HALROPTION Set or get an option for the halr toolbox.
%
% Valid options are:
% 'block-size': Integer representing the minimum block size.
% 'threshold': Value used for off-diagonal truncation.
% 'compression': String indicating the strategy of compression (qr or svd)
% 'norm': Norm to use in truncations (2 or 'fro')
global halr_block_size
global halr_threshold
global halr_compression
global halr_norm
% Private options -- not exposed to users
% This option sets the maximum allowed rank for low-rank blocks with
% respect the dimension: for a block of size (m,n) the maximum allowed rank
% is halroption('rank-ratio') * min(m,n)
global halr_rank_ratio
if isempty(halr_rank_ratio)
halr_rank_ratio = 0.5;
end
if isempty(halr_block_size)
halr_block_size = 256;
end
if isempty(halr_compression)
halr_compression = 'svd';
end
if isempty(halr_threshold)
halr_threshold = 1e-12;
end
if isempty(halr_norm)
halr_norm = 2;
end
if ~exist('key', 'var')
error('Please specify a key');
end
if ~exist('value', 'var')
switch key
case 'block-size'
opt = halr_block_size;
case 'threshold'
opt = halr_threshold;
case 'compression'
opt = halr_compression;
case 'norm'
opt = halr_norm;
case 'rank-ratio'
opt = halr_rank_ratio;
otherwise
error('Unsupported option specified');
end
else
switch key
case 'block-size'
if value <= 2
error('minimum block size must be at least 3');
else
halr_block_size = value;
end
case 'threshold'
if value < 0
error('threshold has to be positive');
else
halr_threshold = max(eps, value);
end
case 'norm'
if (isscalar(value) && value ~= 2) && ~strcmp(value, 'fro')
error('Unsupported norm specified');
else
halr_norm = value;
end
case 'compression'
if strcmp(value,'qr') || strcmp(value, 'svd')
halr_compression = value;
else
error('Unsupported type of compression');
end
otherwise
error('Unsupported option specified');
end
end