在很长的一行上使用autopep8:奇怪的输出,非常慢

时间:2014-11-11 12:56:09

标签: python

我正在试用autopep8工具。它对我的所有测试用例都很有效,除了一个。在这种情况下,我有一个计算六面体体积的函数:

def getHexVolume3(x,y,z):
    v=-x[0]*y[3]*z[4]+x[0]*y[4]*z[3]-x[1]*y[3]*z[0]+x[1]*y[0]*z[3]+x[1]*y[4]*z[0]-x[1]*y[0]*z[4]-y[0]*z[3]*x[4]+y[0]*x[3]*z[4]-y[1]*z[3]*x[0]+y[1]*x[0]*z[4]+y[1]*x[3]*z[0]-z[0]*x[3]*y[4]+z[0]*y[3]*x[4]-z[1]*x[3]*y[0]+z[1]*y[0]*x[4]+z[1]*y[3]*x[0]-x[1]*y[2]*z[0]+x[1]*y[2]*z[5]+x[1]*y[0]*z[2]+x[1]*y[5]*z[0]-x[1]*y[5]*z[2]-x[1]*y[0]*z[5]-y[1]*z[0]*x[5]-y[1]*z[2]*x[0]+y[1]*z[2]*x[5]+y[1]*x[0]*z[5]+y[1]*x[2]*z[0]-y[1]*x[2]*z[5]-z[1]*x[0]*y[5]-z[1]*x[2]*y[0]+z[1]*x[2]*y[5]+z[1]*y[0]*x[5]+z[1]*y[2]*x[0]-z[1]*y[2]*x[5]-y[1]*z[0]*x[4]-z[1]*x[0]*y[4]-x[0]*y[3]*z[7]+x[0]*y[7]*z[3]+x[2]*y[3]*z[7]-x[2]*y[7]*z[3]-x[2]*y[3]*z[0]+x[2]*y[0]*z[3]-y[0]*z[3]*x[7]+y[0]*x[3]*z[7]-y[2]*z[3]*x[0]+y[2]*x[3]*z[0]+y[2]*z[3]*x[7]-y[2]*x[3]*z[7]+z[2]*x[3]*y[7]-z[0]*x[3]*y[7]+z[0]*y[3]*x[7]-z[2]*y[3]*x[7]-z[2]*x[3]*y[0]+z[2]*y[3]*x[0]-x[1]*y[6]*z[2]+x[1]*y[2]*z[6]-x[2]*y[6]*z[3]+x[2]*y[3]*z[6]-x[2]*y[3]*z[1]+x[2]*y[1]*z[3]-z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x[7]*z[5]+x[5]*y[4]*z[0]-y[0]*z[7]*x[4]+y[0]*x[7]*z[4]-y[5]*z[0]*x[4]+y[5]*x[0]*z[4]+y[5]*z[7]*x[4]-y[5]*x[7]*z[4]-z[0]*x[7]*y[4]+z[0]*y[7]*x[4]+z[5]*x[7]*y[4]-z[5]*y[7]*x[4]-z[5]*x[0]*y[4]+z[5]*y[0]*x[4]+x[5]*y[6]*z[4]-x[5]*y[4]*z[6]

    v=v/12
    return v

在此功能上运行autopep8

$ autopep8 t.py

需要2分10秒才能完成输出:

