猿问

unicode_type/string 类型是否适用于 Numba 的 cfunc?

我在 Numba 的文档中看到支持某些 str 类型的操作。我用@jit 装饰器对其进行了测试,它确实有效:


In [14]: @numba.jit("boolean(unicode_type, unicode_type)")

...: def compare_str(a, b):

...:     return a == b

...:                  

In [15]: compare_str("a","a")                                                                                                                                                                                    

Out[15]: True

我想知道这种类型是否也可用于 cfuncs,因为我想要一个 C++ 回调来对字符串进行一些操作,但是我无法在 Python 中成功测试它,尽管它实际上可以编译:


In [13]: @numba.cfunc("boolean(unicode_type, unicode_type)")

    ...: def compare_str(a, b):

    ...:     return a == b

    ...:    

In [12]: compare_str.ctypes("a","a")  

TypeError                                 Traceback (most recent call last)

<ipython-input-17-63a3266c663d> in <module>

----> 1 compare_str.ctypes("a", "a")


~/.virtualenvs/py3cpp/lib/python3.6/site-packages/numba/utils.py in __get__(self, instance, type)

    351         if instance is None:

    352             return self

--> 353         res = instance.__dict__[self.name] = self.func(instance)

    354         return res

    355


~/.virtualenvs/py3cpp/lib/python3.6/site-packages/numba/ccallback.py in ctypes(self)

    159         A ctypes function object representing the C callback.

    160         """

--> 161         ctypes_args = [to_ctypes(ty) for ty in self._sig.args]

    162         ctypes_restype = to_ctypes(self._sig.return_type)

    163         functype = ctypes.CFUNCTYPE(ctypes_restype, *ctypes_args)


~/.virtualenvs/py3cpp/lib/python3.6/site-packages/numba/ccallback.py in <listcomp>(.0)

    159         A ctypes function object representing the C callback.

    160         """

--> 161         ctypes_args = [to_ctypes(ty) for ty in self._sig.args]

    162         ctypes_restype = to_ctypes(self._sig.return_type)

    163         functype = ctypes.CFUNCTYPE(ctypes_restype, *ctypes_args)



我正在使用 numba 0.42.0 和 Python 3.6.7。任何提示将不胜感激。


ABOUTYOU
浏览 277回答 1
1回答

陪伴而非守候

尚不支持。在Numba 的公开讨论谷歌组中得到了回答
随时随地看视频慕课网APP

相关分类

Python
我要回答