在numba jitted nopython函数中,我需要用另一个数组中的值索引一个数组。两个数组都是numpy数组float。在
例如
@numba.jit("void(f8[:], f8[:], f8[:])", nopython=True)
def need_a_cast(sources, indices, destinations):
for i in range(indices.size):
destinations[i] = sources[indices[i]]
我的代码是不同的,但是让我们假设这个问题可以通过这个愚蠢的例子重现(即,我不能有int类型的索引)。另外,我不能在nopythonjit函数内部使用int(index[i])或index[i].astype(“int”)。在
我该怎么做?在
如果您真的不能使用}来解决它:
int(indices[i])
(它对JoshAdel和我都有效),那么您应该可以使用math.trunc
或{据我所知,
math.floor
只适用于Python3,因为它在Python2中返回一个float
。但是math.trunc
则取整为负值。在至少使用numba 0.24,你可以做一个简单的投射:
相关问题 更多 >
编程相关推荐