2017-11-05 15 views
0

numba.cuda.jit, numba.jit 및 none (순수한 python) 중에서 선택하는 데있어 가장 좋은 방법은 무엇입니까? [프로젝트에는 10 또는 100 개의 기능이 있으므로 모든 기능에 적용하기 쉽습니다.] 여기은 numba 웹 사이트의 예제입니다.순수 파이썬 numba.jit 및 numba.cuda.jit에서 동적으로/조건 적으로 선택

import numba as nb 
import numpy as np 

# global control of this --> @nb.jit or @nb.cuda.jit or none 
# some functions with @nb.jit or cuda.jit with kwargs like (nopython=True, **other_kwargs) 
def sum2d(arr): 
    M, N = arr.shape 
    result = 0.0 
    for i in range(M): 
     for j in range(N): 
      result += arr[i,j] 
    return result 


a = np.arange(81).reshape(9,9) 

sum2d(a) 

답변

1

당신은 뭔가 더 정교한 할 수 있지만, 상대적으로 간단한 해결책은 설정에 따라 jit을 재정의합니다. 예 :

def _noop_jit(f=None, *args, **kwargs): 
    """ returns function unmodified, discarding decorator args""" 
    if f is None: 
     return lambda x: x 
    return f 

# some config flag 
if settings.PURE_PYTHON_MODE: 
    jit = _noop_jit 
else: # etc 
    from numba import jit 

@jit(nopython=True) 
def f(a): 
    return a + 1