Hi, following Danny Weitekamp’s structref example (here), I was trying to create a numba StructRefProxy myself.
Basically, I am predefining the types like in the example above, e.g.:
@structref.register
class TestTypeTemplate(types.StructRef):
def preprocess_fields(self, fields):
return tuple((name, types.unliteral(type)) for name, type in fields)
kb_fields = [
("value", types.int64),
("array", types.UnionType(types=(types.float64[::1], types.int64[::1]))),
]
structref.define_boxing(TestTypeTemplate, Test)
The idea is that the array of values can either be an array of float64 or int64 types.
The example above can’t be used to initialize structref classes unfortunately. For example, when I pass an array of int64 integers to my Test class, I get:
numba.core.errors.NumbaNotImplementedError: Failed in nopython mode pipeline (step: native lowering)
Cannot cast array(int64, 1d, C) to Union[array(float64, 1d, C),array(int64, 1d, C)]: %"inserted.strides" = insertvalue {i8*, i8*, i64, i64, i64*, [1 x i64], [1 x i64]} %"inserted.shape", [1 x i64] %".13", 6
I was wondering if it is actually possible at all in this scenario, to allow users to either provide an array of int64 or float64 values. I have found a workaround, but I don’t like it. Simply put, I can check whether the input is an int64/float64 array and then initialize the class using 2 different constructors (1 for floats, 1 for integers), but that is not something I can use unfortunately.