Mentions légales du service

Skip to content
Snippets Groups Projects
Commit bbc714b9 authored by hhakim's avatar hhakim
Browse files

Label all matfaust unit tests and remove junk output to lighten test reports.

parent 43973491
No related branches found
No related tags found
No related merge requests found
...@@ -37,8 +37,8 @@ classdef FaustFactoryTest < matlab.unittest.TestCase ...@@ -37,8 +37,8 @@ classdef FaustFactoryTest < matlab.unittest.TestCase
cons{2} = ConstraintReal(ConstraintName(ConstraintName.NORMCOL), 32, 32, 1.0); cons{2} = ConstraintReal(ConstraintName(ConstraintName.NORMCOL), 32, 32, 1.0);
stop_crit = StoppingCriterion(200); stop_crit = StoppingCriterion(200);
params = ParamsPalm4MSA(cons, stop_crit, 'is_update_way_R2L', is_update_way_R2L, 'init_lambda', init_lambda, 'step_size', ParamsFact.DEFAULT_STEP_SIZE,... params = ParamsPalm4MSA(cons, stop_crit, 'is_update_way_R2L', is_update_way_R2L, 'init_lambda', init_lambda, 'step_size', ParamsFact.DEFAULT_STEP_SIZE,...
'constant_step_size', ParamsFact.DEFAULT_CONSTANT_STEP_SIZE); 'constant_step_size', ParamsFact.DEFAULT_CONSTANT_STEP_SIZE);
F = matfaust.fact.palm4msa(M, params) F = matfaust.fact.palm4msa(M, params);
this.verifyEqual(size(F), size(M)) this.verifyEqual(size(F), size(M))
%disp('norm F: ') %disp('norm F: ')
%norm(F, 'fro') %norm(F, 'fro')
...@@ -69,8 +69,8 @@ classdef FaustFactoryTest < matlab.unittest.TestCase ...@@ -69,8 +69,8 @@ classdef FaustFactoryTest < matlab.unittest.TestCase
cons{2} = ConstraintReal(ConstraintName(ConstraintName.NORMCOL), 32, 32, 1.0); cons{2} = ConstraintReal(ConstraintName(ConstraintName.NORMCOL), 32, 32, 1.0);
stop_crit = StoppingCriterion(200); stop_crit = StoppingCriterion(200);
params = ParamsPalm4MSA(cons, stop_crit, 'is_update_way_R2L', is_update_way_R2L, 'init_lambda', init_lambda, 'step_size', ParamsFact.DEFAULT_STEP_SIZE,... params = ParamsPalm4MSA(cons, stop_crit, 'is_update_way_R2L', is_update_way_R2L, 'init_lambda', init_lambda, 'step_size', ParamsFact.DEFAULT_STEP_SIZE,...
'constant_step_size', ParamsFact.DEFAULT_CONSTANT_STEP_SIZE); 'constant_step_size', ParamsFact.DEFAULT_CONSTANT_STEP_SIZE);
F = matfaust.fact.palm4msa(M, params, 'backend', 2020) F = matfaust.fact.palm4msa(M, params, 'backend', 2020);
this.verifyEqual(size(F), size(M)) this.verifyEqual(size(F), size(M))
%disp('norm F: ') %disp('norm F: ')
%norm(F, 'fro') %norm(F, 'fro')
...@@ -97,7 +97,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase ...@@ -97,7 +97,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase
cons{2} = ConstraintReal(ConstraintName(ConstraintName.NORMCOL), 32, 32, 1.0); cons{2} = ConstraintReal(ConstraintName(ConstraintName.NORMCOL), 32, 32, 1.0);
stop_crit = StoppingCriterion(200); stop_crit = StoppingCriterion(200);
params = ParamsPalm4MSA(cons, stop_crit, 'is_update_way_R2L', is_update_way_R2L, 'init_lambda', init_lambda); params = ParamsPalm4MSA(cons, stop_crit, 'is_update_way_R2L', is_update_way_R2L, 'init_lambda', init_lambda);
F = matfaust.fact.palm4msa(M, params) F = matfaust.fact.palm4msa(M, params);
this.verifyEqual(size(F), size(M)) this.verifyEqual(size(F), size(M))
%disp('norm F: ') %disp('norm F: ')
%norm(F, 'fro') %norm(F, 'fro')
...@@ -125,7 +125,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase ...@@ -125,7 +125,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase
cons{2} = ConstraintReal(ConstraintName(ConstraintName.NORMCOL), 32, 32, 1.0); cons{2} = ConstraintReal(ConstraintName(ConstraintName.NORMCOL), 32, 32, 1.0);
stop_crit = StoppingCriterion(200); stop_crit = StoppingCriterion(200);
params = ParamsPalm4MSA(cons, stop_crit, 'is_update_way_R2L', is_update_way_R2L, 'init_lambda', init_lambda, 'init_facts', init_facts); params = ParamsPalm4MSA(cons, stop_crit, 'is_update_way_R2L', is_update_way_R2L, 'init_lambda', init_lambda, 'init_facts', init_facts);
F = matfaust.fact.palm4msa(M, params) F = matfaust.fact.palm4msa(M, params);
this.verifyEqual(size(F), size(M)) this.verifyEqual(size(F), size(M))
%disp('norm F: ') %disp('norm F: ')
%norm(F, 'fro') %norm(F, 'fro')
...@@ -153,7 +153,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase ...@@ -153,7 +153,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase
cons{2} = ConstraintReal(ConstraintName(ConstraintName.NORMCOL), 32, 32, 1.0); cons{2} = ConstraintReal(ConstraintName(ConstraintName.NORMCOL), 32, 32, 1.0);
stop_crit = StoppingCriterion(200); stop_crit = StoppingCriterion(200);
params = ParamsPalm4MSA(cons, stop_crit, 'is_update_way_R2L', is_update_way_R2L, 'init_lambda', init_lambda, 'init_facts', init_facts); params = ParamsPalm4MSA(cons, stop_crit, 'is_update_way_R2L', is_update_way_R2L, 'init_lambda', init_lambda, 'init_facts', init_facts);
F = matfaust.fact.palm4msa(M, params, 'backend', 2020) F = matfaust.fact.palm4msa(M, params, 'backend', 2020);
this.verifyEqual(size(F), size(M)) this.verifyEqual(size(F), size(M))
%disp('norm F: ') %disp('norm F: ')
%norm(F, 'fro') %norm(F, 'fro')
...@@ -196,7 +196,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase ...@@ -196,7 +196,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase
%init_facts = cell(num_facts,1); %init_facts = cell(num_facts,1);
%init_facts{1} = zeros(500,32); %init_facts{1} = zeros(500,32);
%for i=2:num_facts %for i=2:num_facts
%init_facts{i} = zeros(32); %init_facts{i} = zeros(32);
%end %end
%M = rand(500, 32) %M = rand(500, 32)
load([this.faust_paths{1},'../../../misc/data/mat/matrix_hierarchical_fact.mat']) load([this.faust_paths{1},'../../../misc/data/mat/matrix_hierarchical_fact.mat'])
...@@ -213,7 +213,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase ...@@ -213,7 +213,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase
stop_crit = StoppingCriterion(200); stop_crit = StoppingCriterion(200);
stop_crit2 = StoppingCriterion(200); stop_crit2 = StoppingCriterion(200);
params = ParamsHierarchical(fact_cons, res_cons, stop_crit, stop_crit2); params = ParamsHierarchical(fact_cons, res_cons, stop_crit, stop_crit2);
F = matfaust.fact.hierarchical(M, params) F = matfaust.fact.hierarchical(M, params);
this.verifyEqual(size(F), size(M)) this.verifyEqual(size(F), size(M))
%disp('norm F: ') %disp('norm F: ')
%norm(F, 'fro') %norm(F, 'fro')
...@@ -234,7 +234,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase ...@@ -234,7 +234,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase
%init_facts = cell(num_facts,1); %init_facts = cell(num_facts,1);
%init_facts{1} = zeros(500,32); %init_facts{1} = zeros(500,32);
%for i=2:num_facts %for i=2:num_facts
%init_facts{i} = zeros(32); %init_facts{i} = zeros(32);
%end %end
%M = rand(500, 32) %M = rand(500, 32)
load([this.faust_paths{1},'../../../misc/data/mat/matrix_hierarchical_fact.mat']) load([this.faust_paths{1},'../../../misc/data/mat/matrix_hierarchical_fact.mat'])
...@@ -251,7 +251,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase ...@@ -251,7 +251,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase
stop_crit = StoppingCriterion(200); stop_crit = StoppingCriterion(200);
stop_crit2 = StoppingCriterion(200); stop_crit2 = StoppingCriterion(200);
params = ParamsHierarchical(fact_cons, res_cons, stop_crit, stop_crit2); params = ParamsHierarchical(fact_cons, res_cons, stop_crit, stop_crit2);
F = matfaust.fact.hierarchical(M, params, 'backend', 2020) F = matfaust.fact.hierarchical(M, params, 'backend', 2020);
this.verifyEqual(size(F), size(M)) this.verifyEqual(size(F), size(M))
%disp('norm F: ') %disp('norm F: ')
%norm(F, 'fro') %norm(F, 'fro')
...@@ -272,7 +272,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase ...@@ -272,7 +272,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase
%init_facts = cell(num_facts,1); %init_facts = cell(num_facts,1);
%init_facts{1} = zeros(500,32); %init_facts{1} = zeros(500,32);
%for i=2:num_facts %for i=2:num_facts
%init_facts{i} = zeros(32); %init_facts{i} = zeros(32);
%end %end
%M = rand(500, 32) %M = rand(500, 32)
load([this.faust_paths{1},'../../../misc/data/mat/matrix_hierarchical_fact.mat']) load([this.faust_paths{1},'../../../misc/data/mat/matrix_hierarchical_fact.mat'])
...@@ -289,8 +289,8 @@ classdef FaustFactoryTest < matlab.unittest.TestCase ...@@ -289,8 +289,8 @@ classdef FaustFactoryTest < matlab.unittest.TestCase
stop_crit = StoppingCriterion(200); stop_crit = StoppingCriterion(200);
stop_crit2 = StoppingCriterion(200); stop_crit2 = StoppingCriterion(200);
params = ParamsHierarchical(fact_cons, res_cons, stop_crit, stop_crit2,... params = ParamsHierarchical(fact_cons, res_cons, stop_crit, stop_crit2,...
'init_lambda', init_lambda, 'is_update_way_R2L', is_update_way_R2L); 'init_lambda', init_lambda, 'is_update_way_R2L', is_update_way_R2L);
F = matfaust.fact.hierarchical(M, params) F = matfaust.fact.hierarchical(M, params);
this.verifyEqual(size(F), size(M)) this.verifyEqual(size(F), size(M))
%disp('norm F: ') %disp('norm F: ')
%norm(F, 'fro') %norm(F, 'fro')
...@@ -311,7 +311,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase ...@@ -311,7 +311,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase
%init_facts = cell(num_facts,1); %init_facts = cell(num_facts,1);
%init_facts{1} = zeros(500,32); %init_facts{1} = zeros(500,32);
%for i=2:num_facts %for i=2:num_facts
%init_facts{i} = zeros(32); %init_facts{i} = zeros(32);
%end %end
%M = rand(500, 32) %M = rand(500, 32)
load([this.faust_paths{1},'../../../misc/data/mat/matrix_hierarchical_fact.mat']) load([this.faust_paths{1},'../../../misc/data/mat/matrix_hierarchical_fact.mat'])
...@@ -328,8 +328,8 @@ classdef FaustFactoryTest < matlab.unittest.TestCase ...@@ -328,8 +328,8 @@ classdef FaustFactoryTest < matlab.unittest.TestCase
stop_crit = StoppingCriterion(200); stop_crit = StoppingCriterion(200);
stop_crit2 = StoppingCriterion(200); stop_crit2 = StoppingCriterion(200);
params = ParamsHierarchical(fact_cons, res_cons, stop_crit, stop_crit2,... params = ParamsHierarchical(fact_cons, res_cons, stop_crit, stop_crit2,...
'init_lambda', init_lambda, 'is_update_way_R2L', is_update_way_R2L); 'init_lambda', init_lambda, 'is_update_way_R2L', is_update_way_R2L);
F = matfaust.fact.hierarchical(M, params, 'backend', 2020) F = matfaust.fact.hierarchical(M, params, 'backend', 2020);
this.verifyEqual(size(F), size(M)) this.verifyEqual(size(F), size(M))
%disp('norm F: ') %disp('norm F: ')
%norm(F, 'fro') %norm(F, 'fro')
...@@ -369,7 +369,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase ...@@ -369,7 +369,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase
%disp('norm F: ') %disp('norm F: ')
%norm(F, 'fro') %norm(F, 'fro')
E = F*full(D)*F'-Lap; E = F*full(D)*F'-Lap;
err = norm(E,'fro')/norm(Lap,'fro') err = norm(E,'fro')/norm(Lap,'fro');
% the error reference is from the C++ test, % the error reference is from the C++ test,
% misc/test/src/C++/EigTJ.cpp.in % misc/test/src/C++/EigTJ.cpp.in
this.verifyEqual(err, 0.0326529, 'AbsTol', 0.00001) this.verifyEqual(err, 0.0326529, 'AbsTol', 0.00001)
...@@ -439,14 +439,14 @@ classdef FaustFactoryTest < matlab.unittest.TestCase ...@@ -439,14 +439,14 @@ classdef FaustFactoryTest < matlab.unittest.TestCase
res_cons{3} = ConstraintInt(ConstraintName(ConstraintName.SP), 128, 128, 384); res_cons{3} = ConstraintInt(ConstraintName(ConstraintName.SP), 128, 128, 384);
stop_crit = StoppingCriterion(params.niter1); stop_crit = StoppingCriterion(params.niter1);
stop_crit2 = StoppingCriterion(params.niter2); stop_crit2 = StoppingCriterion(params.niter2);
params.fact_side = 0 % forced params.fact_side = 0; % forced
params.verbose = 0 % forced params.verbose = 0; % forced
params.init_lambda = 128; params.init_lambda = 128;
params.step_size = 1e-16 params.step_size = 1e-16
params.grad_calc_opt_mode = 2 params.grad_calc_opt_mode = 2
params = ParamsHierarchical(fact_cons, res_cons, stop_crit, stop_crit2, 'is_fact_side_left', params.fact_side == 1, 'is_update_way_R2L', params.update_way == 1, 'init_lambda', params.init_lambda, 'step_size', params.step_size, 'constant_step_size', false, 'is_verbose', params.verbose ~= 1); params = ParamsHierarchical(fact_cons, res_cons, stop_crit, stop_crit2, 'is_fact_side_left', params.fact_side == 1, 'is_update_way_R2L', params.update_way == 1, 'init_lambda', params.init_lambda, 'step_size', params.step_size, 'constant_step_size', false, 'is_verbose', params.verbose ~= 1);
diag_init_D = diag(init_D) diag_init_D = diag(init_D);
[F,D,lambda] = matfaust.fact.fgft_palm(U, Lap, params, diag_init_D) [F,D,lambda] = matfaust.fact.fgft_palm(U, Lap, params, diag_init_D);
this.verifyEqual(size(F), size(U)) this.verifyEqual(size(F), size(U))
%disp('norm F: ') %disp('norm F: ')
%norm(F, 'fro') %norm(F, 'fro')
...@@ -457,12 +457,13 @@ classdef FaustFactoryTest < matlab.unittest.TestCase ...@@ -457,12 +457,13 @@ classdef FaustFactoryTest < matlab.unittest.TestCase
this.verifyEqual(err, 0.0555, 'AbsTol', 0.0001) this.verifyEqual(err, 0.0555, 'AbsTol', 0.0001)
end end
function test_svdtj(this) function test_svdtj(this)
import matfaust.fact.svdtj disp('Test matfaust.fact.svdtj')
M = rand(16, 32); import matfaust.fact.svdtj
[U5, S5, V5] = svdtj(M, 'tol', 1e-3, 'enable_large_Faust', false); M = rand(16, 32);
this.verifyLessThanOrEqual(norm(U5 * S5 * V5' - M) / norm(M), 1e-3) [U5, S5, V5] = svdtj(M, 'tol', 1e-3, 'enable_large_Faust', false);
end this.verifyLessThanOrEqual(norm(U5 * S5 * V5' - M) / norm(M), 1e-3)
end
function testHadamard(this) function testHadamard(this)
disp('Test matfaust.wht()') disp('Test matfaust.wht()')
...@@ -508,7 +509,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase ...@@ -508,7 +509,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase
n = 2^log2n; n = 2^log2n;
normed_vals = {true, false}; normed_vals = {true, false};
for i=1:2 for i=1:2
normed = normed_vals{i} normed = normed_vals{i};
F = dft(n, 'normed', normed, 'diag_opt', true); F = dft(n, 'normed', normed, 'diag_opt', true);
fF = full(F); fF = full(F);
frefF = full(dft(n, 'normed', normed, 'diag_opt', false)); frefF = full(dft(n, 'normed', normed, 'diag_opt', false));
...@@ -516,33 +517,35 @@ classdef FaustFactoryTest < matlab.unittest.TestCase ...@@ -516,33 +517,35 @@ classdef FaustFactoryTest < matlab.unittest.TestCase
end end
end end
function testRandButterfly(this) function testRandButterfly(this)
import matfaust.wht disp('Test matfaust.rand_butterfly')
import matfaust.rand_butterfly import matfaust.wht
H = full(wht(32)); import matfaust.rand_butterfly
classes = {'single', 'double'}; H = full(wht(32));
fields = {'real', 'complex'}; classes = {'single', 'double'};
for i=1:2 fields = {'real', 'complex'};
for j=1:2 for i=1:2
field = fields{j} for j=1:2
if strcmp(field, 'real') field = fields{j}
class = classes{i}; if strcmp(field, 'real')
else % field == complex class = classes{i};
class = classes{2}; else % field == complex
end class = classes{2};
F = rand_butterfly(32, 'class', class, 'field', field); end
this.assertNotEqual(full(F), H); F = rand_butterfly(32, 'class', class, 'field', field);
[ref_I, ref_J, ~] = find(H); this.assertNotEqual(full(F), H);
[I, J, ~] = find(full(F)); [ref_I, ref_J, ~] = find(H);
this.assertEqual(ref_I, I); [I, J, ~] = find(full(F));
this.assertEqual(ref_J, J); this.assertEqual(ref_I, I);
end this.assertEqual(ref_J, J);
end end
end end
end
function testCircAntiCirc(this) function testCircAntiCirc(this)
disp('Test matfaust.circ/anticirc')
c = [1 2 3 4]; c = [1 2 3 4];
C = [[1 4 3 2] C = [[1 4 3 2];
[2 1 4 3] [2 1 4 3]
[3 2 1 4] [3 2 1 4]
[4 3 2 1]]; [4 3 2 1]];
...@@ -550,39 +553,40 @@ classdef FaustFactoryTest < matlab.unittest.TestCase ...@@ -550,39 +553,40 @@ classdef FaustFactoryTest < matlab.unittest.TestCase
this.assertEqual(C, real(full(matfaust.circ(c, 'diag_opt', true)))) this.assertEqual(C, real(full(matfaust.circ(c, 'diag_opt', true))))
this.assertEqual(matfaust.circ(c) * reshape(c, numel(c), 1), matfaust.circ(c, 'diag_opt', true) * reshape(c, numel(c), 1)) this.assertEqual(matfaust.circ(c) * reshape(c, numel(c), 1), matfaust.circ(c, 'diag_opt', true) * reshape(c, numel(c), 1))
A = [[2 3 4 1] A = [[2 3 4 1]
[3 4 1 2] [3 4 1 2]
[4 1 2 3] [4 1 2 3]
[1 2 3 4]]; [1 2 3 4]];
this.assertEqual(A, real(full(matfaust.anticirc(c)))) this.assertEqual(A, real(full(matfaust.anticirc(c))))
this.assertEqual(A, real(full(matfaust.anticirc(c, 'diag_opt', true)))) this.assertEqual(A, real(full(matfaust.anticirc(c, 'diag_opt', true))))
this.assertEqual(matfaust.anticirc(c) * reshape(c, numel(c), 1), matfaust.anticirc(c, 'diag_opt', true) * reshape(c, numel(c), 1)) this.assertEqual(matfaust.anticirc(c) * reshape(c, numel(c), 1), matfaust.anticirc(c, 'diag_opt', true) * reshape(c, numel(c), 1))
% not a power of two % not a power of two
c = [1 2 3 4 5]; c = [1 2 3 4 5];
C = [[1 5 4 3 2] C = [[1 5 4 3 2]
[2 1 5 4 3] [2 1 5 4 3]
[3 2 1 5 4] [3 2 1 5 4]
[4 3 2 1 5]; [4 3 2 1 5]
[5 4 3 2 1]]; [5 4 3 2 1]];
this.assertEqual(C, real(full(matfaust.circ(c))), 'AbsTol', 1e-8) this.assertEqual(C, real(full(matfaust.circ(c))), 'AbsTol', 1e-8)
this.assertEqual(C, real(full(matfaust.circ(c, 'diag_opt', true))), 'AbsTol', 1e-8) this.assertEqual(C, real(full(matfaust.circ(c, 'diag_opt', true))), 'AbsTol', 1e-8)
this.assertEqual(matfaust.circ(c) * reshape(c, numel(c), 1), matfaust.circ(c, 'diag_opt', true) * reshape(c, numel(c), 1)) this.assertEqual(matfaust.circ(c) * reshape(c, numel(c), 1), matfaust.circ(c, 'diag_opt', true) * reshape(c, numel(c), 1))
A = [[2 3 4 5 1] A = [[2 3 4 5 1]
[3 4 5 1 2] [3 4 5 1 2]
[4 5 1 2 3] [4 5 1 2 3]
[5 1 2 3 4] [5 1 2 3 4]
[1 2 3 4 5]]; [1 2 3 4 5]];
this.assertEqual(A, real(full(matfaust.anticirc(c))), 'AbsTol', 1e-8) this.assertEqual(A, real(full(matfaust.anticirc(c))), 'AbsTol', 1e-8)
this.assertEqual(A, real(full(matfaust.anticirc(c, 'diag_opt', true))), 'AbsTol', 1e-8) this.assertEqual(A, real(full(matfaust.anticirc(c, 'diag_opt', true))), 'AbsTol', 1e-8)
this.assertEqual(matfaust.anticirc(c) * reshape(c, numel(c), 1), matfaust.anticirc(c, 'diag_opt', true) * reshape(c, numel(c), 1)) this.assertEqual(matfaust.anticirc(c) * reshape(c, numel(c), 1), matfaust.anticirc(c, 'diag_opt', true) * reshape(c, numel(c), 1))
end end
function testToeplitz(this) function testToeplitz(this)
c = [1 2 3 4] disp('Test matfaust.toeplitz')
r = [1 7 8] c = [1 2 3 4];
r = [1 7 8];
T = [[1., 7., 8.] T = [[1., 7., 8.]
[2., 1., 7.] [2., 1., 7.]
[3., 2., 1.] [3., 2., 1.]
[4., 3., 2.]] [4., 3., 2.]];
this.verifyEqual(T, real(full(matfaust.toeplitz(c, r))), 'AbsTol', 1e-6) this.verifyEqual(T, real(full(matfaust.toeplitz(c, r))), 'AbsTol', 1e-6)
this.verifyEqual(T, real(full(matfaust.toeplitz(c, r, 'diag_opt', true))), 'AbsTol', 1e-6) this.verifyEqual(T, real(full(matfaust.toeplitz(c, r, 'diag_opt', true))), 'AbsTol', 1e-6)
this.verifyEqual(toeplitz(c, r), real(full(matfaust.toeplitz(c, r))), 'AbsTol', 1e-6) this.verifyEqual(toeplitz(c, r), real(full(matfaust.toeplitz(c, r))), 'AbsTol', 1e-6)
...@@ -594,6 +598,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase ...@@ -594,6 +598,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase
end end
function test_sp(this) function test_sp(this)
disp('Test matfaust.proj.sp')
import matfaust.proj.sp; import matfaust.proj.sp;
min_n = 5; min_n = 5;
min_m = 5; min_m = 5;
...@@ -610,6 +615,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase ...@@ -610,6 +615,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase
end end
function test_splincol(this) function test_splincol(this)
disp('Test matfaust.proj.splincol')
import matfaust.proj.splincol import matfaust.proj.splincol
min_n = 5; min_n = 5;
min_m = 5; min_m = 5;
...@@ -624,6 +630,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase ...@@ -624,6 +630,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase
end end
function test_spcol(this) function test_spcol(this)
disp('Test matfaust.proj.spcol')
import matfaust.proj.spcol import matfaust.proj.spcol
min_n = 5; min_n = 5;
min_m = 5; min_m = 5;
...@@ -640,6 +647,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase ...@@ -640,6 +647,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase
end end
function test_normcol(this) function test_normcol(this)
disp('Test matfaust.proj.normcol')
import matfaust.proj.normcol import matfaust.proj.normcol
min_n = 5; min_n = 5;
min_m = 5; min_m = 5;
...@@ -655,6 +663,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase ...@@ -655,6 +663,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase
end end
function test_normlin(this) function test_normlin(this)
disp('Test matfaust.proj.normlin')
import matfaust.proj.normlin import matfaust.proj.normlin
min_n = 5; min_n = 5;
min_m = 5; min_m = 5;
...@@ -670,6 +679,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase ...@@ -670,6 +679,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase
end end
function test_const(this) function test_const(this)
disp('Test matfaust.proj.const')
import matfaust.proj.const import matfaust.proj.const
min_n = 5; min_n = 5;
min_m = 5; min_m = 5;
...@@ -684,6 +694,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase ...@@ -684,6 +694,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase
end end
function test_supp(this) function test_supp(this)
disp('Test matfaust.proj.supp')
import matfaust.proj.supp import matfaust.proj.supp
min_n = 5; min_n = 5;
min_m = 5; min_m = 5;
...@@ -698,57 +709,62 @@ classdef FaustFactoryTest < matlab.unittest.TestCase ...@@ -698,57 +709,62 @@ classdef FaustFactoryTest < matlab.unittest.TestCase
end end
function test_skperm(this) function test_skperm(this)
disp('Test matfaust.proj.skperm')
import matfaust.proj.skperm import matfaust.proj.skperm
M = [-0.04440802, -0.17569296, -0.02557815, -0.15559154; M = [-0.04440802, -0.17569296, -0.02557815, -0.15559154;
-0.0083095, -3.38725936, -0.78484126, -0.4883618; -0.0083095, -3.38725936, -0.78484126, -0.4883618;
-1.48942563, -1.71787215, -0.84000212, -3.71752454; -1.48942563, -1.71787215, -0.84000212, -3.71752454;
-0.88957883, -0.19107863, -5.92900636, -6.51064175] -0.88957883, -0.19107863, -5.92900636, -6.51064175];
p = skperm(size(M), 2, 'normalized', false) p = skperm(size(M), 2, 'normalized', false);
pM_ref = [-0.04440802,0.,-0.02557815,0.; pM_ref = [-0.04440802,0.,-0.02557815,0.;
-0.0083095,-3.38725936,0.,0.; -0.0083095,-3.38725936,0.,0.;
0.,-1.71787215,0.,-3.71752454; 0.,-1.71787215,0.,-3.71752454;
0.,0.,-5.92900636,-6.51064175] 0.,0.,-5.92900636,-6.51064175];
pM = p(M) pM = p(M);
this.verifyEqual(norm(pM-pM_ref)/norm(pM_ref), 0) this.verifyEqual(norm(pM-pM_ref)/norm(pM_ref), 0)
end end
function test_sptriu(this) function test_sptriu(this)
import matfaust.proj.sptriu disp('Test matfaust.proj.sptriu')
M = rand(5, 5); import matfaust.proj.sptriu
k = 2; M = rand(5, 5);
p = sptriu(size(M), k); k = 2;
M_ = p(M); p = sptriu(size(M), k);
this.verifyEqual(numel(nonzeros(M_)), k) M_ = p(M);
this.verifyEqual(norm(tril(M_, -1)), 0) this.verifyEqual(numel(nonzeros(M_)), k)
end this.verifyEqual(norm(tril(M_, -1)), 0)
end
function test_sptril(this)
import matfaust.proj.sptril function test_sptril(this)
M = rand(5, 5); disp('Test matfaust.proj.sptril')
k = 2; import matfaust.proj.sptril
p = sptril(size(M), k); M = rand(5, 5);
M_ = p(M); k = 2;
this.verifyEqual(numel(nonzeros(M_)), k) p = sptril(size(M), k);
this.verifyEqual(norm(triu(M_, 1)), 0) M_ = p(M);
end this.verifyEqual(numel(nonzeros(M_)), k)
this.verifyEqual(norm(triu(M_, 1)), 0)
function test_spsymm(this) end
import matfaust.proj.spsymm
M = rand(5, 5); function test_spsymm(this)
k = 2; disp('Test matfaust.proj.spsymm')
p = spsymm(size(M), k); import matfaust.proj.spsymm
M_ = p(M); M = rand(5, 5);
this.verifyEqual(M_.', M_) k = 2;
this.verifyEqual(numel(nonzeros(M_)), k) p = spsymm(size(M), k);
end M_ = p(M);
this.verifyEqual(M_.', M_)
this.verifyEqual(numel(nonzeros(M_)), k)
end
function test_butterfly(this) function test_butterfly(this)
disp('Test matfaust.fact.butterfly')
import matfaust.wht import matfaust.wht
import matfaust.dft import matfaust.dft
import matfaust.fact.butterfly import matfaust.fact.butterfly
D = full(dft(64)); D = full(dft(64));
H = full(wht(64)); H = full(wht(64));
types = {'left', 'right', 'bbtree'} types = {'left', 'right', 'bbtree'};
for t=1:2 for t=1:2
if(t == 2) if(t == 2)
M = D; M = D;
...@@ -757,10 +773,10 @@ classdef FaustFactoryTest < matlab.unittest.TestCase ...@@ -757,10 +773,10 @@ classdef FaustFactoryTest < matlab.unittest.TestCase
end end
for i=1:3 for i=1:3
type = types{i}; type = types{i};
args = {M, 'type', type}; args = {M, 'type', type};
if ~ isreal(M) if ~ isreal(M)
args = [args, {'perm', 'bitrev'}]; args = [args, {'perm', 'bitrev'}];
end end
F = butterfly(args{:}); F = butterfly(args{:});
this.verifyEqual(norm(full(F)-M)/norm(M), 0, 'AbsTol', 1e-6); this.verifyEqual(norm(full(F)-M)/norm(M), 0, 'AbsTol', 1e-6);
end end
...@@ -768,6 +784,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase ...@@ -768,6 +784,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase
end end
function test_palm4msa_mhtp(this) function test_palm4msa_mhtp(this)
disp('Test matfaust.fact.palm4msa_mhtp')
import matfaust.fact.palm4msa_mhtp import matfaust.fact.palm4msa_mhtp
import matfaust.factparams.* import matfaust.factparams.*
import matfaust.proj.* import matfaust.proj.*
...@@ -776,12 +793,13 @@ classdef FaustFactoryTest < matlab.unittest.TestCase ...@@ -776,12 +793,13 @@ classdef FaustFactoryTest < matlab.unittest.TestCase
stop_crit = StoppingCriterion(200); stop_crit = StoppingCriterion(200);
param = ParamsPalm4MSA(projs, stop_crit); param = ParamsPalm4MSA(projs, stop_crit);
mhtp_param = MHTPParams('num_its', 60, 'palm4msa_period', 10); mhtp_param = MHTPParams('num_its', 60, 'palm4msa_period', 10);
G = palm4msa_mhtp(M, param, mhtp_param) G = palm4msa_mhtp(M, param, mhtp_param);
err = norm(full(G)-M)/norm(M) err = norm(full(G)-M)/norm(M)
this.verifyLessThanOrEqual(err, 0.20) this.verifyLessThanOrEqual(err, 0.20)
end end
function test_hierarchical_mhtp(this) function test_hierarchical_mhtp(this)
disp('Test matfaust.fact.hierarchical_mhtp')
import matfaust.fact.hierarchical_mhtp import matfaust.fact.hierarchical_mhtp
import matfaust.factparams.ParamsHierarchical import matfaust.factparams.ParamsHierarchical
import matfaust.factparams.StoppingCriterion import matfaust.factparams.StoppingCriterion
...@@ -790,18 +808,18 @@ classdef FaustFactoryTest < matlab.unittest.TestCase ...@@ -790,18 +808,18 @@ classdef FaustFactoryTest < matlab.unittest.TestCase
M = rand(500,32); M = rand(500,32);
fact_projs = { splin([500,32], 5), sp([32,32], 96), sp([32, 32], 96)}; fact_projs = { splin([500,32], 5), sp([32,32], 96), sp([32, 32], 96)};
res_projs = { normcol([32,32], 1), sp([32,32], 666), sp([32, 32], 333)}; res_projs = { normcol([32,32], 1), sp([32,32], 666), sp([32, 32], 333)};
stop_crit1 = StoppingCriterion(200) stop_crit1 = StoppingCriterion(200);
stop_crit2 = StoppingCriterion(200) stop_crit2 = StoppingCriterion(200);
% 50 iterations of MHTP will run every 100 iterations of PALM4MSA (each time PALM4MSA is called by the hierarchical algorithm) % 50 iterations of MHTP will run every 100 iterations of PALM4MSA (each time PALM4MSA is called by the hierarchical algorithm)
mhtp_param = MHTPParams('num_its', 150, 'palm4msa_period', 100) mhtp_param = MHTPParams('num_its', 150, 'palm4msa_period', 100);
param = ParamsHierarchical(fact_projs, res_projs, stop_crit1, stop_crit2) param = ParamsHierarchical(fact_projs, res_projs, stop_crit1, stop_crit2);
F = hierarchical_mhtp(M, param, mhtp_param) F = hierarchical_mhtp(M, param, mhtp_param);
err = norm(full(F)-M)/norm(M) err = norm(full(F)-M)/norm(M)
this.verifyLessThanOrEqual(err, 0.20) this.verifyLessThanOrEqual(err, 0.20)
end end
function test_hierarchical_dft(this) function test_hierarchical_dft(this)
disp('Test hierarchical dft') disp('Test matfaust.fact.hierarchical')
import matfaust.fact.hierarchical import matfaust.fact.hierarchical
import matfaust.dft import matfaust.dft
DFT = full(dft(32)) DFT = full(dft(32))
...@@ -814,42 +832,44 @@ classdef FaustFactoryTest < matlab.unittest.TestCase ...@@ -814,42 +832,44 @@ classdef FaustFactoryTest < matlab.unittest.TestCase
this.verifyLessThanOrEqual(err, 1e-3) this.verifyLessThanOrEqual(err, 1e-3)
end end
function test_dct(this) function test_dct(this)
n = 128; disp('Test matfaust.dct')
% x = rand(n, 1); n = 128;
x = ones(n, 1) % x = rand(n, 1);
y_ref = zeros(n, 1); x = ones(n, 1);
for k=1:n y_ref = zeros(n, 1);
for i=1:n for k=1:n
y_ref(k) = y_ref(k) + 2 * x(i) * cos(pi * (k-1) * (2 * (i-1) + 1) / 2 / n); for i=1:n
end y_ref(k) = y_ref(k) + 2 * x(i) * cos(pi * (k-1) * (2 * (i-1) + 1) / 2 / n);
end end
DCT = matfaust.dct(n, 'normed', false); end
y_test = real(DCT*x); DCT = matfaust.dct(n, 'normed', false);
this.verifyEqual(y_ref, y_test, 'AbsTol', 1e-6); y_test = real(DCT*x);
DCT_normed = matfaust.dct(n) this.verifyEqual(y_ref, y_test, 'AbsTol', 1e-6);
DCT_normalized = normalize(DCT) DCT_normed = matfaust.dct(n);
this.verifyEqual(DCT_normed*x, DCT_normalized*x, 'AbsTol', 1e-6); DCT_normalized = normalize(DCT);
end this.verifyEqual(DCT_normed*x, DCT_normalized*x, 'AbsTol', 1e-6);
end
function test_dst(this)
n = 128; function test_dst(this)
% x = rand(n, 1); disp('Test matfaust.dst')
x = ones(n, 1); n = 128;
y_ref = zeros(n, 1); % x = rand(n, 1);
for k=1:n x = ones(n, 1);
for i=1:n y_ref = zeros(n, 1);
y_ref(k) = y_ref(k) + x(i) * sin(pi / n * ((i-1) + 1 / 2) * k); for k=1:n
end for i=1:n
end y_ref(k) = y_ref(k) + x(i) * sin(pi / n * ((i-1) + 1 / 2) * k);
y_ref = y_ref * 2; end
DST = matfaust.dst(n, 'normed', false); end
y_test = real(DST*x); y_ref = y_ref * 2;
this.verifyEqual(y_ref, y_test, 'AbsTol', 1e-6); DST = matfaust.dst(n, 'normed', false);
DST_normed = matfaust.dst(n) y_test = real(DST*x);
DST_normalized = normalize(DST) this.verifyEqual(y_ref, y_test, 'AbsTol', 1e-6);
this.verifyEqual(DST_normed*x, DST_normalized*x, 'AbsTol', 1e-6); DST_normed = matfaust.dst(n);
end DST_normalized = normalize(DST);
this.verifyEqual(DST_normed*x, DST_normalized*x, 'AbsTol', 1e-6);
end
end end
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment