This approach is 4 times fast than the mapslices approach
using BenchmarkTools
function cumprod_exp(x)
y = similar(x)
foreach(
[view(y, :, i) for i in 1:size(y, 2)],
[view(x, :, i) for i in 1:size(x, 2)]
) do v, u
cumprod!(v, exp.(u))
end
return y
end
@btime cumprod_exp($(rand(10, 100)))
You can make it even faster if x is no longer needed
function cumprod_exp(x)
y = similar(x)
foreach(
[view(y, :, i) for i in 1:size(y, 2)],
[view(x, :, i) for i in 1:size(x, 2)]
) do v, u
u .= exp.(u)
cumprod!(v, u)
end
return y
end
Note, that you can easily save even more time by preallocating y – this just avoids the vcats in mapslices