在尝试减少通过使用生成器表达式计算可能性的函数生成的分配数量时,我遇到了以下我不太理解的行为。取以下两个函数:
\nfunction testMax!(x,X,\xce\xb2)\n xmax = 0.0\n @inbounds for i \xe2\x88\x88 eachindex(x)\n x[i] = X[i,2] * \xce\xb2[1] + X[i,2] * \xce\xb2[2]\n if x[i] > xmax \n xmax = x[i]\n end \n end \n y = 0.0 \n for i \xe2\x88\x88 eachindex(x)\n y += exp(x[i]-xmax)\n end\n return xmax, y\nend\n\nfunction testMaxWeird!(x,X,\xce\xb2)\n xmax = 0.0\n @inbounds for i \xe2\x88\x88 eachindex(x)\n x[i] = X[i,2] * \xce\xb2[1] + X[i,2] * \xce\xb2[2]\n if x[i] > xmax \n xmax = x[i]\n end \n end \n y = …Run Code Online (Sandbox Code Playgroud) julia ×1