overload of __call__ not supported in jitclass?

0 views
Skip to first unread message

Neal Becker

unread,
May 25, 2016, 8:33:59 AM5/25/16
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;



Siu Kwan Lam

unread,
May 25, 2016, 12:38:36 PM5/25/16
to numba...@continuum.io
Overriding __call__ does not work yet.  That is one of the feature I am working on.  

--
You received this message because you are subscribed to the Google Groups "Numba Public Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to numba-users...@continuum.io.
To post to this group, send email to numba...@continuum.io.
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/numba-users/ni4638%24irg%241%40ger.gmane.org.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.
--
Siu Kwan Lam
Software Engineer
Continuum Analytics
Reply all
Reply to author
Forward
0 new messages