# Changeset 3894

Ignore:
Timestamp:
Apr 13, 2019 8:10:41 AM (5 years ago)
Message:

optimize getRhos ~ 10-20% improvement is all I could manage

File:
1 edited

Unmodified
Added
Removed
• ## trunk/GSASIImath.py

 r3893 :returns: density at xyz ''' Blk = 8     #8 seems optimal nBlk = len(XYZ)//Blk        #select Blk so this is an exact divide rollMap = lambda rho,roll: np.roll(np.roll(np.roll(rho,roll[0],axis=0),roll[1],axis=1),roll[2],axis=2)[:2,:2,:2] mapShape = np.array(rho.shape) mapStep = 1./mapShape X = XYZ%1.    #get into unit cell I = np.array(np.rint(X*mapShape),dtype='int') iBeg = 0 R = np.zeros(len(XYZ)) for i,x in enumerate(X): D = x-I[i]*mapStep         #position inside map cell Rho = rollMap(rho,-I[i])    #shifts map so point is in corner RIJ = Rho[0,:2,:2]*(1.-D[0]) RI = RIJ[0]*(1.-D[1])+RIJ[1]*D[1] R[i] = RI[0]*(1.-D[2])+RI[1]*D[2] #actually a bit faster! for iblk in range(nBlk): iFin = iBeg+Blk Xs = X[iBeg:iFin] I = np.array(np.rint(Xs*mapShape),dtype='int') Rhos = np.array([rollMap(rho,-i) for i in I]) Ds = Xs-I*mapStep RIJs = Rhos[:,0,:2,:2]*(1.-Ds[:,0][:,nxs,nxs]) RIs = RIJs[:,0]*(1.-Ds[:,1][:,nxs])+RIJs[:,1]*Ds[:,1][:,nxs] R[iBeg:iFin] = RIs[:,0]*(1.-Ds[:,2])+RIs[:,1]*Ds[:,2] iBeg += Blk #one at a time #    for i,x in enumerate(X): #        D = x-I[i]*mapStep         #position inside map cell #        Rho = rollMap(rho,-I[i])    #shifts map so point is in corner #        RIJ = Rho[0,:2,:2]*(1.-D[0]) #        RI = RIJ[0]*(1.-D[1])+RIJ[1]*D[1] #        R[i] = RI[0]*(1.-D[2])+RI[1]*D[2] return R
Note: See TracChangeset for help on using the changeset viewer.