[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #45497] missing function: repelem
From: |
Nick Jankowski |
Subject: |
[Octave-bug-tracker] [bug #45497] missing function: repelem |
Date: |
Wed, 08 Jul 2015 21:09:38 +0000 |
User-agent: |
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0 |
Follow-up Comment #2, bug #45497 (project octave):
Looks good. A couple comments. I noticed you're using repmat even for the
simpler cases. Just went through a run length decoding exercise and what I
first found was discussion about using indexing tricks to avoid calling
repmat, can make a big performance improvement.
E.g., the following two lines produce the same output:
>> v = 2;
>> element = [1 2 3 4 5 6];
>> repmat (element, 2, 1)(:)'
ans =
1 1 2 2 3 3 4 4 5 5 6 6
>> element(ones(2,1),:)(:)'
ans =
1 1 2 2 3 3 4 4 5 5 6 6
Additionally, doing a quick and (very) dirty timing test:
>> tic;for ii = 1:10000,repmat (element, v, 1)(:)';,endfor;toc
Elapsed time is 3.182 seconds.
>> tic;for ii = 1:10000,element(ones(v,1),:)(:)';,endfor;toc
Elapsed time is 0.207 seconds.
For v being a vector, I came upon the following :
Matlab array manipulation tips and tricks
http://home.online.no/~pjacklam/matlab/doc/index.html
In chapter 15.5.2 it had a section on run length encoding & decoding with 3
different scripts. while the author says the 1st one should be the slowest, my
timing of the three with octave (it was a touch more involved that the timing
test above) showed it to be the fastest. with your variable naming the code
would be (haven't checked for accuracy with your code):
ii = cumsum(v);
jj = zeros(1, ii(end));
jj(ii(1:end-1)+1) = 1;
jj(1) = 1;
ret = element(cumsum(jj));
I've been toying with using the (ones()) indexing with multidimensional
arrays, and it works well. If I get a chance I'll look at what you have and
what repelem needs to cover.
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?45497>
_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/
- [Octave-bug-tracker] [bug #45497] missing function: repelem, Nick Jankowski, 2015/07/08
- [Octave-bug-tracker] [bug #45497] missing function: repelem, Markus Bergholz, 2015/07/08
- [Octave-bug-tracker] [bug #45497] missing function: repelem,
Nick Jankowski <=
- [Octave-bug-tracker] [bug #45497] missing function: repelem, Markus Bergholz, 2015/07/09
- [Octave-bug-tracker] [bug #45497] missing function: repelem, Nick Jankowski, 2015/07/09
- [Octave-bug-tracker] [bug #45497] missing function: repelem, Nick Jankowski, 2015/07/09
- [Octave-bug-tracker] [bug #45497] missing function: repelem, Carnë Draug, 2015/07/09
- [Octave-bug-tracker] [bug #45497] missing function: repelem, Nick Jankowski, 2015/07/09
- [Octave-bug-tracker] [bug #45497] missing function: repelem, Markus Bergholz, 2015/07/09
- [Octave-bug-tracker] [bug #45497] missing function: repelem, Markus Bergholz, 2015/07/11
- [Octave-bug-tracker] [bug #45497] missing function: repelem, Markus Bergholz, 2015/07/11
- [Octave-bug-tracker] [bug #45497] missing function: repelem, Nick Jankowski, 2015/07/21
- [Octave-bug-tracker] [bug #45497] missing function: repelem, Nick Jankowski, 2015/07/26