내가 Numba를 시작하기 위해 노력하고있어, 그것이 나의 첫 경험은 다음과 같은 코드로했다 설치 입수 한 :AttributeError는 'STR'객체는 Numba에는 속성 '_PTR을'이없는 @autojit 기능
from numba import autojit
@autojit
def trial(a,b):
return a+b
trial(1,1)
다음 오류가 발생합니다. autojit이 변수 유형을 오해하고 있지만 더 이상 알려주지 않는다는 것을 알 수 있습니다. (예를 들어, @jit(...)
과 같은 다른 방법으로 함수를 래핑하는 경우에도 마찬가지입니다.) 문제는 this과 비슷하지만 조작에 구애되지 않습니다. 함수가 수행하는 작업이나 수행 방법에 관계없이 발생합니다 (예를 들어 보여줍니다). 문제가 무엇인지에 대한 제안? Ubuntu 12.04에서 실행되고 Github의 지침에 따라 설치됩니다.
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-1-653102b59b98> in <module>()
5 return a+b
6
----> 7 trial(1,1)
/usr/local/lib/python2.7/dist-packages/numba/numbawrapper.so in numba.numbawrapper._NumbaSpecializingWrapper.__call__ (numba/numbawrapper.c:3934)()
/usr/local/lib/python2.7/dist-packages/numba/wrapping/compiler.pyc in compile_from_args(self, args, kwargs)
67 def compile_from_args(self, args, kwargs):
68 signature = self.resolve_argtypes(args, kwargs)
---> 69 return self.compile(signature)
70
71 def compile(self, signature):
/usr/local/lib/python2.7/dist-packages/numba/wrapping/compiler.pyc in compile(self, signature)
86 env=self.env, func_ast=self.ast, **self.flags)
87
---> 88 compiled_function = dec(self.py_func)
89 return compiled_function
90
/usr/local/lib/python2.7/dist-packages/numba/decorators.pyc in _jit_decorator(func)
222 sig, lfunc, wrapper = compile_function(env, func, argtys,
223 restype=return_type,
--> 224 nopython=nopython, func_ast=func_ast, **kwargs)
225 return numbawrapper.create_numba_wrapper(func, wrapper, sig, lfunc)
226
/usr/local/lib/python2.7/dist-packages/numba/decorators.pyc in compile_function(env, func, argtypes, restype, func_ast, **kwds)
131 assert kwds.get('llvm_module') is None, kwds.get('llvm_module')
132
--> 133 func_env = pipeline.compile2(env, func, restype, argtypes, func_ast=func_ast, **kwds)
134
135 function_cache.register_specialization(func_env)
/usr/local/lib/python2.7/dist-packages/numba/pipeline.pyc in compile2(env, func, restype, argtypes, ctypes, compile_only, func_ast, **kwds)
142 pipeline = env.get_pipeline(kwds.get('pipeline_name', None))
143 func_ast.pipeline = pipeline
--> 144 post_ast = pipeline(func_ast, env)
145 func_signature = func_env.func_signature
146 symtab = func_env.symtab
/usr/local/lib/python2.7/dist-packages/numba/pipeline.pyc in __call__(self, ast, env)
189
190 if self.is_composed:
--> 191 ast = self.transform(ast, env)
192 else:
193 try:
/usr/local/lib/python2.7/dist-packages/numba/pipeline.pyc in transform(self, ast, env)
654 stage_tuple = (stage, utils.ast2tree(ast))
655 logger.debug(pprint.pformat(stage_tuple))
--> 656 ast = stage(ast, env)
657 return ast
658
/usr/local/lib/python2.7/dist-packages/numba/pipeline.pyc in _stage(ast, env)
639 def _stage(ast, env):
640 stage_obj = getattr(env.pipeline_stages, name)
--> 641 return _check_stage_object(stage_obj)(ast, env)
642 _stage.__name__ = name
643 stage = _stage
/usr/local/lib/python2.7/dist-packages/numba/pipeline.pyc in __call__(self, ast, env)
192 else:
193 try:
--> 194 ast = self.transform(ast, env)
195 except error.NumbaError as e:
196 func_env = env.translation.crnt
/usr/local/lib/python2.7/dist-packages/numba/pipeline.pyc in transform(self, ast, env)
551 **func_env.kwargs)
552
--> 553 func_env.translator.translate()
554 func_env.lfunc = func_env.translator.lfunc
555 return ast
/usr/local/lib/python2.7/dist-packages/numba/codegen/translate.pyc in translate(self)
327 self.lfunc = None
328 try:
--> 329 self.setup_func()
330 if isinstance(self.ast, ast.FunctionDef):
331 # Handle the doc string for the function
/usr/local/lib/python2.7/dist-packages/numba/codegen/translate.pyc in setup_func(self)
304
305 # TODO: Put current function into symbol table for recursive call
--> 306 self.setup_return()
307
308 if self.have_cfg:
/usr/local/lib/python2.7/dist-packages/numba/codegen/translate.pyc in setup_return(self)
471 llvm_ret_type = self.func_signature.return_type.to_llvm(self.context)
472 self.return_value = self.builder.alloca(llvm_ret_type,
--> 473 "return_value")
474
475 # All non-NULL object emporaries are DECREFed here
/usr/local/lib/python2.7/dist-packages/llvm/core.pyc in alloca(self, ty, size, name)
2303
2304 def alloca(self, ty, size=None, name=""):
-> 2305 sizeptr = size._ptr if size else None
2306 return _make_value(self._ptr.CreateAlloca(ty._ptr, sizeptr, name))
2307
AttributeError: 'str' object has no attribute '_ptr'
편집 : @JoshAdel에 대응하여, 내 LLVM_BUILD_DIR=/opt/
으로 Github에서 페이지의 "사용자 정의 파이썬 환경"에 대한 지침을 사용했다. repo의 CHANGE_LOG에서 설치 한 버전을 0.11로 가져옵니다. 난 당신이 제공하는 예제를 실행하면, 나는
from numba import autojit, typeof
@autojit
def trial(a,b):
print typeof(a), typeof(b)
return a+b
trial(1,1)
어떤
File "<unknown file>", line 2
print typeof(a), typeof(b)
^
SyntaxError: invalid syntax
나는 그것을 확인 작동 @autojit
제거 할 경우 얻을. 그것 @autojit
와 함께 호출 던졌습니다 확실히 단서이지만, 내가 충분히 말할 수 없었을 정도로이 새로운 ...
나는 또한 중요한, 나는 IPython 시동시 numpy, scipy 및 matplotlib가 자동으로로드되도록 노트북.
내가 잘못 생각하면 numba의 내부 문제 일 것입니다. – aIKid
그냥 제쳐두고, numpy, scipy 등은 IPython에서 자동으로로드됩니다. 권장하지 않는'--pylab' 플래그로 시작할 수 있습니다 : http://carreau.github.io/posts/10-No- PyLab-Thanks.ipynb.html – JoshAdel