Mentions légales du service

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

Enable butterfly and permutation optimizations of the dft in pyfaust.circ (diag_opt arg.).

Issue #287.
parent 91ca514a
No related branches found
No related tags found
No related merge requests found
...@@ -3628,13 +3628,15 @@ def dst(n, normed=True, dev='cpu', dtype='float64'): ...@@ -3628,13 +3628,15 @@ def dst(n, normed=True, dev='cpu', dtype='float64'):
F = F.astype(dtype) F = F.astype(dtype)
return F return F
def circ(c, dev='cpu'): def circ(c, dev='cpu', diag_opt=False):
"""Returns a circulant Faust C defined by the vector c (which is the first """Returns a circulant Faust C defined by the vector c (which is the first
column of C.toarray()). column of C.toarray()).
Args: Args:
c: the vector to define the circulant Faust. c: the vector to define the circulant Faust.
dev: the device on which the Faust is created, 'cpu' (default) or 'gpu'. dev: the device on which the Faust is created, 'cpu' (default) or 'gpu'.
diag_opt: if True then the returned Faust is optimized using
pyfaust.opt_butterfly_faust (because the DFT is used to implement circ).
Example: Example:
>>> from pyfaust import circ >>> from pyfaust import circ
...@@ -3685,11 +3687,11 @@ def circ(c, dev='cpu'): ...@@ -3685,11 +3687,11 @@ def circ(c, dev='cpu'):
C = toeplitz(c, np.hstack((c[0:1], c[-1:0:-1])), dev=dev) C = toeplitz(c, np.hstack((c[0:1], c[-1:0:-1])), dev=dev)
return C return C
n = len(c) n = len(c)
F = dft(n, normed=False) F = dft(n, normed=False, diag_opt=diag_opt)
FH = F.H FH = F.H
S = csr_matrix(diags(FH@(c/n))) S = csr_matrix(diags(FH@(c/n)))
# S = csr_matrix(diags(np.sqrt(n)*FH@c)) # if it was normed==True # S = csr_matrix(diags(np.sqrt(n)*FH@c)) # if it was normed==True
if diag_factor == 'csr': if diag_factor == 'csr' or diag_opt:
C = F @ Faust(S) @ FH C = F @ Faust(S) @ FH
elif diag_factor == 'multiplied': elif diag_factor == 'multiplied':
nf = F.numfactors() nf = F.numfactors()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment