|
From: | Augustin Lefèvre |
Subject: | Re: Taking a mean of a fixed length number of points |
Date: | Sat, 30 Nov 2019 06:18:44 +0100 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 |
Dear Henk, You're asking a question about "the best possible way to encode a block average operator in octave". One possible way you could try to save time is to write "for loops" in an oct-file It would look like translating the following octave code into C++ : h=floor(n/k); y=zeros(h,m); for ik=1:h tstart = (ik-1)*k+1; tstop = ik*k; y(ik,:)=mean(x(tstart:tstop,:)); end But I can't guarantee it will be faster : it might depend on the ratio n/k. You will find as attachment an investigation into this matter, which I summarize in the post-scriptum. If that does not work, you might try encoding your block average operator into a sparse matrix. Best regards, Augustin Post-Scriptum : "it might depend on the ratio n/k" My bet would be : n/k high (high n, small k) => for loop is faster n/k low (small n, high k) => your code is faster Assuming this, there should be a correlation between n/k and the ratio of (CPU time 1)/(CPU time 2). To test this correlation write the for loop directly in octave, and if it holds, writing the oct file will actually make the "for loop" competitive. ... Ok, so I tried it (see attached script), and the correlation is weak, so either an oct-file will unconditionally save time or not. On 30/11/2019 02:50, Nicholas Jankowski wrote:
|
blockavg.m
Description: Text Data
[Prev in Thread] | Current Thread | [Next in Thread] |