-
Notifications
You must be signed in to change notification settings - Fork 5
/
externaldps.py
40 lines (31 loc) · 1.44 KB
/
externaldps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import numpy
import scipy
import dataprocessor
# Import a bunch of numpy functions directly.
external_funcs = {'Abs': ('numpy.abs', numpy.abs),
'Diff': ('numpy.diff', numpy.diff),
'Exp': ('numpy.exp', numpy.exp),
'Flatten': ("numpy's flatten", lambda x: x.flatten()),
'FFT': ('numpy.fft.fft', numpy.fft.fft),
'IFFT': ('numpy.fft.ifft', numpy.fft.ifft),
'RFFT': ('numpy.fft.rfft', numpy.fft.rfft),
'IRFFT': ('numpy.fft.irfft', numpy.fft.irfft),
'Real': ('numpy.real', numpy.real),
'Imag': ('numpy.imag', numpy.imag),
'Square': ('numpy.square', numpy.square),
'Sqrt': ('numpy.sqrt', numpy.sqrt),
}
__all__ = external_funcs.keys()
for local_name, tpl in external_funcs.iteritems():
name, func = tpl
class ExternalDP(dataprocessor.DataProcessor):
__doc__ = "DataProcessor wrapper around %s." % name
def __init__(self, *args, **kwargs):
self.args = args
self.kwargs = kwargs
def _call_external_func(self, frame, external_func=func):
return external_func(frame, *self.args, **self.kwargs)
def process_frame(self, frame):
return self._call_external_func(frame)
exec("ExternalDP.__name__ = '%s'" % local_name)
exec("%s = ExternalDP" % local_name)