From: Jan Simon on 7 Jan 2010 03:48 Dear Sudheer! Bump. My idea might have been lost in the discussion. Did you try this? http://www.mathworks.com/matlabcentral/newsreader/view_thread/269584#706578 Jan
From: Bruno Luong on 7 Jan 2010 07:37 "Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message <hi4745$erg$1(a)fred.mathworks.com>... > Dear Sudheer! > > Bump. My idea might have been lost in the discussion. > > Did you try this? > http://www.mathworks.com/matlabcentral/newsreader/view_thread/269584#706578 I did, it is a very good method speed wise, a little bit hard to read for someone who starts to use Matlab. The two sort commands save a bit of runtime compared to SORTROWS and calls for the fact that Matlab SORT is an *stable* sorting algorithm (prevail the initial order for draw elements) which not many people know how to exploit efficiently, so thank you for having showed us an example. Bruno
From: Jan Simon on 7 Jan 2010 08:17 Dear Bruno! > I did, Thank you for testing. I actually thought, this is a job for Sudheer with his original data. Perhaps, I don't want to be bold, but not too shy also: If you could stop doing Sudheer's work and start programming the STORTIND for me... ?! Perhaps if I'd try the modern tricks? PLZZZZZ.. Urgent & Emergency & Tomorrow is due & Grandfather is ill !!!.. I feel very junior today. > a little bit hard to read for someone who starts to use Matlab. Sorry! I should be improved optically. What about: [v, ind1] = sort(x(:, 2)); [v, ind2] = sort(x(ind1, 1)); ==> [theRightInstanceIsTaken, theRightInstanceIsTaken] = sort(x(:, 2)); [theRightInstanceIsTaken2, theRightInstanceIsTaken2] = ... sort(x(theRightInstanceIsTaken, 1)); Better. Not Matlab-poetry, but better. I feel very senior today. Sorry for taking your time - *I* had my funny coffee break, Jan
From: Bruno Luong on 9 Jan 2010 06:47 "Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message <hi2u1m$pg5$1(a)fred.mathworks.com>... > Dear Bruno! > > > Jan, how much do you estimate an inplace sorting (e.g., on large double array) would save time? > > It is clear, that the creation of the sort index is the demanding part of SORT, while the copy of the input in sorted order is secondary - usually. Unfortuantely one of the 2 DIMM ports of my computer is damaged and I have to live with 512MB RAM. But saving temporarily used memory is always useful, even on a 16 GB machine. Nevertheless, timing matters for 8MB array already: > > For the estimation of the speed gain: > x = rand(1e6, 1); > tic; y = sort(x); toc ==> 0.26 sec > tic; [y, s] = sort(x); toc ==> 0.40 sec > tic; y = x(s); toc ==> 0.14 sec > > So I assume I could save 35% computing time. Bad news, I implement an in-place 1D quicksort (the unstable version) and it get beaten by Matlab SORT with two outputs calling. My Matlab is 2010A prerelease; I compile the mex with MSVC 6. My guess is inplace sorting requires accessing in cascade the double data, and it slows the thing down. So I won't go any further. Better spend the effort on something else. Bruno
From: Bruno Luong on 9 Jan 2010 06:56
"Bruno Luong" <b.luong(a)fogale.findmycountry> wrote in message <hi9qbn$qmn$1(a)fred.mathworks.com>... > > Bad news, I implement an in-place 1D quicksort (the unstable version) and it get beaten by Matlab SORT with two outputs calling. My Matlab is 2010A prerelease; I compile the mex with MSVC 6. My guess is inplace sorting requires accessing in cascade the double data, and it slows the thing down. To avoid confusion, what I call "inplace sorting" is an implementation of the algorithm that works on the indexes without touching the original data. Bruno |