Skip to content

Mixing of dask.array and numpy.ndarray in Numba @guvectorize #6855

@ischoegl

Description

@ischoegl

It appears that dask.array and numpy.ndarray cannot be mixed when using Numba's @guvectorize decorator - see the minimal example below. It would be a nice feature if dask could resolve this (or at least raise a more helpful exception!). Regardless, this is a truly helpful package!

Minimal Example

import dask.array as da
import numpy as np
import numba as nb

# large array
x = np.random.random((300000, 100, 10))
y = da.from_array(x) # for the sake of the example

# small vector
v = np.ones(10)
w = da.from_array(v)

@nb.guvectorize([nb.void(nb.f8[:, :], nb.f8[:], nb.f8[:])],
                '(m, n), (n) -> (m)', target='parallel')
def test(arr, vec, out):
    # really just a test function
    out[:] = (arr + vec).sum(axis=1)

out1 = test(x, v) # works
out2 = test(y, w).compute() # works

out3 = test(y, v) # fails with ValueError

The following ValueError is raised ... (on dask version 2.30.0)

[...]
ValueError: `dtype` inference failed in `apply_gufunc`.

Please specify the dtype explicitly using the `output_dtypes` kwarg.

Original error is below:
------------------------
ValueError('test: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (m, n), (n) -> (m) (size 10 is different from 1)',)

Traceback:
---------
  File "<...>/miniconda3-latest/envs/<...>/lib/python3.6/site-packages/dask/array/core.py", line 377, in apply_infer_dtype
    o = func(*args, **kwargs)

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