# I don't understand this compilation error

**URL:** <https://numba.discourse.group/t/i-dont-understand-this-compilation-error/1758>\
**Category:** Support: What is this error message?\
**Created:** [January 30, 2023, 3:35am UTC](https://numba.discourse.group/t/i-dont-understand-this-compilation-error/1758 "2023-01-30T03:35:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pauljurczak](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/pauljurczak/32/479_2.png) [@pauljurczak](https://numba.discourse.group/u/pauljurczak)\
**Post date:** [January 30, 2023, 3:35am UTC](https://numba.discourse.group/t/i-dont-understand-this-compilation-error/1758/1 "2023-01-30T03:35:34Z")

</div>

This script:

```auto
import numpy as np
import numba as nb
from math import pi, atan2, sqrt

@nb.njit(fastmath=True, locals=dict(w=nb.uint32))
def test2(im, grads, w):
  for i in range(im.size-w-1):
    dx = im[i+w+1]-im[i]
    dy = im[i+w]-im[i+1]
    grads[i] = (sqrt(dx*dx+dy*dy), np.int8(np.int8((atan2(dy, dx)+1.125*pi)/(pi/4)+5)%8))

w, h = 640, 480
im = np.random.rand(w*h).astype('f4')
grads = np.empty_like(im, dtype=[('magn', 'f4'), ('dir', 'i1')])
test2(im, grads, w)
print(grads)

```

produces this error:

```auto
Traceback (most recent call last):
  File "/home/paul/vision/so-9.py", line 15, in <module>
    test2(im, grads, w)
  File "/home/paul/venv/vision/lib/python3.10/site-packages/numba/core/dispatcher.py", line 468, in _compile_for_args
    error_rewrite(e, 'typing')
  File "/home/paul/venv/vision/lib/python3.10/site-packages/numba/core/dispatcher.py", line 409, in error_rewrite
    raise e.with_traceback(None)
numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
No implementation of function Function(<built-in function setitem>) found for signature:
 
 >>> setitem(unaligned array(Record(magn[type=float32;offset=0],dir[type=int8;offset=4];5;False), 1d, C), int64, Tuple(float32, int8))
 
There are 16 candidate implementations:
  - Of which 16 did not match due to:
  Overload of function 'setitem': File: <numerous>: Line N/A.
    With argument(s): '(unaligned array(Record(magn[type=float32;offset=0],dir[type=int8;offset=4];5;False), 1d, C), int64, Tuple(float32, int8))':
   No match.

During: typing of setitem at /home/paul/vision/so-9.py (10)

File "so-9.py", line 10:
def test2(im, grads, w):
    <source elided>
    dy = im[i+w]-im[i+1]
    grads[i] = (sqrt(dx*dx+dy*dy), np.int8(np.int8((atan2(dy, dx)+1.125*pi)/(pi/4)+5)%8))
    ^

```

The script runs fine without Numba. I though that `Tuple(float32, int8)` is the proper type to set an element of `grads`. What is the problem here?

---

<div class="post-metadata">

**Author:** ![Rutger](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/rutger/32/446_2.png) [@Rutger](https://numba.discourse.group/u/Rutger)\
**Post date:** [January 30, 2023, 8:21am UTC](https://numba.discourse.group/t/i-dont-understand-this-compilation-error/1758/2 "2023-01-30T08:21:04Z")

</div>

I think you should be able to write it like:

```python
grads["magn"][i] = sqrt(dx*dx+dy*dy)
grads["dir"][i] = np.int8(np.int8((atan2(dy, dx)+1.125*pi)/(pi/4)+5)%8)

```

---

<div class="post-metadata">

**Author:** ![nelson2005](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/nelson2005/32/47_2.png) [@nelson2005](https://numba.discourse.group/u/nelson2005)\
**Post date:** [January 30, 2023, 2:56pm UTC](https://numba.discourse.group/t/i-dont-understand-this-compilation-error/1758/3 "2023-01-30T14:56:57Z")

</div>

> [@pauljurczak](#):
>
> The script runs fine without Numba. I though that `Tuple(float32, int8)` is the proper type to set an element of `grads`. What is the problem here?

[Related post](https://numba.discourse.group/t/assigning-to-numpy-structural-array-using-a-tuple-in-jitclass/549)

---

<div class="post-metadata">

**Author:** ![nelson2005](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/nelson2005/32/47_2.png) [@nelson2005](https://numba.discourse.group/u/nelson2005)\
**Post date:** [January 30, 2023, 3:14pm UTC](https://numba.discourse.group/t/i-dont-understand-this-compilation-error/1758/4 "2023-01-30T15:14:20Z")

</div>

In general, [fancy-dtype](https://github.com/numba/numba/issues/5329) stuff is a bit hit-and-miss with numba. It can usually be worked around one way or another.
