~ubuntu-branches/ubuntu/lucid/python-scipy/lucid

« back to all changes in this revision

Viewing changes to Lib/fftpack/pseudo_diffs.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-01-07 14:12:12 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070107141212-mm0ebkh5b37hcpzn
* Remove build dependency on python-numpy-dev.
* python-scipy: Depend on python-numpy instead of python-numpy-dev.
* Package builds on other archs than i386. Closes: #402783.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
           'cs_diff','cc_diff','sc_diff','ss_diff',
9
9
           'shift']
10
10
 
11
 
from scipy_base import pi, asarray, sin, cos, sinh, cosh, tanh
 
11
from numpy import pi, asarray, sin, cos, sinh, cosh, tanh, iscomplexobj
12
12
import convolve
13
13
 
14
14
import atexit
38
38
        The assumed period of the sequence. Default is 2*pi.
39
39
 
40
40
    Notes:
41
 
      If sum(x)=0 then
 
41
      If sum(x,axis=0)=0 then
42
42
          diff(diff(x,k),-k)==x (within numerical accuracy)
43
43
      For odd order and even len(x), the Nyquist mode is taken zero.
44
44
    """
45
45
    tmp = asarray(x)
46
46
    if order==0:
47
47
        return tmp
48
 
    if tmp.typecode() in ['F','D']:
 
48
    if iscomplexobj(tmp):
49
49
        return diff(tmp.real,order,period)+1j*diff(tmp.imag,order,period)
50
50
    if period is not None:
51
51
        c = 2*pi/period
79
79
    If x_j and y_j are Fourier coefficients of periodic functions x
80
80
    and y, respectively, then
81
81
 
82
 
      y_j = -sqrt(-1)*coth(j*h*2*pi/period) * x_j
 
82
      y_j = sqrt(-1)*coth(j*h*2*pi/period) * x_j
83
83
      y_0 = 0
84
84
 
85
85
    Input:
89
89
        The assumed period of the sequence. Default period is 2*pi.
90
90
 
91
91
    Notes:
92
 
      If sum(x)==0 and n=len(x) is odd then
 
92
      If sum(x,axis=0)==0 and n=len(x) is odd then
93
93
        tilbert(itilbert(x)) == x
94
94
      If 2*pi*h/period is approximately 10 or larger then numerically
95
95
        tilbert == hilbert
97
97
      For even len(x), the Nyquist mode of x is taken zero.
98
98
    """
99
99
    tmp = asarray(x)
100
 
    if tmp.typecode() in ['F','D']:
 
100
    if iscomplexobj(tmp):
101
101
        return tilbert(tmp.real,h,period)+\
102
102
               1j*tilbert(tmp.imag,h,period)
103
103
    if period is not None:
108
108
        if len(_cache)>20:
109
109
            while _cache: _cache.popitem()
110
110
        def kernel(k,h=h):
111
 
            if k: return -1/tanh(h*k)
 
111
            if k: return 1.0/tanh(h*k)
112
112
            return 0
113
113
        omega = convolve.init_convolution_kernel(n,kernel,d=1)
114
114
        _cache[(n,h)] = omega
127
127
    If x_j and y_j are Fourier coefficients of periodic functions x
128
128
    and y, respectively, then
129
129
 
130
 
      y_j = sqrt(-1)*tanh(j*h*2*pi/period) * x_j
 
130
      y_j = -sqrt(-1)*tanh(j*h*2*pi/period) * x_j
131
131
      y_0 = 0
132
132
 
133
133
    Optional input: see tilbert.__doc__
134
134
    """
135
135
    tmp = asarray(x)
136
 
    if tmp.typecode() in ['F','D']:
 
136
    if iscomplexobj(tmp):
137
137
        return itilbert(tmp.real,h,period)+\
138
138
               1j*itilbert(tmp.imag,h,period)
139
139
    if period is not None:
144
144
        if len(_cache)>20:
145
145
            while _cache: _cache.popitem()
146
146
        def kernel(k,h=h):
147
 
            if k: return tanh(h*k)
 
147
            if k: return -tanh(h*k)
148
148
            return 0
149
149
        omega = convolve.init_convolution_kernel(n,kernel,d=1)
150
150
        _cache[(n,h)] = omega
163
163
    If x_j and y_j are Fourier coefficients of periodic functions x
164
164
    and y, respectively, then
165
165
 
166
 
      y_j = -sqrt(-1)*sign(j) * x_j
 
166
      y_j = sqrt(-1)*sign(j) * x_j
167
167
      y_0 = 0
168
168
 
169
169
    Notes:
170
 
      If sum(x)==0 then
 
170
      If sum(x,axis=0)==0 then
171
171
        hilbert(ihilbert(x)) == x
172
172
      For even len(x), the Nyquist mode of x is taken zero.
173
173
    """
