-
Notifications
You must be signed in to change notification settings - Fork 29
/
opiChol.m
103 lines (89 loc) · 3.4 KB
/
opiChol.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
92
93
94
95
96
97
98
99
100
101
102
103
classdef opiChol < opFactorization
%opiChol Operator representing the incomplete Cholesky factorization of a
% symmetric and definitematrix with optional iterative refinement.
%
% opiChol(A) creates an operator for multiplication by an approximate
% inverse of the matrix A implicitly represented by its incomplete
% Cholesky factorization. Optionally, iterative refinement is performed.
% Note that A is an explicit matrix.
%
% Additional input arguments are passed directly to ichol() with the
% exception of the 'shape' attribute.
%
% The following attributes may be changed by the user:
% * nitref : the maximum number of iterative refinement steps (3)
% * itref_tol : iterative refinement tolerance (1.0e-8)
% * force_itref : force iterative refinement (false)
%
% See also ichol.
%
% Dominique Orban <[email protected]>, 2014.
%
% Copyright 2009, Ewout van den Berg and Michael P. Friedlander
% See the file COPYING.txt for full copyright information.
% Use the command 'spot.gpl' to locate this file.
% http://www.cs.ubc.ca/labs/scl/spot
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Properties
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
properties( SetAccess = private )
L % Lower triangular incomplete factor
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Methods - Public
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
methods
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% opiChol. Constructor
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function op = opiChol(A, varargin)
[m,n] = size(A);
if m ~= n
error('Input matrix must be square');
end
% Construct operator
op = op@opFactorization('iChol', n, n);
B = A;
if ~issparse(A)
B = sparse(A);
end
op.A = opMatrix(B);
if nargin > 1
opts = varargin{1};
end
opts.shape = 'lower';
op.L = ichol(B, opts);
op.Ainv = inv(op.L') * inv(op.L);
op.cflag = ~isreal(A);
end % function opiChol
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% transpose
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function opOut = transpose(op)
opOut = inv(op.L.') * inv(op.L);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% conj
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function opOut = conj(op)
opOut = inv(conj(op.L')) * inv(conj(op.L));
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ctranpose
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function opOut = ctranspose(op)
opOut = op.Ainv;
end
end % methods - public
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Methods - Protected
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
methods( Access = protected )
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% divide
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function x = divide(op, b, mode)
x = op.L * (op.L' * b); % Not the same as op.A * b.
end % function divide
end % methods - protected
end % classdef