Mul.flatten -- optimize for all-objects-are-commutative case
Previously we used to pass all objects through non-commutative flow path, and
only then they were returned back to commutative code-path.
Of course this was adding some overhead, and this patch reorganizes PART-1 of
Mul.flatten to handle commutative objects more effectively.
Timings (cache: off)
--------------------
d = [x,y,z]
q = [x,y,z,x**2,y**2,z**2]
Mul(*d) Mul(*q) fem_test.py
old: 253 µs 599 µs 4.99 s
new: 208 µs 501 µs 4.67 s
speddup: 21.6% 19.5% 6.8%
Signed-off-by: Kirill Smelkov <kirr@landau.phys.spbu.ru>
Signed-off-by: Ondrej Certik <ondrej@certik.cz>