Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Description
Problem
The addition and subtraction operations in the transformer pipeline always produce various redundant structures, affecting performance and not living up to expectations.
Proposed solution
It is well known that matplotlib uses a transformer pipeline to provide coordinate transformations. The transformer pipeline connects individual transformers in sequence, using the transformation result of the previous transformer as the original coordinates for the next one. Based on the characteristics of coordinate transformations, we can consider it to conform to a mathematical structure called a group, which has the following properties within the transformer pipeline:
- A binary operation (concatenating two transformer pipelines)
- The binary operation has an identity element (IdentityTransform does not change the coordinates and can serve as the identity element)
- The binary operation satisfies the associative law (the order of concatenation does not change the transformation result, the transformation result of a+(b+c) is consistent with that of (a+b)+c)
- The binary operation has an inverse (the inverse function can return the inverse transformation of the current transformer pipeline)
In light of this, I believe the data structure should be improved as follows to conform to the underlying mathematical structure:
- The CompositeGenericTransform class doesn't need a nested structure any more; its storage can be changed to a list of independent transformers. When adding or subtracting, first concatenate the two lists, and then eliminate independent transformers one by one from the connection point. This algorithm can eliminate redundant transformers as much as possible.
- Adding or subtracting IdentityTransform from the transformer pipeline equals the original transformer pipeline.
This is expected not to change the API and should improve the performance of CompositeGenericTransform.