Pythran export dict with tuples as key
Asked Answered
S

1

0

I try to use Pythran in a function that needs an int array and for the second arg a dict with tuples of ints as keys and an int as value:

myarray = np.array([[0, 0], [0, 1], [1, 1],
                    [1, 2], [2, 2], [1, 3]])

dict_with_tuples_key = {(0, 1): 1, (3, 7): 1}

What is the correct way to inform Pythran about the dict ?:

#pythran export update_dict((int, int):int dict, int[][])
def update_dict(dict_with_tuples_key, myarray):
    # do something with dict_with_tuples_key and myarray
    # return and updated dict_with_tuples_key
    return dict_with_tuples_key

With (int, int):int dict I get this error:

File "/usr/lib/python2.7/inspect.py", line 526, in findsource
  file = getfile(object)
File "/usr/lib/python2.7/inspect.py", line 403, in getfile
  raise TypeError('{!r} is a built-in module'.format(object))
TypeError: <module 'sys' (built-in)> is a built-in module
Seedbed answered 6/2, 2016 at 10:55 Comment(1)
which version of pythran are you using? Ifail to repoduce your issue with the master (b44c9a38a0894bf89872482a10abee2a61316303) version.Glaciate
G
2

From your backtrace, it seems you're importing sys. In that kind of situation, pythran tries to get the source of the import module to compile it. As sys is a built-in module, it fails.

Glaciate answered 6/2, 2016 at 21:14 Comment(1)
Ok I get it, I was running pythran on a code.py file with a lot of other functions; I thought that only the one with # pythran export ... comments will be affected by pythran. All work as a charm if I create a dedicated ccompile.py with only the functions I want to give to pythran. The acceleration is amazing !Seedbed

© 2022 - 2024 — McMap. All rights reserved.