Skip to content
Snippets Groups Projects
Commit 4f50ae6e authored by adjemian's avatar adjemian
Browse files

Updated tests for kronecker products.

git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@1825 ac1d8469-bf42-47a9-8791-bf33cf982152
parent 45268c43
No related branches found
No related tags found
No related merge requests found
...@@ -2,7 +2,7 @@ function test_kron(test) ...@@ -2,7 +2,7 @@ function test_kron(test)
if ~nargin if ~nargin
test = 1; test = 3;
end end
...@@ -64,20 +64,27 @@ function test_kron(test) ...@@ -64,20 +64,27 @@ function test_kron(test)
disp(' ') disp(' ')
disp('Direct computation of A*kron(B,B):') disp('Direct computation of A*kron(B,B):')
tic tic
try
D4 = A*kron(B,B); D4 = A*kron(B,B);
notest = 0;
catch
notest = 1;
disp('Out of memory')
end
toc toc
if ~notest
disp(''); disp('');
disp(['Difference between D1 and D4 = ' num2str(max(max(abs(D1-D4))))]); disp(['Difference between D1 and D4 = ' num2str(max(max(abs(D1-D4))))]);
end
end end
if test > 1
if test == 2 hessian = 0;
load nash_matrices; load nash_matrices;
r2 = size(zx,1); r2 = size(zx,1);
...@@ -99,10 +106,10 @@ if test == 2 ...@@ -99,10 +106,10 @@ if test == 2
D2 = sparse_hessian_times_B_kronecker_C(hessian,zx,zx); D2 = sparse_hessian_times_B_kronecker_C(hessian,zx,zx);
toc toc
% $$$ disp(''); disp('');
% $$$ disp(['Difference between D1 and D2 = ' num2str(max(max(abs(D1-D2))))]); disp(['Difference between D1 and D2 = ' num2str(max(max(abs(D1-D2))))]);
% $$$
% $$$ disp(' ') disp(' ')
% $$$ disp('Computation of A*kron(B,B) with two nested loops:') % $$$ disp('Computation of A*kron(B,B) with two nested loops:')
% $$$ tic % $$$ tic
% $$$ D3 = zeros(r1,c2*c2); % $$$ D3 = zeros(r1,c2*c2);
...@@ -122,3 +129,17 @@ if test == 2 ...@@ -122,3 +129,17 @@ if test == 2
disp(['Percentage of non zero elements in the result matrix = ' num2str(100*nnz(D1)/(r1*c2^2)) '%']); disp(['Percentage of non zero elements in the result matrix = ' num2str(100*nnz(D1)/(r1*c2^2)) '%']);
end end
if test>2
A = randn(100,100);
B = randn(10,10);
C = randn(10,10);
disp('Test with full format matrix -- 1')
D1 = A*kron(B,C);
D2 = A_times_B_kronecker_C(A,B,C);
disp(['Difference between D1 and D2 = ' num2str(max(max(abs(D1-D2))))]);
disp('Test with full format matrix -- 1')
D1 = A*kron(B,B);
D2 = A_times_B_kronecker_C(A,B);
disp(['Difference between D1 and D2 = ' num2str(max(max(abs(D1-D2))))]);
end
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment