numba在使用@时会引发性能警告,即使数组是连续的

时间:2019-01-03 16:44:02

标签: python performance numpy pytest numba

我在Fortran数组的列与C数组的一行之间做一个简单的点积(因此两者在内存中是连续的)。

import numpy as np

from numba import njit


@njit
def do_dot():
    X = np.asfortranarray(np.ones((3, 4)))
    B = np.ones((4, 5))

    X[:, 0:1] @ B[0:1, :]


def test_warning():
    do_dot()

但是,我收到警告:

➜  tests/ ✗ pytest test_numba.py
============================================================= test session starts =============================================================
platform linux -- Python 3.6.6, pytest-4.0.2, py-1.5.3, pluggy-0.7.1
rootdir: /home, inifile:
plugins: cov-2.6.0
collected 1 item                                                                                                                              

test_numba.py .                                                                                                                         [100%]

============================================================== warnings summary ===============================================================
tests/test_numba.py::test_warning
  /home/test_numba.py:11: PerformanceWarning: '@' is faster on contiguous arrays, called on (array(float64, 2d, A), array(float64, 2d, A))
    X[:, 0:1] @ B[0:1, :]
  /home/me/anaconda3/lib/python3.6/site-packages/numba/typing/npydecl.py:965: PerformanceWarning: '@' is faster on contiguous arrays, called on (array(float64, 2d, A), array(float64, 2d, A))
    % (self.func_name, (a, b)), PerformanceWarning)

-- Docs: https://docs.pytest.org/en/latest/warnings.html
==================================================== 1 passed, 2 warnings in 0.69 seconds ==========================

此外,仅当测试通过pytest运行时,才会显示警告: 直接在python shell中运行do_dot()不会引发任何警告。

可能是什么原因?

修改:numba版本为0.41.0

0 个答案:

没有答案