I am trying to multiply a small matrix by a slice of a vector (subvector), i.e., z[3:7] .= A * x[3:7]
, and it allocates memory for a copy of the slice. A view is a lightweight option, but it still needs some memory and takes time when I do it many times (10 million times or more). Is there any way to perform such an operation with limited memory usage? (like GEMM or SYMM for slices?)
Examples:
julia> z = zeros(7);
julia> x = ones(7);
julia> A=rand(5,5);
# naive case
julia> @time z[3:7] .= A * x[3:7];
0.000012 seconds (6 allocations: 384 bytes)
# view for x
julia> @time z[3:7] .= A * (@view x[3:7]);
0.000012 seconds (6 allocations: 304 bytes)
# view for z
julia> @time vz = @view z[3:7];
0.000002 seconds (1 allocation: 48 bytes)
julia> @time vz .= A * (@view x[3:7]);
0.000006 seconds (2 allocations: 176 bytes)
7 posts - 4 participants