Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incrementing array location with rank 0 array #9573

Open
aseyboldt opened this issue May 13, 2024 · 6 comments
Open

Incrementing array location with rank 0 array #9573

aseyboldt opened this issue May 13, 2024 · 6 comments
Labels
bug - typing Bugs: occuring at typing time feature_request

Comments

@aseyboldt
Copy link
Contributor

On current main I can not increment a location of an array with a rank 0 value:

import numba

@numba.njit
def inc_array(x, val):
    x[0] += val

inc_array(np.zeros(5), np.array(2.))
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
No implementation of function Function(<built-in function iadd>) found for signature:
 
 >>> iadd(float64, array(float64, 0d, C))
 
There are 18 candidate implementations:
      - Of which 16 did not match due to:
      Overload of function 'iadd': File: <numerous>: Line N[/A.](http://localhost:7890/A.)
        With argument(s): '(float64, array(float64, 0d, C))':
       No match.
      - Of which 2 did not match due to:
      Operator Overload in function 'iadd': File: unknown: Line unknown.
        With argument(s): '(float64, array(float64, 0d, C))':
       No match for registered cases:
        * (int64, int64) -> int64
        * (int64, uint64) -> int64
        * (uint64, int64) -> int64
        * (uint64, uint64) -> uint64
        * (float32, float32) -> float32
        * (float64, float64) -> float64
        * (complex64, complex64) -> complex64
        * (complex128, complex128) -> complex128

During: typing of intrinsic-call at [/tmp/ipykernel_359313/84858975.py](http://localhost:7890/tmp/ipykernel_359313/84858975.py) (5)

File "../../../../tmp/ipykernel_359313/84858975.py", line 5:
<source missing, REPL[/exec](http://localhost:7890/exec) in use?>

If I call it with a scalar value instead, it work:

inc_array(np.zeros(5), 2.)
@guilhermeleobas
Copy link
Collaborator

Thanks for the report @aseyboldt, can confirm the bug.

@guilhermeleobas
Copy link
Collaborator

Fix should be similar to what was done in #4516

@guilhermeleobas guilhermeleobas added feature_request bug - typing Bugs: occuring at typing time labels May 14, 2024
@gmarkall
Copy link
Member

As a workaround I think you can write

@numba.njit
def inc_array(x, val):
    x[()] += val

@aseyboldt
Copy link
Contributor Author

Do you mean

@numba.njit
def inc_array(x, val):
    x[0] += val[()]

because otherwise this will increment all locations in x, not just the first.

@gmarkall
Copy link
Member

Sorry, I think I mean something like that, yes - I'd come across this issue before of having to use variable[()] for the value of a rank 0 array, but I never realised this wasn't the way it was supposed to be.

@ricardoV94
Copy link

ricardoV94 commented May 24, 2024

If it helps, this is only a problem when the lhs is a vector (and a number after indexing). It's fine when it's a matrix (and a vector after indexing)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug - typing Bugs: occuring at typing time feature_request
Projects
None yet
Development

No branches or pull requests

4 participants