-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathtoeplitzBlockToeplitz.m
172 lines (149 loc) · 5.33 KB
/
toeplitzBlockToeplitz.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
classdef toeplitzBlockToeplitz < handle
properties
nRow;
nCol;
nBlockRow;
nBlockCol;
elements;
bytes;
elementsFT;
lambda;
mu;
xi;
na;
inverse;
tag = 'Toeplitz-Block-Toeplitz';
end
properties (Access=private)
log
end
methods
function obj = toeplitzBlockToeplitz(nmBlock, blockNM,T)
obj.nBlockRow = nmBlock(1);
obj.nBlockCol = nmBlock(2);
obj.nRow = blockNM(1);
obj.nCol = blockNM(2);
obj.elements = T(end:-1:1,end:-1:1);
a = obj.elements;
a = a(:);
obj.na = length(a);
%obj.na = pow2(nextpow2(obj.na));
obj.elementsFT = fft(a,obj.na);
n = obj.nCol;
m = obj.nRow;
[i1,i2] = ndgrid ( 1-m:n-1 ,1-m:n-1 );
obj.lambda = ( (m + i1 - 1)*(m+n-1) + (m + i2 -1) )';
[j1,j2] = ndgrid ( 1:n );
mu_ = (m+n)*(n-1)-(j1-1)*(m+n-1)-(j2-1);
obj.mu = mu_'+1;
[j1,j2] = ndgrid ( 1:m );
xi_ = (m+n)*(m+n-1) - j1*(m+n-1) - j2;
obj.xi = xi_'+1;
obj.log = logBook.checkIn(obj);
%display(obj)
end
%% Destructor
function delete(obj)
if ~isempty(obj.log)
checkOut(obj.log,obj)
end
end
function display(obj)
%% DISPLAY Display object information
%
% display(obj) prints information about the toeplitzBlockToeplitz object
fprintf('___ %s ___\n',obj.tag)
fprintf(' . number of blocks: %dX%d\n',obj.nBlockRow,obj.nBlockCol);
fprintf(' . size of blocks: %dX%d\n',obj.nRow,obj.nCol);
fprintf(' . compression factor: %4.0f \n',compressionFactor(obj));
fprintf('----------------------------------------------------\n')
end
function t = full(obj,mask)
T = cell(1,obj.nBlockRow+obj.nBlockCol-1);
for k=1:length(T)
T{k} = full( toeplitzMat( obj.nRow , obj.nCol , obj.elements(:,k) ) );
end
p = obj.nBlockCol;
m = obj.nBlockRow;
x = T; % build vector of user data
cidx = (0:m-1)';
ridx = p:-1:1;
t = cidx(:,ones(p,1)) + ridx(ones(m,1),:); % Toeplitz subscripts
t = x(t); % actual data
t = cell2mat(t);
if nargin>1 && ~isempty(mask)
t(mask,:)=[];
t(:,mask)=[];
end
end
function out = transpose(obj)
% b = a.' computes the non-conjugate transpose of matrix a and
% returns the result in b.
T = obj.elements(:,end:-1:1);
T = T(end:-1:1,:);
out = toeplitzBlockToeplitz(...
[obj.nBlockRow,obj.nBlockCol],...
[obj.nRow,obj.nCol],...
T);
end
function out = ctranspose(obj)
% b = a' computes the complex conjugate transpose of matrix a
% and returns the result in b
T = obj.elements(:,end:-1:1);
T = T(end:-1:1,:);
T = conj(T);
out = toeplitzBlockToeplitz(...
[obj.nBlockRow,obj.nBlockCol],...
[obj.nRow,obj.nCol],...
T);
end
function out = mtimes(obj,b)
% c = T*b multiplies the matrix by the vector b
nU = (obj.nBlockRow+obj.nBlockCol-1)*(obj.nRow+obj.nCol-1);
U = zeros(nU,1);
U(obj.mu(:)) = b;
P = ifft(obj.elementsFT.*fft(U,obj.na));
out = P(obj.xi(:));
end
function out = mldivide(obj,c)
% b = T\c solves Tb = c
if isempty(obj.inverse)
add(obj.log,obj,'Computing the inverse...')
obj.inverse = inv( full(obj) );
end
out = obj.inverse*c;
end
function P = debugGpu(obj,b)
obj.na = (obj.nBlockRow+obj.nBlockCol-1)*(obj.nRow+obj.nCol-1);
U = zeros(obj.na,1);
U(obj.mu(:)) = b;
obj.na = pow2(nextpow2(obj.na));
P = obj.elementsFT.*fft(U,obj.na);
% P = ifft(obj.elementsFT.*fft(U,na));
% out = P(obj.xi(:));
end
function out = maskedMtimes(obj,b,mask)
out = mask.*mtimes(obj,b);
end
% function out = size(obj,idx)
% out = [obj.nBlockRow*obj.nRow,obj.nBlockCol*obj.nCol];
% if nargin>1
% out = out(idx);
% end
% end
%
% function out = length(obj)
% out = max( size( obj ) );
% end
%
function out = numel(obj)
out = 1;
end
function out = nnz(obj)
out = (obj.nBlockRow+obj.nBlockCol-1).*(obj.nRow+obj.nCol-1);
end
function out = compressionFactor(obj)
out = prod( [obj.nBlockRow*obj.nRow,obj.nBlockCol*obj.nCol] )/nnz(obj);
end
end
end