Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
fixed bug in clpmn violating array bounds #482
it seems that there is a bug in the Fortran code of CLPMN where data are written Into the array CPM beyond its bounds provided that M=N. A corresponding bug originally present in the real version LPMN was fixed in 3d5294d3 about eight years ago. This bug concerns not only the associated Legendre polynomials but also the spherical harmonics for complex angles. In Python, the bug becomes apparent in the following minimal code:
The third and fourth argument should not be very important as long as they do not correspond to an argument 1 or -1.
This bug was found by Michael Hartmann and analyzed together with him.
The change in line 275 in b73f9f9 should fix the problem.
ok, I will try to come up with a test. It seems that so far there are no tests for the complex Legendre polynomials but only for the real ones. Should I add a test to the existing class TestLegendreFunctions (so far only real case or rather add a new class for the complex case?
I have added a test to test_basic.py but I must admit that I am not completely happy with it. First of all, the test itself runs ok even with the bug in CLPMN but segfaults at the end if the bug is not fixed. This clearly indicates the presence of the bug but it is not the way how the problem should appear in a test. Secondly, it would be nicer to calculate the expected array from the known formulae but this requires importing sqrt from cmath. I am not sure whether it would be acceptable to do such an import in test_basic.py.
In the test, I have chosen z=0.5+0.3j instead of 5+3j as an argument because then |z|<1 and everything is fine. For |z|>1, there seems to be an extra factor of 1j but I would have to look more deeply into the associated Legendre polynomials for complex arguments to be sure about it. This relates to your remark about writing more comprehensive tests for CLPMN.
added a commit
this pull request
Mar 26, 2013
This comment has been minimized.
This comment has been minimized.Show comment Hide comment
The following picture displaying the behavior of the result of CLPNM for N=M=1 on the imaginary axis gives further evidence that the behavior at |z|=1 is strange. After all, the associated Legendre polynomials should be analytic at z=i.
The problem arises from LS in the code of CLPNM.
The above picture was generated with the following code: