Skip to content

Numba error with NumPy master when indexing #257

Closed

Description

@pentschev

I've come across a Numba error when trying to index a Sparse array. This only happens when NumPy master (eventually to be released as NumPy 1.17), everything works with NumPy 1.16.x.

Code to reproduce and traceback:

>>> import numpy as np
>>> import sparse
>>>
>>> x = np.random.random((2, 3))
>>> x[x < 0.9] = 0
>>>
>>> y = sparse.COO.from_numpy(x)
>>> y[0]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pentschev/miniconda3/envs/sparse-numba/lib/python3.7/site-packages/sparse/coo/indexing.py", line 68, in getitem
    mask, adv_idx = _mask(x.coords, index, x.shape)
  File "/home/pentschev/miniconda3/envs/sparse-numba/lib/python3.7/site-packages/sparse/coo/indexing.py", line 142, in _mask
    mask, is_slice = _compute_mask(coords, _ind_ar_from_indices(indices))
  File "/home/pentschev/miniconda3/envs/sparse-numba/lib/python3.7/site-packages/numba/dispatcher.py", line 350, in _compile_for_args
    error_rewrite(e, 'typing')
  File "/home/pentschev/miniconda3/envs/sparse-numba/lib/python3.7/site-packages/numba/dispatcher.py", line 317, in error_rewrite
    reraise(type(e), e, None)
  File "/home/pentschev/miniconda3/envs/sparse-numba/lib/python3.7/site-packages/numba/six.py", line 658, in reraise
    raise value.with_traceback(tb)
numba.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Failed in nopython mode pipeline (step: nopython frontend)
Invalid use of Function(<function searchsorted at 0x7f73c087b048>) with argument(s) of type(s): (array(int64, 1d, C), int64, side=Literal[str](left))
 * parameterized
In definition 0:
    TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Invalid use of Function(<function _searchsorted.<locals>.searchsorted_inner at 0x7f73db416f28>) with argument(s) of type(s): (array(int64, 1d, C), int64)
 * parameterized
In definition 0:
    TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Invalid use of Function(<ufunc 'isnan'>) with argument(s) of type(s): (int64)
 * parameterized
In definition 0:
    TypingError: ufunc 'isnan' using the loop 'l->?' not supported in this mode
    raised from /home/pentschev/miniconda3/envs/sparse-numba/lib/python3.7/site-packages/numba/typing/npydecl.py:114
In definition 1:
    TypingError: ufunc 'isnan' using the loop 'l->?' not supported in this mode
    raised from /home/pentschev/miniconda3/envs/sparse-numba/lib/python3.7/site-packages/numba/typing/npydecl.py:114
This error is usually caused by passing an argument of a type that is unsupported by the named function.
[1] During: resolving callee type: Function(<ufunc 'isnan'>)
[2] During: typing of call at /home/pentschev/miniconda3/envs/sparse-numba/lib/python3.7/site-packages/numba/targets/arraymath.py (2884)


File "../../../miniconda3/envs/sparse-numba/lib/python3.7/site-packages/numba/targets/arraymath.py", line 2884:
    def searchsorted_inner(a, v):
        <source elided>
        n = len(a)
        if np.isnan(v):
        ^

    raised from /home/pentschev/miniconda3/envs/sparse-numba/lib/python3.7/site-packages/numba/typeinfer.py:861
In definition 1:
    TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Invalid use of Function(<ufunc 'isnan'>) with argument(s) of type(s): (int64)
 * parameterized
In definition 0:
    TypingError: ufunc 'isnan' using the loop 'l->?' not supported in this mode
    raised from /home/pentschev/miniconda3/envs/sparse-numba/lib/python3.7/site-packages/numba/typing/npydecl.py:114
In definition 1:
    TypingError: ufunc 'isnan' using the loop 'l->?' not supported in this mode
    raised from /home/pentschev/miniconda3/envs/sparse-numba/lib/python3.7/site-packages/numba/typing/npydecl.py:114
