On Sun, Feb 16, 2014 at 7:13 PM, Charles R Harris <charlesr.har...@gmail.com> wrote: > > > > On Sun, Feb 16, 2014 at 4:18 PM, <josef.p...@gmail.com> wrote: >> >> On Sun, Feb 16, 2014 at 6:15 PM, <josef.p...@gmail.com> wrote: >> > On Sun, Feb 16, 2014 at 5:50 PM, Eelco Hoogendoorn >> > <hoogendoorn.ee...@gmail.com> wrote: >> >> >> >> My guess; >> >> >> >> First of all, you are actually manipulating twice as much data as >> >> opposed to >> >> an inplace sort. >> >> >> >> Moreover, an inplace sort gains locality as it is being sorted, whereas >> >> the >> >> argsort is continuously making completely random memory accesses. >> >> >> >> >> >> -----Original Message----- >> >> From: josef.p...@gmail.com >> >> Sent: Sunday, February 16, 2014 11:43 PM >> >> To: Discussion of Numerical Python >> >> Subject: [Numpy-discussion] argsort speed >> >> >> >> currently using numpy 1.6.1 >> >> >> >> What's the fastest argsort for a 1d array with around 28 Million >> >> elements, roughly uniformly distributed, random order? >> >> >> >> Is there a reason that np.argsort is almost 3 times slower than >> >> np.sort? >> >> >> >> I'm doing semi-systematic timing for a stats(models) algorithm. >> > >> > I was using np.sort, inplace sort is only a little bit faster >> > >> > It looks like sorting first, and then argsorting is faster than argsort >> > alon >> > >> > pvals.sort() >> > sortind = np.argsort(pvals) >> >> Ok, that was useless, that won't be anything I want. >> > > I think locality is the most important thing. The argsort routines used to > move both the indexes and the array to argsort, the new ones only move the > indexes. It is a tradeoff, twice as many moves vs locality. It's probably > possible to invent an algorithm that mixes the two.
If that's the way it is, then that's the way it is. I just never realized that argsort can take so long, since I usually use only smaller arrays. I was surprised that argsort took almost 10 out of around 12 seconds in my function, and this after I cleaned up my code and removed duplicate and avoidable argsorts. Josef > > <snip> > > Chuck > > _______________________________________________ > NumPy-Discussion mailing list > NumPy-Discussion@scipy.org > http://mail.scipy.org/mailman/listinfo/numpy-discussion > _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion