question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Array types incompatible error in convolve.

See original GitHub issue

I am trying to use the convolve function from the dask_image library. No matter what combination of inputs I try, I seem to keep running into the same error.

My inputs are dcube:

<xarray.DataArray 'A' (time: 2, y: 823, x: 1296)>
array([[[330., 226., 709., ..., 135.,  82.,  76.],
        [125., 615., 293., ..., 156., 207., 127.],
        [126., 506., 218., ..., 228., 240., 179.],
        ...,
        [ 73., 137., 145., ..., 375., 453., 542.],
        [ 86.,  78., 148., ..., 321., 227., 619.],
        [ 88., 155.,  42., ..., 262., 279., 518.]],

       [[330., 226., 709., ..., 135.,  82.,  76.],
        [125., 615., 293., ..., 156., 207., 127.],
        [126., 506., 218., ..., 228., 240., 179.],
        ...,
        [ 73., 137., 145., ..., 375., 453., 542.],
        [ 86.,  78., 148., ..., 321., 227., 619.],
        [ 88., 155.,  42., ..., 262., 279., 518.]]])
Coordinates:
    pol      <U2 'HH'
  * y        (y) float64 3.653e+06 3.653e+06 3.653e+06 ... 3.652e+06 3.652e+06
  * x        (x) float64 1.047e+06 1.047e+06 1.047e+06 ... 1.049e+06 1.049e+06
  * time     (time) datetime64[ns] 2020-11-24T22:24:50 2020-11-18T01:15:05
Attributes:
    orbit:       A
    transform:   (1.1987408006010196, 0.0, 1047472.9120438152, 0.0, -1.198740...
    crs:         {'proj': 'utm', 'zone': 10, 'datum': 'WGS84', 'units': 'm', ...

and a patch:

filter_wt =  (1 / (N * N)) * np.ones((N, N),dtype='float64')
>> array([[0.11111111, 0.11111111, 0.11111111],
       [0.11111111, 0.11111111, 0.11111111],
       [0.11111111, 0.11111111, 0.11111111]])

When I try to use the convolve function as follows:

from dask_image.ndfilters import convolve
convolve(dcube[0], xr.DataArray(filter_wt), mode='constant', cval=0.0).compute()

I end up with this error: *** ValueError: Array types must be compatible.

Even though, DaskArray with a numpy backend and a numpy array should be compatible. To get around this, I tried initializing both as dask arrays:

(Pdb) convolve(da.from_array(dcube[i]), da.from_array(filter_wt), mode='constant', cval=0.0).compute()
*** ValueError: Array types must be compatible.
(Pdb) type(da.from_array(dcube[0]))
<class 'dask.array.core.Array'>
(Pdb) type(da.from_array(filter_wt))
<class 'dask.array.core.Array'>

Any instructions on why casting both to ask arrays didn’t work would be very helpful!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
GenevieveBuckleycommented, Feb 19, 2021

I’m going to close this issue now since it seems like the problem has been resolved.

For anyone reading, we’d be very happy to accept a pull request aimed at making the documentation clearer & more helpful for this particular problem. I think that’s a very good idea.

0reactions
GenevieveBuckleycommented, Feb 8, 2021

Thanks for responding to this. I tried setting them both to xarrays, but ran into an error that xarray doesn't have map_blocks. That’s why I assumed that the two must be dask arrays? One suggestion I have is to provide an override flag for this check.

The first argument must be a dask array, yes. Your other array inputs (in this case patch) must match the type of array stored in the dask array chunks of your first argument (dcube).

Examples of compatible arrays:

  • Two (or more) dask arrays with numpy chunks
  • A dask array with numpy chunks, and a numpy array

Examples of incompatible arrays:

  • A numpy array and a cupy array
  • A numpy array and an xarray.DataArray

The reason this is failing is probably that one is a ndarray and the other is a xarray.DataArray. As you mention that the check is discovering that one of the chunks is ndarray and the other is xarray.

Yes, this is a good summary.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Trying to pass an array to a method but throws incompatible ...
1 Answer 1 ... The program shows the message: Incompatible types: int[] cannot be converted to int . This is because the return...
Read more >
How to Think in JAX - JAX documentation - Read the Docs
jit does have limitations: in particular, it requires all arrays to have static shapes. That means that some JAX operations are incompatible with...
Read more >
Supported NumPy features - Numba
Numba excels at generating code that executes on top of NumPy arrays. ... using these attributes will result in a compile-time ( TypingError...
Read more >
convolve_fft — Astropy v5.2
Returns a convolved image with shape = array.shape . Assumes kernel is centered. convolve_fft is very similar to convolve in that it replaces ......
Read more >
astropy.convolution.convolve — Astropy v0.4.2
The data type depends on the input array type. If array is a floating point type, then the return array keeps the same...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found