4

I do a simple dot product between a column of a Fortran array, and a line of a C array (so both are contiguous in memory).

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()

However, I get a warning:

➜  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 ==========================

Additionally, the warnings appear only if the test is ran through pytest: running do_dot() directly in a python shell does not raise any warning.

What could be the cause ?

Edit: numba version is 0.41.0

P. Camilleri
  • 12,664
  • 7
  • 41
  • 76
  • What version of numba? Maybe pytest is pointing to a different version of python than you were running directly? – chrisb Jan 03 '19 at 21:32
  • I don't think it has something to do with `pytest` in particular. `pytest` only emits all warnings it encounters, which means that `numba` should spit it too. Did you try running the code with `NUMBA_WARNINGS=1`, is the warning printed on normal code execution? – hoefling Jan 03 '19 at 22:39
  • Answering my own question - the warning is printed when running `NUMBA_WARNINGS=1 python -c "from spam import do_dot; do_dot()`. The issue is with the function itself, not with the test - most probably `numba` realigns numpy arrays when converting to own arrays. – hoefling Jan 06 '19 at 16:31
  • @hoefling thank you, I wanted to test myself but couldn't set NUMBA_WARNINGS via .numba_config, I was waiting for an answer here: https://stackoverflow.com/questions/54035751/numba-environment-variable-not-set-through-numba-config-yaml?noredirect=1#comment94906941_54035751 – P. Camilleri Jan 07 '19 at 11:31
  • @hoefling So this answers half of my question, but why do I get such a warning eventhough the array is contiguous ? – P. Camilleri Jan 07 '19 at 11:32

0 Answers0