in the online docs there’s an example of modifying the structref from jitted code like
@njit
def make_bob():
bob = MyStruct("unnamed", vector=np.zeros(3))
# Mutate the attributes
bob.name = "Bob"
bob.vector = np.random.random(3)
return bob
This works fine. It doesn’t work in plain-python- if I remove the ‘@njit’, I get
AttributeError: can’t set attribute
I can make a separate setter function, like
def set_name(self, name):
MyStruct_set_name(self, name)
and
@njit
def MyStruct_set_name(self, name):
self.name = name
return self.name
This works fine in plain python but fails when jitted
@njit
def make_bob() -> MyStruct:
bob = MyStruct("unnamed", vector=np.zeros(3))
# Mutate the attributes
bob.name = "Bob"
bob.set_name('Ted') # fails here, Unknown attribute 'set_name' of type numba.MyStructType...
bob.vector = np.random.random(3)
return bob
So I have one way to modify the struct in jit mode and a different way to do it with plain python. Is there any way that works for both modes?