pythran
pythran copied to clipboard
[BUG] Possible bug in optional argument parsing
In file transition_analyzer.py, which gets compiled to transition_analyzer.so:
import numpy as np
#pythran export transition_analyzer(float[:, :], float, float)
#pythran export transition_analyzer(float[:, :], float)
def transition_analyzer(eigenvalues, qshift=0.0, fermi_level=-0.35):
rows, cols = eigenvalues.shape
# eigenvalues = np.asfortranarray(eigenvalues)
print(rows, cols)
just_above_fermi_location = np.empty(cols, dtype=np.int32)
for i in range(cols):
just_above_fermi_location[i] = np.argwhere(eigenvalues[:, i] > fermi_level)[-1][0]
x = []
#pragma omp parallel for
for k1 in range(cols):
for k2 in range(cols):
for energy_of_filled_band in range(rows-1, just_above_fermi_location[k1], -1):
a = eigenvalues[:just_above_fermi_location[k2] + 1, k2] - eigenvalues[energy_of_filled_band, k1]
x.append(a)
print("Done!")
return x
# print(just_above_fermi_location)
In file tester.py
import numpy as np
from transition_analyzer import transition_analyzer
np.random.seed(1)
a = np.linspace(-5, 2, 65)[::-1, None].repeat(40, axis=1)
transition_analyzer(a, qshift=-0.0)
transition_analyzer(a, fermi_level=-0.2)
In file tester.py, the first call works, the second call fails.
The error message is:
65 40
Done!
Traceback (most recent call last):
File "tester.py", line 7, in <module>
transition_analyzer(a, fermi_level=-0.2)
TypeError: Invalid call to pythranized function `transition_analyzer(ndarray, fermi_level=float)'
Candidates are:
transition_analyzer(float[:,:],float)
transition_analyzer(float[:,:].T,float)
transition_analyzer(float[:,:],float,float)
transition_analyzer(float[:,:].T,float,float)
I fail to reproduce on master + python3 :-/
In file pythtest.py which gets compiled to pythtest.so:
#pythran export pythtest(float)
#pythran export pythtest(float, float)
#pythran export pythtest(float, float, float)
def pythtest(a, b=10.0, c=10.0):
return a + b + c
File pythtest_driver.py:
from pythtest import pythtest as pt
print(pt(1.0))
print(pt(1.0, c=3.0))
I've used the old optional syntax with multiple exports. On running this with:
pythran pythtest.py;python pythtest_driver.py
I get
21.0
Traceback (most recent call last):
File "pythtest_driver.py", line 4, in <module>
print(pt(1.0, c=3.0))
TypeError: Invalid call to pythranized function `pythtest(float, c=float)'
Candidates are:
- pythtest(float, float, float)
- pythtest(float, float)
- pythtest(float)
Thanks for the test case, I can now reproduce o/
I now understand the error: the first export maps to pythtest(a)
, the second to pythtest(a, b)
and the third to pythtest(a, b, c)
.
There's currently no way for pythran to understand that you want the default value for b
.