def getHexVolume3(x, y, z):
    v = -x[0] * y[3] * z[4] + x[0] * y[4] * z[3] - x[1] * y[3] * z[0] + x[1] * y[0] * z[3] + x[1] * y[4] * z[0] - x[1] * y[0] * z[4] - y[0] * z[3] * x[4] + y[0] * x[3] * z[4] - y[1] * z[3] * x[0] + y[1] * x[0] * z[4] + y[1] * x[3] * z[0] - z[0] * x[3] * y[4] + z[0] * y[3] * x[4] - z[1] * x[3] * y[0] + z[1] * y[0] * x[4] + z[1] * y[3] * x[0] - x[1] * y[2] * z[0] + x[1] * y[2] * z[5] + x[1] * y[0] * z[2] + x[1] * y[5] * z[0] - x[1] * y[5] * z[2] - x[1] * y[0] * z[5] - y[1] * z[0] * x[5] - y[1] * z[2] * x[0] + y[1] * z[2] * x[5] + y[1] * x[0] * z[5] + y[1] * x[2] * z[0] - y[1] * x[2] * z[5] - z[1] * x[0] * y[5] - z[1] * x[2] * y[0] + z[1] * x[2] * y[5] + z[1] * y[0] * x[5] + z[1] * y[2] * x[0] - z[1] * y[2] * x[5] - y[1] * z[0] * x[4] - z[1] * x[0] * y[4] - x[0] * y[3] * z[7] + x[0] * y[7] * z[3] + x[2] * y[3] * z[7] - x[2] * y[7] * z[3] - x[2] * y[3] * z[0] + x[2] * y[0] * z[3] - y[0] * z[3] * x[7] + y[0] * x[3] * z[7] - y[2] * z[3] * x[0] + y[2] * x[3] * z[0] + y[2] * z[3] * x[7] - y[2] * x[3] * z[7] + z[2] * x[3] * y[7] - z[0] * x[3] * y[7] + z[0] * y[3] * x[7] - z[2] * y[3] * x[7] - z[2] * x[3] * y[0] + z[2] * y[3] * x[0] - x[1] * y[6] * z[2] + x[1] * y[2] * z[6] - x[2] * y[6] * z[3] + x[2] * y[3] * z[6] - x[2] * y[3] * z[1] + x[2] * y[1] * z[3] - z[1] * y[2] * x[6] - z[2] * x[3] * y[1] + z[2] * y[3] * x[1] + z[2] * x[3] * y[6] - z[2] * y[3] * x[6] + y[2] * z[3] * x[6] - y[2] * z[3] * x[1] + y[2] * x[3] * z[1] - y[2] * x[3] * z[6] + z[1] * x[2] * y[6] + y[1] * z[2] * x[6] - y[1] * x[2] * \
        z[6] - x[0] * y[7] * z[4] + x[0] * y[4] * z[7] + x[5] * y[7] * z[4] - x[5] * y[4] * z[7] - x[5] * y[0] * z[4] + x[1] * y[6] * z[5] - x[1] * y[5] * z[6] + z[1] * x[6] * y[5] - z[1] * y[6] * x[5] - z[5] * x[1] * y[4] + z[5] * y[1] * x[4] + z[5] * x[6] * y[4] - z[5] * y[6] * x[4] - y[5] * z[1] * x[4] + y[5] * z[6] * x[4] + y[5] * x[1] * z[4] - y[5] * x[6] * z[4] - x[5] * y[1] * z[4] + x[5] * y[4] * z[1] + y[1] * z[6] * x[5] - y[1] * x[6] * z[5] - x[6] * y[2] * z[5] + x[6] * y[5] * z[2] - x[6] * y[7] * z[2] - x[6] * y[5] * z[7] + x[6] * y[2] * z[7] + x[6] * y[7] * z[5] - x[2] * y[5] * z[6] + x[7] * y[3] * z[4] - x[7] * y[4] * z[3] + y[6] * z[3] * x[7] + y[6] * z[7] * x[4] - y[6] * x[3] * z[7] - y[6] * x[7] * z[4] - x[3] * y[7] * z[4] + x[3] * y[4] * \
        z[7] - x[4] * y[3] * z[7] + x[4] * y[7] * z[3] + x[6] * y[3] * z[7] + x[6] * y[7] * z[4] - x[6] * y[4] * z[7] - x[6] * y[7] * z[3] + z[6] * x[3] * y[7] + z[6] * x[7] * y[4] - z[6] * y[3] * x[7] - z[6] * y[7] * x[4] + x[2] * y[6] * z[5] + z[6] * x[2] * y[7] + z[6] * x[7] * y[5] - z[6] * y[2] * x[7] - z[6] * y[7] * x[5] - x[5] * y[6] * z[2] + x[5] * y[2] * z[6] + y[6] * z[2] * \
        x[7] + y[6] * z[7] * x[5] - y[6] * x[2] * z[7] - y[6] * x[7] * z[5] + x[5] * y[4] * z[0] - y[0] * z[7] * x[4] + y[0] * x[7] * z[4] - y[5] * z[0] * x[4] + y[5] * x[0] * z[4] + y[5] * z[7] * \
        x[4] - y[5] * x[7] * z[4] - z[0] * x[7] * y[4] + z[0] * y[7] * x[4] + z[5] * x[7] * y[4] - z[5] * \
        y[7] * x[4] - z[5] * x[0] * y[4] + z[5] * y[0] * \
        x[4] + x[5] * y[6] * z[4] - x[5] * y[4] * z[6]
    v = v / 12
    return v

对于这种情况,如何改善autopep8的运行时间和输出?

0 个答案:

没有答案