我想知道是否有可能以某種方式在numpy的這部分代碼中優化dotproduts和數組轉換,根據分析器,這占用了我代碼運行時間的95%。(我不想使用f2py,cython或pyOpenCl,我只是在學習如何有效地使用numpy)def evalSeriesInBasi(a,B): Y = dot(a,B[0]) dY = dot(a,B[1]) ddY = dot(a,B[2]) return array([Y,dY,ddY])def evalPolarForces( R, O ): # numexpr doest seem to help it takes 3,644 vs. 1.910 with pure numpy G = 1.0 / (R[0]**2) # Gravitational force F_O = R[0] * O[2] + 2 * R[1] * O[1] # Angular Kinematic Force = Angular engine thrust F_R = R[0] * O[1]**2 + R[2] FTR = F_R - G FT2 = F_O**2 + FTR**2 # Square of Total engine Trust Force ( corespons to propelant consuption for power limited variable specific impulse engine) return array([F_O,F_R,G,FTR, FT2]) def evalTrajectoryPolar( Rt0, Ot0, Bs, Rc, Oc ): Rt = Rt0 + evalSeriesInBasi(Rc,Bs) Ot = Ot0 + evalSeriesInBasi(Oc,Bs) Ft = evalPolarForces( Rt, Ot ) return Ot, Rt, Ft其中“ B”是存儲基本函數的形狀(3,32,128)的數組,“ a”是這些基本函數的系數,并且所有其他數組(如Y,dY,ddY,F_O,F_R,G,FTR,FT2)都是值128個采樣點的某些功能根據探查器,最多的時間是numpy.core.multiarray.array和numpy.core._dotblas.dot ncalls tottime percall cumtime percall filename:lineno(function)22970 2.969 0.000 2.969 0.000 {numpy.core.multiarray.array}46573 0.926 0.000 0.926 0.000 {numpy.core._dotblas.dot} 7656 0.714 0.000 2.027 0.000 basiset.py:61(evalPolarForces) 7656 0.224 0.000 0.273 0.000 OrbitalOptCos_numpyOpt.py:43(fitnesFunc) 7656 0.192 0.000 4.868 0.001 basiset.py:54(evalTrajectoryPolar) 116 0.141 0.001 5.352 0.046 optimize.py:536(approx_fprime) 7656 0.132 0.000 5.273 0.001 OrbitalOptCos_numpyOpt.py:63(evalFitness)15312 0.101 0.000 2.649 0.000 basiset.py:28(evalSeriesInBasi)
添加回答
舉報
0/150
提交
取消