Mentions légales du service

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

Impl. mul. of a real Faust by a complex scalar in pyfaust and complete mul. unit test.

It's a feature asked in issue #18.
parent bed5f630
No related branches found
No related tags found
No related merge requests found
......@@ -394,12 +394,13 @@ class TestFaustPy(unittest.TestCase):
def testMul(self):
print("testMul()")
print("test mul by a full real matrix")
rmat = np.random.rand(self.F.shape[1],
self.r.randint(1,TestFaustPy.MAX_DIM_SIZE))
prod = self.mulFactors().dot(rmat)
test_prod = self.F*rmat
self.assertProdEq(prod, test_prod)
# test mul by a complex matrix
print("test mul by a full complex matrix")
j = np.complex(0,1)
rand = np.random.rand
cmat = rand(rmat.shape[0], rmat.shape[1]) + j*rand(rmat.shape[0],
......@@ -407,7 +408,7 @@ class TestFaustPy(unittest.TestCase):
prod = self.mulFactors().dot(cmat)
test_prod = self.F*cmat
self.assertProdEq(prod, test_prod)
# test mul by a real scalar
print("test mul by a real scalar")
import random
r = random.random()*100
test_prod = self.F*r
......@@ -417,7 +418,13 @@ class TestFaustPy(unittest.TestCase):
self.assertLess(norm((self.F.T*r).toarray()-self.F.toarray().T*r)/norm(self.F.toarray().T*r),1**-5)
self.assertLess(norm((self.F.H*r).toarray()-self.F.toarray().T.conj()*r)/norm(self.F.toarray().T.conj()*r),1**-5)
#TODO: test mul by a complex scalar when impl.
print("test mul by a complex scalar")
c = np.complex(r, random.random()*100)
test_prod = self.F*c
ref_prod = self.mulFactors()*c
self.assertLess(norm(test_prod.toarray()-ref_prod)/norm(ref_prod),
1**-5)
def testConcatenate(self):
print("testConcatenate()")
......
......@@ -224,24 +224,32 @@ cdef class FaustCore:
def multiply_scal(self, scalar):
core = FaustCore(core=True)
core._isReal = self._isReal
if(isinstance(scalar, int)):
scalar = float(scalar)
scalar_type_err = TypeError("The mul. scalar must be a real or a"
" complex number")
if(self._isReal):
if(isinstance(scalar, float)):
core.core_faust_dbl = \
self.core_faust_dbl.mul_scal(scalar)
elif(isinstance(scalar, np.complex)):
cplx_facs = [self.get_fact_opt(i).astype(np.complex) for i in \
range(0,self.get_nb_factors())]
cplx_facs[0] *= scalar # instead of passing the scal to the
# construc. It avoids disp of
# deprecation warning
core = FaustCore(cplx_facs)#, alpha=scalar)
core._isReal = False
else:
raise ValueError("You cannot multiply a real Faust by a"
" complex scalar (not yet implemented).")
raise scalar_type_err
else:
if(isinstance(scalar, np.complex) or isinstance(scalar,
float)):
core.core_faust_cplx = \
self.core_faust_cplx.mul_scal(scalar)
else:
raise ValueError("The multiplicative scalar must be a real or "
"a complex number.")
core._isReal = self._isReal
raise scalar_type_err
return core
cdef _vertcat(self, F):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment