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>