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
Use of lists for shape args in empty(), zero(), Ones() #3993
Comments
Thanks for the report. The issue here is that Numba has to determine the types of everything to be able to compile the code. Numba "knows" that a type is a list, but has no idea how many entries are in the list at compile time, and, as a result, if used in an array constructor, it has no idea what shape the array should be. I'd recommend reading the discussion here: #2771 which discusses implementing the |
As to:
I get this:
do you have any suggestions for improvements please? Feedback is much appreciated. I've been on-and-off working on #3942 to help here, at present it shows this for the above:
again, feedback is welcomed. |
For me, the most common error is using |
@Juanlu001 thanks for the feedback, I think what you are after is something that especially checks the dtype and if the type is identified as a |
One of the problem I have with enviroment vars is that I haven't figured out when they get invoked in conda envs and jupyter notebooks. Is there some stateful way to make it switchable with numba itself?
Also I 'm still puzling over Juan's exampe as I don't yet know what's wrong with what he wrote :-)
… On Apr 19, 2019, at 5:04 AM, stuartarchibald ***@***.***> wrote:
@Juanlu001 <https://github.com/Juanlu001> thanks for the feedback, I think what you are after is something that especially checks the dtype and if the type is identified as a Function class type it hints that you probably meant an equivalent concrete NumPy type? If my assumption is correct, please could you open a ticket to specifically request that, it's not quite the same sort of code path as #3942 <#3942>? Thanks.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub <#3993 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/ACRAR7QTIDU2XLICACLUCU3PRGRMDANCNFSM4HG7K7FQ>.
|
Some feed back: here's what the hint says
HINT: Given argument type(s) were (list(int64)) and the NumPy function 'numpy.empty' is supported for the following argument type(s):
* numpy.empty(any, any)
* numpy.empty(any)
I can't figure out what it's saying. It seems like it is saying the empty takes "any" argument and then above that it says it doesn't take a list or perhaps a list(int64).
THe good thing about this hint is the the first sentence nails the error correctly so that's good. It's the second part that obfuscates that with "any".
My sense is that just as it takes a while to learn to read the tea leaves of a numba Error traceback, that there will be a learning curve for deciphering hints. So It's probably just fine to have this seemingly contradictory hint in this format. When you have a hard to spot bug what you really want is some set of scooby clues follow. So offering more info is better even if some clues are red herrings.
The first line's clue might possibly have been even more informative. FOr example, the fact that it's a list is the actual problem. Not that it's a list of int64. thus omitting the int64 part would have give a better pointer. To see why consider if the error had been because I had used a tuple of floats or strings as the shape parameter. THen the error would not be the tuple itself but the dtype fof the contents. So sometimes the error will be the outer part (list) and sometimes the inner part (not int64).
Anyhow that might beyond the hinting capacity to post mortem. And as I said, any hint, even a partly bad hint, is better than no hint.
…----
regarding my last comment about Environment variables. Since I develop inside jupyter notebooks environment variables are a nuiscance as they don't seem to always stick. And exiting the notebook to set them and relaunch means you lost the state that was causeing an error (perhaps the error is caused by some hard to reproduce condition that is producing a Nan). This means you can't keep a hold on the error and also switch on the enviroment varialbles until you can write code to reproduce the error every time-- which is half the battle of debugging anyhow. If there were a way to switch numba's state directly then one could switch this on and off while interactively debugging. this applies to things like cuda emulators too.
On Apr 19, 2019, at 8:38 AM, Charlie Strauss ***@***.***> wrote:
One of the problem I have with enviroment vars is that I haven't figured out when they get invoked in conda envs and jupyter notebooks. Is there some stateful way to make it switchable with numba itself?
Also I 'm still puzling over Juan's exampe as I don't yet know what's wrong with what he wrote :-)
> On Apr 19, 2019, at 5:04 AM, stuartarchibald ***@***.*** ***@***.***>> wrote:
>
> @Juanlu001 <https://github.com/Juanlu001> thanks for the feedback, I think what you are after is something that especially checks the dtype and if the type is identified as a Function class type it hints that you probably meant an equivalent concrete NumPy type? If my assumption is correct, please could you open a ticket to specifically request that, it's not quite the same sort of code path as #3942 <#3942>? Thanks.
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub <#3993 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/ACRAR7QTIDU2XLICACLUCU3PRGRMDANCNFSM4HG7K7FQ>.
>
|
Thanks for the feedback.
Yes, this is an unfortunate consequence of the data that is available, hence it's not ready for production etc. In this case, the specification of types accepted is very loose and doesn't really offer useful information, in other cases the hint can be very specific about what is accepted. This in general is a tricky problem to solve but we have some ideas #3855.
We're trying hard to make it less mysterious and ideas of things that would help are always welcome. Part of the challenge is always that Numba doesn't behave like e.g. a statically typed language compiler (e.g. C or Fortran) which a lot of people are familiar with, as Python is dynamic and Numba has to do a lot of work to compute the types of everything to get to the point where it can behave like a static typed language compiler.
The idea of telling the user what was supplied is because it's not always obvious what the type inference mechanism has decided a type should be. Though I do see your point about it being the container class opposed to a specific typed instance of the container class being the problem, I think eventually that could be resolved in the hinting. The example above, whilst matching your code was perhaps less useful, a better one might be: @njit
def foo(x):
x[8.3] # oops, float index on a list!?
return x
foo([1,2,3]) which gives:
|
(HINT: If you put
Please could you open a ticket for this? This is a reasonable request but won't be possible for all flags right now due to the way Numba has to load shared libraries and instantiate some global state in them. Thanks. |
I arrived here by Googling "All templates rejected with literals" after failing to run these functions: @njit
def foo():
return np.zeros((2, 2), dtype=int)
@njit
def foo():
return np.zeros((2, 2), dtype=np.int) Because both of them raise this error:
It turns out I was using dtypes wrong:
|
I had a similar error. I was using |
@pfeatherstone indeed, this should ideally be caught. However, note Numba works on bytecode, CPython has already done the lexicographical analysis etc, https://numba.readthedocs.io/en/stable/developer/architecture.html |
@pfeatherstone @astrojuanlu #6184 tracks improving the error message for this use case, it's a "good first issue" if either of you are interested in contributing to Numba? The issue also contains a starter patch. Thanks. |
Noting an inconsistency between numba and numpy in the type of arguments allowed for empty(), zero() and ones() and probably others.
This is not a bug per se, just a case were generally expected behaviors don't match between numba and numpy.
In numpy the documentation states that the shape argument of numpy.empty is a tuple of dimensions.
However although not documented, numpy will also take a list in place of a tuple.
Numba Will only take a tuple. It will not take a list.
This is both good yet unfortunate.
It's bad because it breaks a lot of existing code that, albeit sloppy, depends on a list being accepted in numpy.
I think is it probably good because Cuda types will work better if Tuples are used I believe.
The real problem is the error output is a bit cryptic and the result unexpected by experienced numpy users.
CODE TO REPRODUCE
The text was updated successfully, but these errors were encountered: