Skip to content
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

Assertion check error in core.pyx #34

Closed
rougier opened this issue Apr 22, 2019 · 7 comments
Closed

Assertion check error in core.pyx #34

rougier opened this issue Apr 22, 2019 · 7 comments

Comments

@rougier
Copy link

rougier commented Apr 22, 2019

I'm using triangle for the glumpy library (glumpy.github.io) and since last update (triangle), I get some consistent errors:

Traceback (most recent call last):
  File "collection-triangles.py", line 51, in <module>
    I = triangulate(P)
  File "collection-triangles.py", line 26, in triangulate
    T = triangle.triangulate({'vertices': P[:,:2], 'segments': S}, "p")
  File "/usr/local/lib/python3.7/site-packages/triangle/tri.py", line 66, in triangulate
    tri, _ = triang(tri, opts)
  File "triangle/core.pyx", line 247, in triangle.core.triang
  File "triangle/core.pyx", line 219, in triangle.core.fin
  File "triangle/core.pyx", line 74, in triangle.core.ii._set
  File "triangle/core.pyx", line 115, in triangle.core._wrap.check
AssertionError

When I looked at your code, I've to admit I'm a bit puzzled by these lines:

cdef _wrap(triangulateio* c):

    cdef int _1 = 1
    cdef int _2 = 2
    cdef int _3 = 3
    cdef int _4 = 4

    def check():
        assert _1 == 1
        assert _2 == 2
        assert _3 == 3
        assert _4 == 4

Obviously in my case these assertions are False but I'm not sure to understand how this can be. Any advices on how to debug ?

In glumpy, I'm using the tiger.py to test.

@yuqli
Copy link

yuqli commented Apr 22, 2019

I have the exact same problem since last night! Have to learn some Cython but still, this error seems to be in the assert lines you quoted.

Since this library is updated three months ago and we both seem to be running into trouble since last night, maybe it's some changes in the Cython library. It could be a cdef int is no longer a Python int. I'm not sure why we need these lines either, though.

@drufat
Copy link
Owner

drufat commented Apr 22, 2019

These assertions just make sure that assumptions about the number of dimensions of arrays in the C library and the python wrapper are actually correct. Do you think you can provide the contents of the P and S variables in the call

triangle.triangulate({'vertices': P[:,:2], 'segments': S}, "p")

which results in the assertion failure? Or I can extract them from the example you have given once I get back to my desk a little later.

@yuqli
Copy link

yuqli commented Apr 23, 2019

These assertions just make sure that assumptions about the number of dimensions of arrays in the C library and the python wrapper are actually correct. Do you think you can provide the contents of the P and S variables in the call

triangle.triangulate({'vertices': P[:,:2], 'segments': S}, "p")

which results in the assertion failure? Or I can extract them from the example you have given once I get back to my desk a little later.

Thanks for the prompted reply. If it helps, this is the data I used as inputs to the triangulate function which lead to the exact same error. Is it because my data points are 3D instead of 2D?

Code:

   poly = {'vertices': np.array(newpolypoints), 'segments': np.array(segments)}
    print(poly)
    # print poly
    # -- Triangulate
    t = triangle.triangulate(poly, "p")

Output:


{'vertices': array([[  9.24246154,  -2.02496154,  -8.79692308],
       [  6.71146154,  -4.45896154,  -8.79692308],
       [  2.78446154,  -8.23696154,  -8.79692308],
       [  1.91946154,  -9.06896154,  -8.79692308],
       [-11.00953846,   4.26003846,  -8.79692308],
       [ -3.68553846,  11.30403846,  -8.79692308]]), 'segments': array([[0, 1],
       [1, 2],
       [2, 3],
       [3, 4],
       [4, 5],
       [5, 0]])}
Traceback (most recent call last):
  File "triangulation.py", line 201, in <module>
    main()
  File "triangulation.py", line 195, in main
    res = my_triangulation(face_with_points[0])
  File "triangulation.py", line 146, in my_triangulation
    t = triangle.triangulate(poly, "p")
AttributeError: module 'triangle' has no attribute 'triangulate'

@yuqli
Copy link

yuqli commented Apr 23, 2019

I revised my code and when inputs are 2D arrays the assertionError no longer occurred. Thanks for the help! It could be a coincidence that @rougier and I have the exact same error at roughly the same time... I'm not sure about her/his exact issue though.

@drufat
Copy link
Owner

drufat commented Apr 23, 2019

@yuqli
Yes, vertices need to be a 2D array containing the x, y coordinates of each vertex.

@drufat
Copy link
Owner

drufat commented Apr 23, 2019

@rougier I think this pull request for glumpy should fix the issue with the assertion error.
glumpy/glumpy#216

@rougier
Copy link
Author

rougier commented Apr 23, 2019

@drufat Oh nice, many thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants