Mentions légales du service

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

Implement multiplicative constant to apply to a Faust at initialization time.

The constant is named alpha, not lambda like in Matlab wrapper, because lambda is a keyword in Python (lambda functions).
parent 129688d4
No related branches found
No related tags found
No related merge requests found
......@@ -54,7 +54,7 @@ class Faust:
matrix.
"""
def __init__(F, list_factors=None, filepath=None, core_obj=None):
def __init__(F, list_factors=None, alpha=1.0, filepath=None, core_obj=None):
""" Creates a Faust from a list of factors or alternatively from a file.
Another easy way to create a Faust is to call the static method Faust.randFaust().
......@@ -62,6 +62,9 @@ class Faust:
Args:
list_factors: list/tuple of numpy matrices (either
scipy.sparse.csr.csr_matrix or numpy.ndarray).
alpha: multiplicative scalar applied to the factor product before
to set the Faust with. Note that the constant is ignored if
list_factors argument isn't used.
filepath: the file in Matlab format (.mat) from which a Faust will
be created (the file must have been saved before with
Faust.save()).
......@@ -81,7 +84,7 @@ class Faust:
contents = loadmat(filepath)
list_factors = contents['faust_factors'][0]
if(list_factors is not None):
F.m_faust = FaustCorePy.FaustCore(list_factors);
F.m_faust = FaustCorePy.FaustCore(list_factors, alpha);
#else:
#TODO: manage empty Faust
......
......@@ -50,6 +50,7 @@ from libcpp cimport bool
from libcpp cimport complex
from cpython.mem cimport PyMem_Malloc, PyMem_Realloc, PyMem_Free
from scipy import sparse
from re import match
cdef class FaustCore:
......@@ -60,7 +61,7 @@ cdef class FaustCore:
cdef bool _isReal
#### CONSTRUCTOR ####
#def __cinit__(self,np.ndarray[double, mode="fortran", ndim=2] mat):
def __cinit__(self,list_factors=None, core=False):
def __cinit__(self,list_factors=None, alpha=1.0, core=False):
cdef double [:,:] data
cdef double [:] data1d #only for csr mat factor
cdef int [:] indices # only for csr mat
......@@ -70,6 +71,9 @@ cdef class FaustCore:
cdef unsigned int nbrow
cdef unsigned int nbcol
if(list_factors is not None):
if(match('.*int', repr(list_factors[0].dtype))):
list_factors[0] = list_factors[0].astype(np.float)
list_factors[0] *= alpha
self._isReal = True
for i,factor in enumerate(list_factors):
# Faust uses row-major order for sparse matrices
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment