I'm seeking a way to modify a jitclass variable with its name as a string. I tried to write a setter and getter function (get_A and set_A), and I got the method outside the jitclass. I would like then to pass that method to a jitclass method to update the value of the variable. However I get and error saying:
numba.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
non-precise type pyobject
[1] During: typing of argument at <string> (3)
File "<string>", line 3:
<source missing, REPL/exec in use?>
This error may have been caused by the following argument(s):
- argument 1: cannot determine Numba type of <class 'tuple'>
Here the minimal example:
from numba import float64
from numba.experimental import jitclass
spec = [('A', float64), ('B', float64), ('C', float64)]
@jitclass(spec)
class maClass:
def __init__(self):
self.A = 0
def get_A(self):
return self.A
def set_A(self, x):
self.A = x
def update(self, func, val):
func(val)
C1 = maClass()
print('A', C1.A)
Names= ['A']
vals= [1.]
func = getattr(C1, 'set_' + Names[0])
print(func)
C1.update(func, vals[0])
print('A', C1.A)