Skip to content

Bugfix for TriAnalyzer mismatched indexes - #5065

Merged
WeatherGod merged 1 commit into
matplotlib:masterfrom
ianthomas23:4999_TriAnalyzer_mismatched_indexes
Sep 14, 2015
Merged

WeatherGod merged 1 commit into
matplotlib:masterfrom
ianthomas23:4999_TriAnalyzer_mismatched_indexes

Conversation

@ianthomas23

Copy link
Copy Markdown
Member

This is a bugfix for issue #4999.

It follows a tightening up in numpy 1.10 when indexing one array with a second boolean array which is smaller, such as

x = np.asarray([1.0, 2.0, 3.0, 4.0])
index_array = np.asarray([False, True])
y = x[index_array]

Here index_array is shorter than x. Prior to numpy 1.10 this was acceptable, with index_array padded out with False values. In numpy 1.10 it issues a VisibleDeprecationWarning.

The problem occurs in TriAnalyzer for a Triangulation that contains points that are not referenced by any triangles, which can occur if triangles are masked out. The solution is to make sure the boolean array is of the correct size, which is easily accomplished in this case using the minlength kwarg which was added to numpy.bincount in version 1.6.

I have not added an explicit test as the existing test_triangulation.test_tritools already finds the bug.

Thanks to @WeatherGod for reporting the problem.

@tacaswell tacaswell added this to the next point release milestone Sep 14, 2015
WeatherGod added a commit that referenced this pull request Sep 14, 2015
…_indexes

Bugfix for TriAnalyzer mismatched indexes
@WeatherGod
WeatherGod merged commit 40bc075 into matplotlib:master Sep 14, 2015
@WeatherGod

Copy link
Copy Markdown
Member

Thanks @ianthomas23! Great to get this in for 1.5!

@GBillotey

Copy link
Copy Markdown
Contributor

Thanks @ianthomas23 for the fix. (Sorry for being late on this one, I have been trying to compile again from master under windows with no success so far).

However I have noticed this line in tritools which probably presents a similar issue:
https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/tri/tritools.py#l260

node_mask = (np.bincount(np.ravel(compressed_triangles)) == 0)

Should be

node_mask = (np.bincount(np.ravel(compressed_triangles),
             minlength=self._triangulation.x.size) == 0)

@ianthomas23

Copy link
Copy Markdown
Member Author

@GBillotey: OK, I have written another PR to cover the second occurrence of the bug that you've found.

@ianthomas23
ianthomas23 deleted the 4999_TriAnalyzer_mismatched_indexes branch July 8, 2021 18:22
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

Successfully merging this pull request may close these issues.

4 participants