Mentions légales du service

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

Add unit tests for pyfaust/matfaust sparse versions of GivensFGFT(Parallel).

parent 66f3bbb5
Branches
Tags
No related merge requests found
......@@ -178,8 +178,28 @@ classdef FaustFactoryTest < matlab.unittest.TestCase
this.verifyEqual(D,D2)
end
function test_fgft_givens_sparse(this)
disp('Test matfaust.fact.fgft_givens()')
import matfaust.*
load([this.faust_paths{1} '../../../misc/data/mat/test_GivensDiag_Lap_U_J.mat'])
% Lap and J available
[F,D] = matfaust.fact.fgft_givens(sparse(Lap), J);%, 0, 'verbosity', 1);
this.verifyEqual(size(F), size(Lap))
%disp('norm F: ')
%norm(F, 'fro')
E = F*full(D)*F'-Lap;
err = norm(E,'fro')/norm(Lap,'fro')
% the error reference is from the C++ test,
% misc/test/src/C++/GivensFGFT.cpp.in
this.verifyEqual(err, 0.0326529, 'AbsTol', 0.00001)
% verify it works the same using the eigtj() alias function
[F2,D2] = matfaust.fact.eigtj(Lap, J);%, 0, 'verbosity', 2);
this.verifyEqual(full(F2),full(F))
this.verifyEqual(D,D2)
end
function test_fgft_givens_parallel(this)
disp('Test matfaust.fact.fgft_givens() -- parallel')
disp('Test matfaust.fact.fgft_givens_sparse() -- parallel')
import matfaust.*
load([this.faust_paths{1} '../../../misc/data/mat/test_GivensDiag_Lap_U_J.mat'])
% Lap and J available
......@@ -199,6 +219,27 @@ classdef FaustFactoryTest < matlab.unittest.TestCase
this.verifyEqual(D,D2)
end
function test_fgft_givens_parallel_sparse(this)
disp('Test matfaust.fact.fgft_givens_sparse() -- parallel')
import matfaust.*
load([this.faust_paths{1} '../../../misc/data/mat/test_GivensDiag_Lap_U_J.mat'])
% Lap and J available
t = size(Lap,1)/2;
[F,D] = matfaust.fact.fgft_givens(sparse(Lap), J, t); %, 'verbosity', 2);
this.verifyEqual(size(F), size(Lap))
%disp('norm F: ')
%norm(F, 'fro')
E = F*full(D)*F'-Lap;
err = norm(E,'fro')/norm(Lap,'fro')
% the error reference is from the C++ test,
% misc/test/src/C++/GivensFGFTParallel.cpp.in
this.verifyEqual(err,0.0410448, 'AbsTol', 0.00001)
% verify it works the same using the eigtj() alias function
[F2,D2] = matfaust.fact.eigtj(Lap, J, t); %, 'verbosity', 2);
this.verifyEqual(full(F2),full(F))
this.verifyEqual(D,D2)
end
function test_fgft_palm(this)
disp('Test matfaust.fact.fgft_palm()')
import matfaust.*
......
......@@ -937,6 +937,48 @@ class TestFaustFactory(unittest.TestCase):
# misc/test/src/C++/GivensFGFTParallel.cpp.in
self.assertEqual(err, err2)
def testFGFTGivensSparse(self):
print("Test fact.fgft_givens_sparse()")
print(sys.path)
from scipy.sparse import csr_matrix
import pyfaust.fact
L = loadmat(sys.path[0]+"/../../../misc/data/mat/test_GivensDiag_Lap_U_J.mat")['Lap']
L = L.astype(np.float64)
J = \
int(loadmat(sys.path[0]+"/../../../misc/data/mat/test_GivensDiag_Lap_U_J.mat")['J'])
F, D = pyfaust.fact.fgft_givens(csr_matrix(L), J, 0, verbosity=0)
print("Lap norm:", norm(L, 'fro'))
err = norm((F*D.todense())*F.T.todense()-L,"fro")/norm(L,"fro")
print("err: ", err)
# the error reference is from the C++ test,
# misc/test/src/C++/GivensFGFT.cpp.in
self.assertAlmostEqual(err, 0.0326529, places=7)
def testFGFTGivensParallelSparse(self):
print("Test pyfaust.fact.fgft_givens() -- parallel")
from pyfaust.fact import eigtj, fgft_givens
from scipy.sparse import csr_matrix
L = loadmat(sys.path[0]+"/../../../misc/data/mat/test_GivensDiag_Lap_U_J.mat")['Lap']
L = L.astype(np.float64)
J = \
int(loadmat(sys.path[0]+"/../../../misc/data/mat/test_GivensDiag_Lap_U_J.mat")['J'])
t = int(L.shape[0]/2)
F, D = fgft_givens(csr_matrix(L), J, t, verbosity=0)
print("Lap norm:", norm(L, 'fro'))
err = norm((F*D.todense())*F.T.todense()-L,"fro")/norm(L,"fro")
print("err: ", err)
# the error reference is from the C++ test,
# misc/test/src/C++/GivensFGFTParallel.cpp.in
self.assertAlmostEqual(err, 0.0410448, places=7)
F2, D2 = eigtj(L, J, t, verbosity=0)
print("Lap norm:", norm(L, 'fro'))
err2 = norm((F2*D.todense())*F2.T.todense()-L,"fro")/norm(L,"fro")
print("err2: ", err2)
# the error reference is from the C++ test,
# misc/test/src/C++/GivensFGFTParallel.cpp.in
self.assertEqual(err, err2)
def testFactPalm4MSA_fgft(self):
print("Test pyfaust.fact._palm4msa_fgft()")
from pyfaust.factparams import ConstraintReal,\
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment