我想知道是否有可能以某种方式在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
提交
取消