This error is usually caused by passing an argument of a type that is unsupported by the named function.
[1] During: resolving callee type: Function(<ufunc 'isnan'>)
[2] During: typing of call at /home/pentschev/miniconda3/envs/sparse-numba/lib/python3.7/site-packages/numba/targets/arraymath.py (2884)


File "../../../miniconda3/envs/sparse-numba/lib/python3.7/site-packages/numba/targets/arraymath.py", line 2884:
    def searchsorted_inner(a, v):
        <source elided>
        n = len(a)
        if np.isnan(v):
        ^

    raised from /home/pentschev/miniconda3/envs/sparse-numba/lib/python3.7/site-packages/numba/typeinfer.py:861
This error is usually caused by passing an argument of a type that is unsupported by the named function.
[1] During: resolving callee type: Function(<function _searchsorted.<locals>.searchsorted_inner at 0x7f73db416f28>)
[2] During: typing of call at /home/pentschev/miniconda3/envs/sparse-numba/lib/python3.7/site-packages/numba/targets/arraymath.py (2939)


File "../../../miniconda3/envs/sparse-numba/lib/python3.7/site-packages/numba/targets/arraymath.py", line 2939:
        def searchsorted_impl(a, v, side='left'):
            return loop_impl(a, v)
            ^

    raised from /home/pentschev/miniconda3/envs/sparse-numba/lib/python3.7/site-packages/numba/typeinfer.py:861
In definition 1:
    ValueError: Invalid value given for 'side': unicode_type
    raised from /home/pentschev/miniconda3/envs/sparse-numba/lib/python3.7/site-packages/numba/targets/arraymath.py:2917
This error is usually caused by passing an argument of a type that is unsupported by the named function.
[1] During: resolving callee type: Function(<function searchsorted at 0x7f73c087b048>)
[2] During: typing of call at /home/pentschev/miniconda3/envs/sparse-numba/lib/python3.7/site-packages/sparse/coo/indexing.py (451)


File "../../../miniconda3/envs/sparse-numba/lib/python3.7/site-packages/sparse/coo/indexing.py", line 451:
def _get_mask_pairs(starts_old, stops_old, c, idx):  # pragma: no cover
    <source elided>
        for p_match in range(idx[0], idx[1], idx[2]):
            start = np.searchsorted(c[starts_old[j]:stops_old[j]], p_match, side='left') + starts_old[j]
            ^

[1] During: resolving callee type: type(CPUDispatcher(<function _get_mask_pairs at 0x7f73db9db620>))
[2] During: typing of call at /home/pentschev/miniconda3/envs/sparse-numba/lib/python3.7/site-packages/sparse/coo/indexing.py (387)


File "../../../miniconda3/envs/sparse-numba/lib/python3.7/site-packages/sparse/coo/indexing.py", line 387:
def _compute_mask(coords, indices):  # pragma: no cover
    <source elided>
        # Which would come out of indexing a single integer.
        starts, stops, n_matches = _get_mask_pairs(starts, stops, coords[i], indices[i])
        ^

This is not usually a problem with Numba itself but instead often caused by
the use of unsupported features or an issue in resolving types.

To see Python/NumPy features supported by the latest release of Numba visit:
http://numba.pydata.org/numba-doc/dev/reference/pysupported.html
and
http://numba.pydata.org/numba-doc/dev/reference/numpysupported.html

For more information about typing errors and how to debug them visit:
http://numba.pydata.org/numba-doc/latest/user/troubleshoot.html#my-code-doesn-t-compile

If you think your code should work with Numba, please report the error message
and traceback, along with a minimal reproducer at:
https://github.com/numba/numba/issues/new

List of packages in environment:

