Neal Becker
unread,May 25, 2016, 8:33:59 AM5/25/16Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to numba...@continuum.io
I created an instance of jitclass lms_2nd, but overloading __call__ didn't
seem to work:
python3 test7_multi.py --c1=1 --plot --omega=1e-5 --size=1000000
Traceback (most recent call last):
File "test7_multi.py", line 228, in <module>
run_line (sys.argv)
File "test7_multi.py", line 153, in run_line
return runit (opt)
File "test7_multi.py", line 86, in runit
zout = run()
File "test7_multi.py", line 83, in run
zout = the_lms (A, y1_normed, y2_normed, y2_normed, omegas,
np.array([]))
TypeError: 'lms_2nd' object is not callable
Here is my class:
import numpy as np
from numba import jitclass # import the decorator
from numba import float64, complex128, intc # import the types
spec = [
('M', intc), # a simple scalar field
('zeta', float64),
('omega_n', float64),
('sum1s', complex128[:]),
('sum2s', complex128[:]),
('k', float64),
('aT', float64),
]
@jitclass(spec)
class lms_2nd (object):
def __init__ (self, M, omega_n, zeta):
self.M = M
self.zeta = zeta
self.omega_n = omega_n
self.sum1s = np.zeros (M, dtype=complex128)
self.sum2s = np.zeros (M, dtype=complex128)
self.k = 2 * zeta * omega_n
self.aT = omega_n / (2 * zeta)
def __call__ (self, A, y1, y2, y3, omegas, zetas):
L = A.shape[0]
M = self.M
sum2s = self.sum2s
sum1s = self.sum1s
zout = np.empty (L-M)
for i in range (M//2, L-M//2-1+1):
z = zout[i-M//2] = y1[i] - np.dot (sum2s,
y2[i-(M//2):i+(M//2)+1])
if zetas.shape[0] != 0 or omegas.shape[0] != 0:
new_zeta = zetas[i-M//2] if zetas.shape[0] != 0 else
self.zeta
new_omega = omegas[i-M//2] if omegas.shape[0] != 0 else
omega_n
if new_omega != omega_n or new_zeta != zeta:
reset (new_omega, new_zeta);
for j in range (M):
err = z * np.conj (y3[i-M/2+j])
filter1_out = self.k * err + sum1s[j];
sum1s[j] += err * self.k * self.aT;
sum2s[j] += filter1_out;
return zout;
def reset (self, _omega_n, _zeta):
newk = 2 * _zeta * _omega_n;
newaT = _omega_n / (2 * _zeta);
self.sum1s *= (newk * newaT) / (self.k * self.aT);
self.omega_n = _omega_n;
self.zeta = _zeta;
self.k = newk;
self.aT = newaT;