-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Closed
Labels
Description
Consider the following piece of code:
n=10^6;
X = randn(1,n);
V(x) = 0.5 * dot(x,x);
f(V, X) = [ V((@view X[:,n])) for n = 1:size(X,2) ]
Timing on this reveals:
julia> @time mapslices(V, X, 1);
1.177690 seconds (12.00 M allocations: 267.024 MiB, 6.91% gc time)
julia> @time f(V,X);
0.047745 seconds (1.00 M allocations: 53.406 MiB, 5.58% gc time)
which is substantially different.
Note that in this simple example, my data could be a column vector; however, this is a surrogate for problems where I have time series data and X is d x n with 1< d << n.
innerlee, baggepinnen, lassepe, AboAmmar, LilithHafner and 1 more