@@ -249,6 +249,37 @@ def __init__(self, bounds=(+inf, ), seq=(_zero, ), min=-inf, max=inf):
249249 self .stop = None
250250 self .sample_rate = None
251251
252+ def _head (self ):
253+ for i , s in enumerate (self .seq ):
254+ if s is not _zero :
255+ if i == 0 :
256+ return - inf
257+ return self .bounds [i - 1 ]
258+ return inf
259+
260+ def _tail (self ):
261+ N = len (self .bounds )
262+ for i , s in enumerate (self .seq [::- 1 ]):
263+ if s is not _zero :
264+ if i == 0 :
265+ return inf
266+ return self .bounds [N - i - 1 ]
267+ return - inf
268+
269+ @property
270+ def head (self ):
271+ if self .start is None :
272+ return self ._head ()
273+ else :
274+ return max (self .start , self ._head ())
275+
276+ @property
277+ def tail (self ):
278+ if self .stop is None :
279+ return self ._tail ()
280+ else :
281+ return min (self .stop , self ._tail ())
282+
252283 def sample (self , sample_rate = None , out = None ):
253284 if sample_rate is None :
254285 sample_rate = self .sample_rate
@@ -523,16 +554,18 @@ def __call__(self, x, frag=False, out=None):
523554 #ret = np.zeros_like(x)
524555 ret = []
525556 start , stop = 0 , 0
557+ dtype = float
526558 for i , stop in enumerate (range_list ):
527559 if start < stop and self .seq [i ] != _zero :
528- #ret[start:stop] = _calc(self.seq[i], x[start:stop])
529- ret .append ((start , stop ,
530- np .clip (_calc (self .seq [i ], x [start :stop ]),
531- self .min , self .max )))
560+ part = np .clip (_calc (self .seq [i ], x [start :stop ]), self .min ,
561+ self .max )
562+ if isinstance (part [0 ], complex ):
563+ dtype = complex
564+ ret .append ((start , stop , part ))
532565 start = stop
533566 if not frag :
534567 if out is None :
535- out = np .zeros_like (x )
568+ out = np .zeros_like (x , dtype = dtype )
536569 else :
537570 out *= 0
538571 for start , stop , part in ret :
@@ -791,7 +824,13 @@ def sin(w, phi=0):
791824
792825
793826def exp (alpha ):
794- return Waveform (seq = (_basic_wave (EXP , alpha ), ))
827+ if isinstance (alpha , complex ):
828+ if alpha .real == 0 :
829+ return cos (alpha .imag ) + 1j * sin (alpha .imag )
830+ else :
831+ return exp (alpha .real ) * (cos (alpha .imag ) + 1j * sin (alpha .imag ))
832+ else :
833+ return Waveform (seq = (_basic_wave (EXP , alpha ), ))
795834
796835
797836def sinc (bw ):
0 commit comments