Hi All,
I'm new in Julia and I need to decide about the more correct/better
implementation for two data collection. I have implemented mean absolute
percentage error (MAPE) for *Generator Expressions* (Comprehensions without
brackets):
a = rand(10_000_000)
p = rand(10_000_000)
err(actual, predicted) = (actual - predicted) / actual
f(a, p) = 100 * sumabs(err(a[i], p[i]) for i in eachindex(a)) /length(a)
a with *mapreduce()* function.
function mapre(a, p)
s = mapreduce(t -> begin b,c=t; abs((b - c) / b) end, +, zip(a, p))
s * 100/length(a)
end
When compare *@time f(a,p) *I get:
0.026515 seconds (11 allocations: 304 bytes) 797.1301337918511
and *@time mapre(a, p):*
0.079932 seconds (9 allocations: 272 bytes) 797.1301337918511
Thanks in advance,
Martin