forked from mpf/spot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopLDL.m
102 lines (91 loc) · 3.42 KB
/
opLDL.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
classdef opLDL < opFactorization
%OPLDL Operator representing the LDL factorization of a symmetric
% matrix with optional iterative refinement. Only the lower
% triangle of the input matrix is referenced. This is currently
% only available for real matrices. If the matrix
% is known to be definite, opChol will be more efficient.
%
% opLDL(A) creates an operator for multiplication by the
% inverse of the matrix A implicitly represented by its LDL
% factorization. Optionally, iterative refinement is performed.
% Note that A is an explicit matrix.
%
% opLDL(A, thresh) sets the pivot tolerance to thresh.
%
% 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 ldl.
%
% 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 )
P % Permutation operator
L % Lower triangular factor
D % (Block-)diagonal factor
nnzL % Number of nonzeros in strict lower triangle of L
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Methods - Public
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
methods
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% opLDL. Constructor
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function op = opLDL(A, thresh)
if nargin > 2
error('Invalid number of arguments.');
end
% Get size of input matrix
n = size(A,1);
if n ~= size(A,2)
error('Input matrix must be square.');
end
% Construct operator
op = op@opFactorization('LDL', n, n);
B = A;
if ~issparse(A)
B = sparse(A);
end
op.A = opHermitian(B);
if nargin == 2
[L, D, p] = ldl(tril(B), thresh, 'vector');
else
[L, D, p] = ldl(tril(B), 'vector');
end
op.nnzL = nnz(L) - n; % L contains a unit diagonal.
op.L = opMatrix(L);
op.D = opMatrix(D);
op.P = opPermutation(p);
op.Ainv = op.P' * inv(op.L') * inv(op.D) * inv(op.L) * op.P;
op.cflag = ~isreal(A);
end % function opLDL
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% transpose
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function opOut = transpose(op)
opOut = op;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% conj
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function opOut = conj(op)
opOut = op;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ctranpose
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function opOut = ctranspose(op)
opOut = op;
end
end % methods - public
end % classdef