Mentions légales du service

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

Handle mul. of Faust by a cplx matrix in pyfaust and add unit tests.

- Unit tests for this case added for pyfaust and matfaust but matfaust was already doing the mul. properly.
parent c70d2241
No related branches found
No related tags found
No related merge requests found
...@@ -260,6 +260,23 @@ classdef FaustTest < matlab.unittest.TestCase ...@@ -260,6 +260,23 @@ classdef FaustTest < matlab.unittest.TestCase
%TODO %TODO
end end
function testMul(this)
disp('Test Faust.mtimes()')
F = this.test_faust;
rmat = rand(size(F,2),size(F,2));
ref_full_faust = this.mulFactors();
ref_mat = ref_full_faust*rmat;
test_mat = F*rmat;
this.verifyEqual(test_mat,ref_mat, 'RelTol', 10^-3)
% do the same for a complex matrix
cmat = rand(size(F,2),size(F,2)) + i*rand(size(F,2),size(F,2));
ref_mat = ref_full_faust*cmat;
test_mat = F*cmat;
this.verifyEqual(test_mat,ref_mat, 'RelTol', 10^-3)
end
function testDelete(this) function testDelete(this)
disp('Test Faust.delete()') disp('Test Faust.delete()')
tFaust = transpose(this.test_faust); tFaust = transpose(this.test_faust);
......
...@@ -258,6 +258,14 @@ class TestFaustPy(unittest.TestCase): ...@@ -258,6 +258,14 @@ class TestFaustPy(unittest.TestCase):
prod = self.mulFactors().dot(rmat) prod = self.mulFactors().dot(rmat)
test_prod = self.F*rmat test_prod = self.F*rmat
self.assertProdEq(prod, test_prod) self.assertProdEq(prod, test_prod)
# test mul by a complex matrix
j = np.complex(0,1)
rand = np.random.rand
cmat = rand(rmat.shape[0], rmat.shape[1]) + j*rand(rmat.shape[0],
rmat.shape[1])
prod = self.mulFactors().dot(cmat)
test_prod = self.F*cmat
self.assertProdEq(prod, test_prod)
def testTranspose(self): def testTranspose(self):
......
...@@ -483,6 +483,9 @@ class Faust: ...@@ -483,6 +483,9 @@ class Faust:
return Faust(core_obj=F.m_faust.multiply(A.m_faust)) return Faust(core_obj=F.m_faust.multiply(A.m_faust))
elif(isinstance(A, float) or isinstance(A, int) or isinstance(A, np.complex)): elif(isinstance(A, float) or isinstance(A, int) or isinstance(A, np.complex)):
return Faust(core_obj=F.m_faust.multiply_scal(A)) return Faust(core_obj=F.m_faust.multiply_scal(A))
elif(isinstance(A, np.ndarray) and isinstance(A[0,0], np.complex)):
j = np.complex(0,1)
return F.m_faust.multiply(A.real).astype(np.complex) + j*F.m_faust.multiply(A.imag)
else: else:
return F.m_faust.multiply(A) return F.m_faust.multiply(A)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment