How to efficiently create a tuple of length N with code that will compile with numba?
问题 I timed two ways to create a tuple of length N. This is very fast: def createTuple(): for _ in range(100000): tuplex = (0,) * 1000 CPU times: user 439 ms, sys: 1.01 ms, total: 440 ms Wall time: 442 ms This is very fast, but doesn't compile with Numba: Invalid use of Function(<built-in function mul>) with argument(s) of type(s): (UniTuple(Literal[int](0) x 1), int64) This is much slower: def createTuple(): for _ in range(100000): tuplex = tuple(0 for _ in range(1000)) %time createTuple() CPU