[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-gsl] Array sorting queries

From: Andrew W. Steiner
Subject: Re: [Help-gsl] Array sorting queries
Date: Wed, 22 Oct 2008 09:19:04 -0400

Naively, one might be able to do this by setting the pointer to the
first element in the GSL vector as the last element in your array, and
then setting the stride to -1. However, it isn't quite that simple
because the stride is of type size_t. However, you can still rewrite
the sorting function in sort/sortvec_source.c and just "replace the
stride with -1" everywhere.

If you happen to be working in C++, then it's a bit easier. It's just
a matter of using:
and vector_sort() in .

Of course, a decreasing sort function wouldn't be a bad addition at all.

- Andrew Steiner
(c.f. O2scl at

On Wed, Oct 22, 2008 at 7:30 AM, Joseph Wakeling
<address@hidden> wrote:
> Hello,
> A few queries about the sorting functions in GSL.
> I have a few different arrays which I need to sort, depending on what
> they are, into either ascending or descending order.
> Later on in the program, I will need to perform index-sorts on the same
> arrays -- again, respectively in either ascending or descending order.
> What bothers me is that I don't see, from the GSL manual, how to do this
> effectively.  Sorting in ascending order is easy -- just use gsl_sort()
> and gsl_sort_index() -- but there's no hint in the manual how to sort
> arrays in _descending_ order.
> I could of course use gsl_sort_largest() over the whole array but that
> means having to assign a separate destination array and seems an
> expensive solution...
> Can anyone suggest a better solution?  (Apologies if I've missed
> something in the manual.)
> Thanks & best wishes,
>    -- Joe
> _______________________________________________
> Help-gsl mailing list
> address@hidden

reply via email to

[Prev in Thread] Current Thread [Next in Thread]