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
UniformTriRefiner gives uncorrect results for transposed arrays #4180
Comments
Hi, Ian, The output of print: Obviously, fine1 is different with fine2, I use numpy 1.9.0 and python 2.7.8, while you used numpy 1.8.2 and python 2.7.6. |
@miaocb The images did not make it through. |
I have confirmed that the bug occurs with mpl 1.4.x and numpy 1.9.x. There is no problem with mpl 1.4.x and numpy 1.8.x, and mpl master is fine regardless of numpy version. I recall that numpy 1.9 required quite a few changes to deal with slightly different python and C interfaces. This is something we must have missed at the time. The C++ triangulation code deals with contiguous numpy arrays and it assumes they are ordered as conventional C arrays, i.e. C-contiguous. A fortran-contiguous array (which is what this issue uses) is correctly converted to C-contiguous by our code for numpy < 1.9, but not for numpy >= 1.9. In the master branch, the rewrite to remove PyCXX has fortuitously removed the bug for us; this is good, but is probably why the bug has not been spotted before. If I remember correctly, we won't be making any more releases from the 1.4.x branch as the next release will be 1.5 or 2.0 from the master branch. If so, there is no point in me fixing the bug in the 1.4.x branch as it will never be released. Can you confirm @tacaswell? @miaocb: Thanks for reporting this bug. Until we make a new release you have a number of options to deal with this bug:
|
2.0 (the color over haul) will be based off of the 1.4 branch rather than Once 2.0 is released the master branch will become 2.1 On Tue, Mar 3, 2015, 04:51 Ian Thomas notifications@github.com wrote:
|
I guess it would make sense to turn this into a test too? |
…iguous triangles
…tiguous_triangles Fix for issue #4180 trirefiner not dealing with fortran contiguous triangles
Thanks. I changed the code as suggested. |
The following code repeats the problem. Array ele1 is same as ele2 except that it is transpose of ele0, but the refined triangles using ele1 is incorrect.
!/bin/env python
import numpy as np
import matplotlib.tri as tri
import matplotlib.pyplot as plt
x = np.array([ 120.39299774, 120.59100342, 120.42900085, 120.31700134])
y = np.array([ 33.99900055, 34.00899887, 34.18799973, 34.18399811])
ele0 = np.array([[2, 2], [0, 1], [3, 0]])
ele1 = ele0.transpose() # ele1 is same as ele2 except that it is transpose of ele0
ele2 = np.array([[2, 0, 3], [2, 1, 0]])
triang1 = tri.Triangulation(x, y, ele1)
triang2 = tri.Triangulation(x, y, ele2)
refiner1 = tri.UniformTriRefiner(triang1)
refiner2 = tri.UniformTriRefiner(triang2)
fine_triang1 = refiner1.refine_triangulation(subdiv=1)
fine_triang2 = refiner2.refine_triangulation(subdiv=1)
fig = plt.figure()
ha1 = fig.add_subplot(121)
ha1.set_aspect('equal')
plt.triplot(fine_triang1, color='b', linewidth=0.5)
plt.triplot(triang1, color='k', linewidth=1)
plt.title('refine_triang1 is incorrect')
ha2 = fig.add_subplot(122)
ha2.set_aspect('equal')
plt.triplot(fine_triang2, color='b', linewidth=0.5)
plt.triplot(triang2, color='k', linewidth=1)
plt.title('refine_triang2 is correct')
plt.show()
The text was updated successfully, but these errors were encountered: