I have done some additional trials using these suggestions, again on the Raspberry PI.
The new code is:
function deinterleavesj(data::Vector{T}, num_channels::Integer, num_samples_per_channel::Integer) where T <: AbstractFloat
if length(data) == num_channels * num_samples_per_channel
datamatrix = transpose(reshape(a, num_channels, num_samples_per_channel));
else
error("Dimension mismatch")
end
return datamatrix
end
function deinterleaverg(data::Vector{T}, num_channels::Integer, num_samples_per_channel::Integer) where T <: AbstractFloat
if length(data) == num_channels * num_samples_per_channel
datamatrix = transpose(reshape(view(a, :), num_channels, num_samples_per_channel));
else
error("Dimension mismatch")
end
return datamatrix
end
giving the following performance benchmarks:
julia> @btime deinterleavesj(a, 4, length(a) ÷ 4 );
729.622 ns (6 allocations: 96 bytes)
julia> @btime deinterleaverg(a, 4, length(a) ÷ 4 );
1.252 μs (6 allocations: 120 bytes)
This gives close to a 100x speed improvement with minimal use of memory.
Thanks for the pointers!