pyccel / pyccel

Python extension language using accelerators
MIT License
335 stars 55 forks source link

Python interfaces #802

Open EmilyBourne opened 3 years ago

EmilyBourne commented 3 years ago

Describe the bug Interfaces in python assume that the code is the same in all languages and therefore print the body of the first FunctionDef with all the decorators. However the code generated by pyccel is not always the same (e.g. if the input can be either a boolean or a numeric type)

To Reproduce Provide code to reproduce the behavior:

@types('float')
@types('complex')
def get_imag(a):
    import numpy as np
    return np.imag(a)

Provide the generated code, or the error message:

from pyccel.decorators import types

@types('float')
@types('complex')
def get_imag(a):

    from numpy import imag
    return 0.0

Expected behavior There are multiple possible solutions:

Language python

Additional context This is causing some of our tests to be incomplete, but the tests could also be fixed by avoiding interfaces. In an ideal world, the dtype should be a pytest parameter

ratnania commented 3 years ago

What if we have a python decorator that will concatenate the function name with the associated type, in order to avoid the last defined function get_imag?

EmilyBourne commented 3 years ago

What if we have a python decorator that will concatenate the function name with the associated type, in order to avoid the last defined function get_imag?

I'm not sure that we can avoid the last function no matter the name of the functions as in pyccel we always aim to have a result that can be called in the same way as the original code

EmilyBourne commented 3 years ago

Duplicate of #885