【发布时间】:2023-04-11 00:29:01
【问题描述】:
我在一个 Julia 项目中,我想在下面的代码中优化我的函数 oneAttempt。
下面是我的代码的简要说明:
- 函数
oneAttmept实现一定的递归算法返回终端结果。 - 变量@ 987654323是通过我在下面的代码中写入的算法更新的变量(我将省略这个问题)。
- 函数
oneAttempt会在for循环下被多次调用(超过1000次)。
function oneAttempt()
n = 30
m = 900
x = rand(Normal(), n, n)
A = ones(n, n) * sum(sum(x, dims = 1))
# f would be passed to the algorithm below.
# f0 is the initial value of f
f0 = ones(n, n) + x - (1 / m) * A
f = copy(f0)
o = zeros(n, n)
#=
algorithm part:
while loop in which f would be updated many times under complicated algorithm
=#
return f;
end
# the function `oneAttempt` would be called many times (more than 1000 times) under for loop.
我想有更好的优化方法来制作f0,因为我听说向量计算将是 Julia 编码中的一个普通瓶颈。
有更好的编码方式吗?
任何信息将不胜感激。
【问题讨论】:
标签: arrays algorithm optimization julia