Matrix: speedup __getattr__ and __setattr__ for element-wise access
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 <b0eeaac46e675e9f95bf68c0df1041cf581c26f4@landau.phys.spbu.ru>
Signed-off-by: Mateusz Paprocki <4e51c28eba28c1534bcc4a6bd2cccd314d8bf749@gmail.com>

kumarkrishna/sympy,maniteja123/sympy,pbrady/sympy,farhaanbukhsh/sympy,madan96/sympy,iamutkarshtiwari/sympy,jaimahajan1997/sympy,oliverlee/sympy,ga7g08/sympy,diofant/diofant,VaibhavAgarwalVA/sympy,Arafatk/sympy,atreyv/sympy,lindsayad/sympy,jerli/sympy,cswiercz/sympy,lindsayad/sympy,postvakje/sympy,MridulS/sympy,mcdaniel67/sympy,shikil/sympy,beni55/sympy,asm666/sympy,Designist/sympy,atsao72/sympy,hargup/sympy,postvakje/sympy,AkademieOlympia/sympy,meghana1995/sympy,Arafatk/sympy,aktech/sympy,kevalds51/sympy,atsao72/sympy,sunny94/temp,liangjiaxing/sympy,meghana1995/sympy,hargup/sympy,wanglongqi/sympy,cswiercz/sympy,ChristinaZografou/sympy,rahuldan/sympy,kaushik94/sympy,VaibhavAgarwalVA/sympy,mcdaniel67/sympy,abhiii5459/sympy,jbaayen/sympy,farhaanbukhsh/sympy,jamesblunt/sympy,saurabhjn76/sympy,atreyv/sympy,saurabhjn76/sympy,pernici/sympy,hrashk/sympy,yukoba/sympy,atreyv/sympy,shipci/sympy,debugger22/sympy,asm666/sympy,bukzor/sympy,sunny94/temp,dqnykamp/sympy,Shaswat27/sympy,sahmed95/sympy,mattpap/sympy-polys,tovrstra/sympy,Mitchkoens/sympy,Davidjohnwilson/sympy,mafiya69/sympy,wyom/sympy,abhiii5459/sympy,ChristinaZografou/sympy,bukzor/sympy,drufat/sympy,wyom/sympy,cswiercz/sympy,kaushik94/sympy,vipulroxx/sympy,mafiya69/sympy,chaffra/sympy,debugger22/sympy,kmacinnis/sympy,cccfran/sympy,jamesblunt/sympy,Davidjohnwilson/sympy,madan96/sympy,chaffra/sympy,amitjamadagni/sympy,liangjiaxing/sympy,vipulroxx/sympy,Mitchkoens/sympy,wyom/sympy,grevutiu-gabriel/sympy,Mitchkoens/sympy,beni55/sympy,abloomston/sympy,Gadal/sympy,mafiya69/sympy,jerli/sympy,sunny94/temp,aktech/sympy,bukzor/sympy,hazelnusse/sympy-old,yashsharan/sympy,lidavidm/sympy,abloomston/sympy,abloomston/sympy,wanglongqi/sympy,moble/sympy,vipulroxx/sympy,hazelnusse/sympy-old,jbbskinny/sympy,shipci/sympy,MechCoder/sympy,yashsharan/sympy,liangjiaxing/sympy,garvitr/sympy,Curious72/sympy,ChristinaZografou/sympy,MechCoder/sympy,beni55/sympy,shikil/sympy,saurabhjn76/sympy,rahuldan/sympy,moble/sympy,emon10005/sympy,iamutkarshtiwari/sympy,MridulS/sympy,flacjacket/sympy,Curious72/sympy,Vishluck/sympy,kumarkrishna/sympy,garvitr/sympy,sampadsaha5/sympy,Davidjohnwilson/sympy,Vishluck/sympy,dqnykamp/sympy,kmacinnis/sympy,VaibhavAgarwalVA/sympy,sampadsaha5/sympy,jbbskinny/sympy,Designist/sympy,maniteja123/sympy,garvitr/sympy,souravsingh/sympy,mcdaniel67/sympy,Sumith1896/sympy,dqnykamp/sympy,jaimahajan1997/sympy,grevutiu-gabriel/sympy,sahilshekhawat/sympy,AunShiLord/sympy,lidavidm/sympy,kevalds51/sympy,kevalds51/sympy,kmacinnis/sympy,chaffra/sympy,sahilshekhawat/sympy,hrashk/sympy,souravsingh/sympy,emon10005/sympy,ahhda/sympy,moble/sympy,AkademieOlympia/sympy,meghana1995/sympy,aktech/sympy,ryanGT/sympy,Vishluck/sympy,Shaswat27/sympy,debugger22/sympy,farhaanbukhsh/sympy,Designist/sympy,jamesblunt/sympy,toolforger/sympy,shikil/sympy,skidzo/sympy,kumarkrishna/sympy,Curious72/sympy,Gadal/sympy,shipci/sympy,KevinGoodsell/sympy,sahmed95/sympy,oliverlee/sympy,cccfran/sympy,toolforger/sympy,amitjamadagni/sympy,MridulS/sympy,postvakje/sympy,sampadsaha5/sympy,abhiii5459/sympy,minrk/sympy,jerli/sympy,yukoba/sympy,pandeyadarsh/sympy,srjoglekar246/sympy,grevutiu-gabriel/sympy,kaichogami/sympy,toolforger/sympy,kaushik94/sympy,minrk/sympy,yashsharan/sympy,AunShiLord/sympy,AunShiLord/sympy,madan96/sympy,AkademieOlympia/sympy,hargup/sympy,Titan-C/sympy,Gadal/sympy,souravsingh/sympy,ahhda/sympy,maniteja123/sympy,sahilshekhawat/sympy,Shaswat27/sympy,lidavidm/sympy,skirpichev/omg,ga7g08/sympy,oliverlee/sympy,jaimahajan1997/sympy,ahhda/sympy,hrashk/sympy,iamutkarshtiwari/sympy,Arafatk/sympy,ga7g08/sympy,kaichogami/sympy,kaichogami/sympy,rahuldan/sympy,sahmed95/sympy,MechCoder/sympy,jbbskinny/sympy,pandeyadarsh/sympy,drufat/sympy,skidzo/sympy,fperez/sympy,pbrady/sympy,atsao72/sympy,Titan-C/sympy,skidzo/sympy,Sumith1896/sympy,pandeyadarsh/sympy,asm666/sympy,wanglongqi/sympy,drufat/sympy,lindsayad/sympy,yukoba/sympy,cccfran/sympy,Titan-C/sympy,emon10005/sympy,Sumith1896/sympy,pbrady/sympy