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

ValueError: cannot compute fingerprint of empty list #2152

Closed
dickreuter opened this issue Oct 16, 2016 · 9 comments
Closed

ValueError: cannot compute fingerprint of empty list #2152

dickreuter opened this issue Oct 16, 2016 · 9 comments
Milestone

Comments

@dickreuter
Copy link

dickreuter commented Oct 16, 2016

from numba import jit
@jit()
def create_card_deck():
    values = "23456789TJQKA"
    suites = "CDHS"
    Deck = []
    for x in values:
        for y in suites:
            Deck.append(x + y)
    return Deck

create_card_deck()
@synapticarbors
Copy link
Contributor

A work around is to create the list with an initial item of the same type as you are going to add and then throw it away before you return:

from numba import jit

@jit
def create_card_deck():
    values = "23456789TJQKA"
    suites = "CDHS"
    Deck = ['x']
    for x in values:
        for y in suites:
            Deck.append(x + y)
    return Deck[1:]

@dickreuter
Copy link
Author

Ok makes sense. Thanks

On Tuesday, 18 October 2016, Joshua Adelman notifications@github.com
wrote:

A work around is to create the list with an initial item of the same type
as you are going to add and then throw it away before you return:

from numba import jit
@jitdef create_card_deck():
values = "23456789TJQKA"
suites = "CDHS"
Deck = ['x']
for x in values:
for y in suites:
Deck.append(x + y)
return Deck[1:]


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#2152 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/ABMrfkyaD62cIBy3_sLfuMMk--MtHiGzks5q1NQogaJpZM4KX9jG
.

@seibert seibert added this to the Numba 0.30 milestone Oct 20, 2016
stuartarchibald added a commit to stuartarchibald/numba that referenced this issue Oct 28, 2016
This patch is one way of seemingly fixing the inability to compute
the fingerprint of an empty list (or set!), as reported in numba#2152.

It seems like empty containers can take part in fast lookup but
only if more op codes are added. Whether this is a valid approach,
given possible nuances, and the general "adding more opcodes"
going against the principle of fast lookup, is to be determined.

It should be noted that using '[' for an empty list seemingly
works too.
stuartarchibald added a commit to stuartarchibald/numba that referenced this issue Nov 1, 2016
This patch is one way of seemingly fixing the inability to compute
the fingerprint of an empty list (or set!), as reported in numba#2152.

It seems like empty containers can take part in fast lookup but
only if more op codes are added. Whether this is a valid approach,
given possible nuances, and the general "adding more opcodes"
going against the principle of fast lookup, is to be determined.

It should be noted that using '[' for an empty list seemingly
works too.
@stuartarchibald
Copy link
Contributor

Related comments on what needs to happen to fix this are at the bottom of #2184

@Permafacture
Copy link

So, how does the closing of #2184 affect this issue? Is it now intentional to disallow empty lists being passed into nopython jitted functions?

@stuartarchibald
Copy link
Contributor

As of 0.42.0 the original sample works (updates have been made to type inference to help type empty lists). Closing.

@Mostro-Complexity
Copy link

Mostro-Complexity commented Jan 7, 2020

When I use version 0.44.1 numba, the above problem still occurs.
my code:

def func(X, a, b):
    if len(a) > 0 and len(b) > 0:
        for i in range(X.shape[1]):
            X[:, :i] += i

    return np.empty(X.shape[0], dtype=np.float64)


func(np.zeros((10, 10)), [], [])

Error message:

Exception has occurred: ValueError
cannot compute fingerprint of empty list

@stuartarchibald
Copy link
Contributor

@Mostro-Complexity reflected lists (what you are using) are in the process of being deprecated, please take a look at their replacement, numba.typed.List, docs are here. Thanks.

@shaunc
Copy link
Contributor

shaunc commented Jul 18, 2021

I'm getting the equivalent error for set. There doesn't seem to be any equivalent to numba.typed.List for set? (At least, not in doc.) Should I open a tracking issue ... or is this otherwise in the works?

Update:

Ah -- https://numba.pydata.org/numba-doc/latest/reference/deprecation.html#expected-replacement

Upshot: typed set is at least documented as not yet implemented.

@esc
Copy link
Member

esc commented Jul 19, 2021

Upshot: typed set is at least documented as not yet implemented.

Yup it's on the wishlist. It is quite the undertaking and will require lot's of code to be written.It will however be reasonably well isolated from the rest of the code base, since the feature will be largely additive. And, in addition there are two existing typed container implementations, List and Dict that can be cribbed from. Essentially, it involves taking the set implementation from cpython and transplanting it into Numba (and it's runtime) and making it usable from there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants