def fft(fx,gamma=0,delta=0,scale=1): from numpy import sqrt, roll, arange, exp, sign from numpy.fft import fft as ft from scipy import pi from spyctral.common.indexing import integer_range try: from pymbolic.algorithm import fft except: from numpy.fft import fft from connection import int_connection N = fx.size if fx.dtype==object: import pymbolic.algorithm as pyalg modes = pyalg.sym_fft(fx)*float(sqrt(2*pi)/N) else: modes = fft(fx)*sqrt(2*pi)/N ks = integer_range(N) modes = roll(modes,N/2) flags = ks!=0 flags2 = ((ks%2)==1) modes[flags] *= exp(-1j*ks[flags]*pi/N) modes[flags2] *= -1 return int_connection(modes,0,0,gamma,delta)
def ifft(f,gamma=0.,delta=0.,scale=1.): from numpy import sqrt, roll, arange, exp, sign from numpy.fft import ifft as ift from scipy import pi from spyctral.common.indexing import integer_range from connection import int_connection_backward try: from pymbolic.algorithm import ifft except: from numpy.fft import ifft N = f.size ks = integer_range(N) fx = int_connection_backward(f,0,0,gamma,delta) flags = ks!=0 flags2 = ((ks%2)==1) fx[flags2] *= -1 fx[flags] /= exp(-1j*ks[flags]*pi/N) fx = roll(fx,-(N-1)/2) if fx.dtype==object: import pymbolic.algorithm as pyalg return 1/sqrt(2*pi)*pyalg.sym_fft(fx,sign=-1) else: return N/float(sqrt(2*pi)*ift(fx))
def apply_stiff_entries_overhead(N,s=1.,t=0.,scale=1.): print """This function is not supported due to the efficiency of the CSR matvec routine in scipy. genwienerw_stiff() returns a CSR representation of the stiffness matrix""" from spyctral.common.indexing import integer_range ks = integer_range(N) # Generate the coefficients entries = weighted_wiener_stiff_entries(ks,s=s,t=t,scale=scale) # Generate necessary maps to appl if entries.size[0] != N: print """Error: inputs f and coefficients must have the same
def fft_overhead(N,gamma=0.,delta=0.,scale=1.): from numpy import sqrt, arange, exp, sign,ones,array from scipy import pi from spyctral.common.indexing import integer_range from connection import int_connection_overhead ks = integer_range(N) flags = ks!=0 flags2 = ((ks%2)==1) factors = exp(-1j*ks[flags]*pi/N) factors2 = -1 all_factors = ones(N,dtype=complex) all_factors[flags] *= factors all_factors[flags2] *= factors2 all_factors *= sqrt(2*pi)/N matrices = int_connection_overhead(N,0,0,gamma,delta) return [all_factors,matrices]