This probably does what you want, but note it’s using “unsafe” Numba-internal things:
from numba import njit
import numpy as np
from numba.cpython.unsafe.tuple import tuple_setitem
@njit
def drop_elements(tup: tuple):
for x in range(len(tup)):
empty = tup[:-1] # it's not empty, but its the right size and will be mutated
idx = 0
for i in range(len(tup)):
if i != x:
empty = tuple_setitem(empty, idx, tup[i])
idx += 1
yield tup[x], empty
z = [x for x in drop_elements((1,2,3))]
print(z)
the reason the expression yield element, tup[:i] + tup[i+1:]
won’t compile is that i
isn’t constant and so Numba can’t work out what size the tuple resulting from tup[:i]
should be, essentially, dynamic slicing of tuples isn’t supported.