bzip2                     1.0.6             h14c3975_1002    conda-forge
ca-certificates           2019.3.9             hecc5488_0    conda-forge
certifi                   2019.3.9                 py37_0    conda-forge
libblas                   3.8.0               10_openblas    conda-forge
libcblas                  3.8.0               10_openblas    conda-forge
libffi                    3.2.1             he1b5a44_1006    conda-forge
libgcc-ng                 8.2.0                hdf63c60_1
libgfortran-ng            7.3.0                hdf63c60_0
liblapack                 3.8.0               10_openblas    conda-forge
libstdcxx-ng              8.2.0                hdf63c60_1
llvmlite                  0.28.0           py37hdbcaa40_0    conda-forge
ncurses                   6.1               hf484d3e_1002    conda-forge
numba                     0.43.1           py37hf2d7682_0    conda-forge
numpy                     1.17.0.dev0+4b6b29a          pypi_0    pypi
openblas                  0.3.6                h6e990d7_2    conda-forge
openssl                   1.1.1b               h14c3975_1    conda-forge
pip                       19.1                     py37_0    conda-forge
python                    3.7.3                h5b0a415_0    conda-forge
readline                  7.0               hf8c457e_1001    conda-forge
scipy                     1.3.0            py37h921218d_0    conda-forge
setuptools                41.0.1                   py37_0    conda-forge
sparse                    0.7.0                      py_0    conda-forge
sqlite                    3.28.0               h8b20d00_0    conda-forge
tk                        8.6.9             h84994c4_1001    conda-forge
wheel                     0.33.4                   py37_0    conda-forge
xz                        5.2.4             h14c3975_1001    conda-forge
zlib                      1.2.11            h14c3975_1004    conda-forge

The error persists with Sparse master. I don't know what's the current Sparse policy, regarding unreleased versions of dependencies or if this is a known issue, but thought it was worth reporting.

Activity

  1. hameerabbasi commented on May 29, 2019

    @hameerabbasi
    Collaborator

    I think it’s worth it to pin the package on conda-forge and pip, until this issue is fixed. Can this be reported upstream to Numba? I was never able to reproduce it, I think I was never using NumPy master, and I tested Numba at the time. Now I see it was a combination of the two that was an issue.

  2. pentschev commented on May 29, 2019

    @pentschev
    ContributorAuthor

    Which package do you mean should be pinned on conda-forge and pip?

    Sure, I'll report this to Numba, will try to come up with a sample that doesn't depend on packages other than Numpy and Numba itself.

  3. hameerabbasi commented on May 29, 2019

    @hameerabbasi
    Collaborator

    I’m unfortunately unavailable for the next few days otherwise I’d do this myself. I’ll still try to send a PR for the version pinning and make a release.

  4. pentschev commented on May 29, 2019

    @pentschev
    ContributorAuthor

    Don't worry about this, I'm just reporting to keep a record, but it's not urgent for me. And only to clarify, I'm intentionally working on upstream NumPy, if that's what you mean should have its version pinned.

  5. hameerabbasi commented on May 29, 2019

    @hameerabbasi
    Collaborator

    While I realise that, if the issue is present in the RC, we should pin it.

  6. pentschev commented on May 29, 2019

    @pentschev
    ContributorAuthor

    I see what you mean now. Yes, it's probably a good idea to do that until this issue is fixed.

  7. added a commit that references this issue on Jul 29, 2019
  8. added a commit that references this issue on Jul 29, 2019
  9. jcrist commented on Aug 5, 2019

    @jcrist
    Contributor

    We just ran into this in the dask test suite with numpy 1.17.0. Any insight into what is needed for a fix here (we're trying pinning for now)?

  10. hameerabbasi commented on Aug 6, 2019

    @hameerabbasi
    Collaborator

    Unfortunately this doesn’t look like something that can be fixed on our side, it’s been reported upstream to Numba.

    I can release a new version with a pinned NumPy if it helps.

  11. jakirkham commented on Aug 6, 2019

    @jakirkham

    Do you have an xref to the issue?

  12. hameerabbasi commented on Aug 12, 2019

    @hameerabbasi
    Collaborator

    Looks like this is resolved: numba/numba#3953

  13. added a commit that references this issue on Aug 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions