I have written this function to iterate over tuples of integers of constant sum, but it doesn’t work when I jit it.
I understand the problem is in the line where there’s a for
loop on the generator function itself.
from numba import njit
# @njit
def my_generator(N, k):
r"""Numba implementation of an iterator over tuples of N integers,
such that sum(tuple) == k.
Args:
N (int): number of elements in the tuple
k (int): sum of the elements
Returns:
tuple(int): a tuple of N integers
"""
if N == 1:
yield (k,)
else:
for i in range(k+1):
for j in my_generator(N-1, k-i):
yield (i,) + j
is there a simple fix?