@@ -305,7 +305,13 @@ def simplified(obj):
305305 return retval
306306
307307 def _simplified (self ):
308- return
308+ # The _simplified methods aim to bring the evaluable into an equivalent
309+ # form that is cheaper to evaluate. To avoid circular edits, the
310+ # proposed equivalent form should be a higher priority operation than
311+ # the original based on the following order (high to low): Ravel,
312+ # InsertAxis, Inflate, Diagonalize, Multiply, Add, LoopSum, Sign,
313+ # Power, Inverse, Unravel, Product, Determinant, Sum, Take, TakeDiag.
314+ pass
309315
310316 @cached_property
311317 def optimized_for_numpy (self ):
@@ -5103,32 +5109,4 @@ def eval_sparse(funcs: AsEvaluableArray, **arguments: typing.Mapping[str, numpy.
51035109 _POINTWISE .extend (_c .__subclasses__ ())
51045110
51055111
5106- if __name__ == '__main__' :
5107- # Diagnostics for the development for simplify operations.
5108- simplify_priority = (
5109- Transpose , Ravel , # reinterpretation
5110- InsertAxis , Inflate , Diagonalize , # size increasing
5111- Multiply , Add , LoopSum , Sign , Power , Inverse , Unravel , # size preserving
5112- Product , Determinant , Sum , Take , TakeDiag ) # size decreasing
5113- # The simplify priority defines the preferred order in which operations are
5114- # performed: shape decreasing operations such as Sum and Take should be done
5115- # as soon as possible, and shape increasing operations such as Inflate and
5116- # Diagonalize as late as possible. In shuffling the order of operations the
5117- # two classes might annihilate each other, for example when a Sum passes
5118- # through a Diagonalize. Any shape increasing operations that remain should
5119- # end up at the surface, exposing sparsity by means of the _assparse method.
5120- attrs = ['_' + cls .__name__ .lower () for cls in simplify_priority ]
5121- # The simplify operations responsible for swapping (a.o.) are methods named
5122- # '_add', '_multiply', etc. In order to avoid recursions the operations
5123- # should only be defined in the direction defined by operator priority. The
5124- # following code warns gainst violations of this rule and lists permissible
5125- # simplifications that have not yet been implemented.
5126- for i , cls in enumerate (simplify_priority ):
5127- warn = [attr for attr in attrs [:i ] if getattr (cls , attr ) is not getattr (Array , attr )]
5128- if warn :
5129- print ('[!] {} should not define {}' .format (cls .__name__ , ', ' .join (warn )))
5130- missing = [attr for attr in attrs [i + 1 :] if not getattr (cls , attr ) is not getattr (Array , attr )]
5131- if missing :
5132- print ('[ ] {} could define {}' .format (cls .__name__ , ', ' .join (missing )))
5133-
51345112# vim:sw=4:sts=4:et
0 commit comments