Skip to content

TriAnalyzer.scale_factors() has mismatched boolean indexes #4999

Closed

Description

@WeatherGod

Testing matplotlib master with numpy 1.10rc1 revealed some possible bugs in matplotlib through deprecation warnings. One set of warnings comes from the triangulation library:

/nas/home/broot/centos6/lib/python2.7/site-packages/matplotlib-1.5.dev1-py2.7-linux-x86_64.egg/matplotlib/tri/tritools.py:52: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 5 but corresponding boolean dimension is 4
  x = self._triangulation.x[node_used]
/nas/home/broot/centos6/lib/python2.7/site-packages/matplotlib-1.5.dev1-py2.7-linux-x86_64.egg/matplotlib/tri/tritools.py:53: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 5 but corresponding boolean dimension is 4
  y = self._triangulation.y[node_used]

Indeed, adding a check in scale_factors() and running the triangulation test suite reveals:

======================================================================
ERROR: __main__.test_tritools
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/nas/home/broot/centos6/lib/python2.7/site-packages/nose-1.1.2-py2.7.egg/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "lib/matplotlib/tests/test_triangulation.py", line 834, in test_tritools
    assert_array_almost_equal(analyser.scale_factors,
  File "/nas/home/broot/centos6/lib/python2.7/site-packages/matplotlib-1.5.dev1-py2.7-linux-x86_64.egg/matplotlib/tri/tritools.py", line 55, in scale_factors
    len(node_used)))
ValueError: len of nodes does not match node_used. 5 vs. 4

The test in question:

def test_tritools():
    # Tests TriAnalyzer.scale_factors on masked triangulation
    # Tests circle_ratios on equilateral and right-angled triangle.
    x = np.array([0., 1., 0.5, 0., 2.])
    y = np.array([0., 0., 0.5*np.sqrt(3.), -1., 1.])
    triangles = np.array([[0, 1, 2], [0, 1, 3], [1, 2, 4]], dtype=np.int32)
    mask = np.array([False, False, True], dtype=np.bool)
    triang = mtri.Triangulation(x, y, triangles, mask=mask)
    analyser = mtri.TriAnalyzer(triang)
    assert_array_almost_equal(analyser.scale_factors,
                              np.array([1., 1./(1.+0.5*np.sqrt(3.))]))
   <snip>

@ianthomas23 , git blame tells me that you didn't write tritools.py, but perhaps you have some insights? Looks like it was introduced in cd45a80

Activity

  1. WeatherGod commented on Aug 27, 2015

    @WeatherGod
    MemberAuthor
  2. ianthomas23 commented on Sep 14, 2015

    @ianthomas23
    Member

    @WeatherGod: Thanks for reporting this. Bug confirmed using numpy 1.10.0b1; trivial fix on its way.

  3. jenshnielsen commented on Sep 15, 2015

    @jenshnielsen
    Member

    @ianthomas23 @WeatherGod Is this fully fixed?

  4. WeatherGod commented on Sep 15, 2015

    @WeatherGod
    MemberAuthor

    Should be, now that the two PRs are in. If there are other sources of this bug in the tri module, I wouldn't know and the tests aren't picking up on it using numpy 1.10.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions