Matrix: speedup __getattr__ and __setattr__ for element-wise access
commit683c877946737b6f165c8e84c8295f1715ba9ca0
authorKirill Smelkov <kirr@landau.phys.spbu.ru>
Thu, 21 Aug 2008 18:30:51 +0000 (21 22:30 +0400)
committerKirill Smelkov <kirr@landau.phys.spbu.ru>
Thu, 21 Aug 2008 18:30:51 +0000 (21 22:30 +0400)
treec4dfb80058e00b07e43be5f96059ad4b1f27d4f5
parent54c0646bb1d4571d7465c54b98335f651cf4a931
Matrix: speedup __getattr__ and __setattr__ for element-wise access

This two operations are the workhorse of many matrix algorithms, e.g.
solve_linear_system. That's why it is so important to provide fast
access to matrix elements.

The speedup is done through:

o not using isinstance (which is slow) and using type(x) is Y (which is
  much faster) instead
o inlining calls to a2idx  (function calls are expensive in Pthon)

Timings (cache: off)
--------------------

N=8
M=eye(N)

        %timeit     %time
        M[0,0]      integrate(x**3*sin(x), x)

old:    38.3 µs     5.77 s
new:    14.4 µs     5.04 s

speedup: 2.66x       14%

Signed-off-by: Kirill Smelkov <kirr@landau.phys.spbu.ru>
Signed-off-by: Mateusz Paprocki <mattpap@gmail.com>
sympy/matrices/matrices.py