174
174
    tmp = asarray(x)
175
 
    if tmp.typecode() in ['F','D']:
176
 
        return hilbert(tmp.real,tol)+1j*hilbert(tmp.imag)
 
175
    if iscomplexobj(tmp):
 
176
        return hilbert(tmp.real)+1j*hilbert(tmp.imag)
177
177
    n = len(x)
178
178
    omega = _cache.get(n)
179
179
    if omega is None:
180
180
        if len(_cache)>20:
181
181
            while _cache: _cache.popitem()
182
182
        def kernel(k):
183
 
            if k>0: return -1
184
 
            elif k<0: return 1
185
 
            return 0
 
183
            if k>0: return 1.0
 
184
            elif k<0: return -1.0
 
185
            return 0.0
186
186
        omega = convolve.init_convolution_kernel(n,kernel,d=1)
187
187
        _cache[n] = omega
188
 
    overwrite_x = tmp is not x and not hasattr(x,'__array__')        
 
188
    overwrite_x = tmp is not x and not hasattr(x,'__array__')
189
189
    return convolve.convolve(tmp,omega,swap_real_imag=1,overwrite_x=overwrite_x)
190
190
del _cache
191
191
 
198
198
    If x_j and y_j are Fourier coefficients of periodic functions x
199
199
    and y, respectively, then
200
200
 
201
 
      y_j = sqrt(-1)*sign(j) * x_j
 
201
      y_j = -sqrt(-1)*sign(j) * x_j
202
202
      y_0 = 0
203
203
    """
204
204
    return -hilbert(x)
228
228
      For even len(x), the Nyquist mode of x is taken zero.
229
229
    """
230
230
    tmp = asarray(x)
231
 
    if tmp.typecode() in ['F','D']:
 
231
    if iscomplexobj(tmp):
232
232
        return cs_diff(tmp.real,a,b,period)+\
233
233
               1j*cs_diff(tmp.imag,a,b,period)
234
234
    if period is not None:
274
274
      For even len(x), the Nyquist mode of x is taken zero.
275
275
    """
276
276
    tmp = asarray(x)
277
 
    if tmp.typecode() in ['F','D']:
 
277
    if iscomplexobj(tmp):
278
278
        return sc_diff(tmp.real,a,b,period)+\
279
279
               1j*sc_diff(tmp.imag,a,b,period)
280
280
    if period is not None:
319
319
      ss_diff(ss_diff(x,a,b),b,a) == x
320
320
    """
321
321
    tmp = asarray(x)
322
 
    if tmp.typecode() in ['F','D']:
 
322
    if iscomplexobj(tmp):
323
323
        return ss_diff(tmp.real,a,b,period)+\
324
324
               1j*ss_diff(tmp.imag,a,b,period)
325
325
    if period is not None:
365
365
      cc_diff(cc_diff(x,a,b),b,a) == x
366
366
    """
367
367
    tmp = asarray(x)
368
 
    if tmp.typecode() in ['F','D']:
 
368
    if iscomplexobj(tmp):
369
369
        return cc_diff(tmp.real,a,b,period)+\
370
370
               1j*cc_diff(tmp.imag,a,b,period)
371
371
    if period is not None:
401
401
        The period of the sequences x and y. Default period is 2*pi.
402
402
    """
403
403
    tmp = asarray(x)
404
 
    if tmp.typecode() in ['F','D']:
 
404
    if iscomplexobj(tmp):
405
405
        return shift(tmp.real,a,period)+1j*shift(tmp.imag,a,period)
406
406
    if period is not None:
407
407
        a = a*2*pi/period
424
424
                               overwrite_x=overwrite_x)
425
425
 
426
426
del _cache
427