NAME
Math::GSL::Sort - Functions for sorting data
SYNOPSIS
use Math::GSL::Sort qw/:all/;my $x = [ 2**15, 1.67, 20e5, -17, 6900, 1/3 , 42e-10 ];my $sorted = gsl_sort($x, 1, $#$x+1 );my $numbers = [ map { rand(100) } (1..100) ];my ($status, $smallest10) = gsl_sort_smallest($array, 10, $x, 1, $#$x+1);
DESCRIPTION
- •
-
gsl_sort_vector($v)
This function sorts the elements of the vector
$vinto ascending numerical order.
- •
-
gsl_sort_vector_index($p,
$v)This function indirectly sorts the elements of the vector
$vinto ascending order, storing the resulting permutation in$p. The elements of$pgive the index of the vector element which would have been stored in that position if the vector had been sorted in place. The first element of$pgives the index of the least element in$v, and the last element of$pgives the index of the greatest element in$v. The vector$vis not changed.
- •
-
gsl_sort_vector_smallest($array,
$k,$vector)This function outputs 0 if the operation succeeded, 1 otherwise and then the
$ksmallest elements of the vector$v.$kmust be less than or equal to the length of the vector$v.
- •
-
gsl_sort_vector_smallest_index($p,
$k,$v)This function outputs 0 if the operation succeeded, 1 otherwise and then the indices of the
$ksmallest elements of the vector$v.$pmust be a prealocated array reference. This should be removed in further versions.$kmust be less than or equal to the length of the vector$v.
- •
-
gsl_sort_vector_largest($array,
$k,$vector)This function outputs 0 if the operation succeeded, 1 otherwise and then the
$klargest elements of the vector$v.$kmust be less than or equal to the length of the vector$v.
- •
-
gsl_sort_vector_largest_index($p,
$k,$v)This function outputs 0 if the operation succeeded, 1 otherwise and then the indices of the
$klargest elements of the vector$v.$pmust be a prealocated array reference. This should be removed in further versions.$kmust be less than or equal to the length of the vector$v.
- •
-
gsl_sort($data,
$stride,$n)This function returns an array reference to the sorted
$nelements of the array$datawith stride$strideinto ascending numerical order.
- •
-
gsl_sort_index($p,
$data,$stride,$n)This function indirectly sorts the
$nelements of the array$datawith stride$strideinto ascending order, outputting the permutation in the foram of an array.$pmust be a prealocated array reference. This should be removed in further versions. The array$datais not changed.
- •
-
gsl_sort_smallest($array,
$k,$data,$stride,$n)This function outputs 0 if the operation succeeded, 1 otherwise and then the
$ksmallest elements of the array$data, of size$nand stride$stride, in ascending numerical. The size$kof the subset must be less than or equal to$n. The data$srcis not modified by this operation.$arraymust be a prealocated array reference. This should be removed in further versions.
- •
-
gsl_sort_smallest_index($p,
$k,$src,$stride,$n)This function outputs 0 if the operation succeeded, 1 otherwise and then the indices of the
$ksmallest elements of the array$src, of size$nand stride$stride. The indices are chosen so that the corresponding data is in ascending numerical order.$kmust be less than or equal to$n. The data$srcis not modified by this operation.$pmust be a prealocated array reference. This should be removed in further versions.
- •
-
gsl_sort_largest($array,
$k,$data,$stride,$n)This function outputs 0 if the operation succeeded, 1 otherwise and then the
$klargest elements of the array$data, of size$nand stride$stride, in ascending numerical. The size$kof the subset must be less than or equal to$n. The data$srcis not modified by this operation.$arraymust be a prealocated array reference. This should be removed in further versions.
- •
-
gsl_sort_largest_index($p,
$k,$src,$stride,$n)This function outputs 0 if the operation succeeded, 1 otherwise and then the indices of the
$klargest elements of the array$src, of size$nand stride$stride. The indices are chosen so that the corresponding data is in ascending numerical order.$kmust be less than or equal to$n. The data$srcis not modified by this operation.$pmust be a prealocated array reference. This should be removed in further versions.
Here is a complete list of all tags for this module :
- all
- plain
- vector
For more information on the functions, we refer you to the GSL official documentation: <http://www.gnu.org/software/gsl/manual/html_node/>
PERFORMANCE
In the source code of Math::GSL, the file "examples/benchmark/sort" compares the performance of gsl_sort() to Perl's builtin sort() function. Its first argument is the number of iterations and the second is the size of the array of numbers to sort. For example, to see a benchmark of 1000 iterations for arrays of size 50000 you would type
./examples/benchmark/sort 1000 50000
Initial benchmarks indicate just slightly above a 2x performance increase over sort() for arrays of between 5000 and 50000 elements. This may mostly be due to the fact that gsl_sort() takes and returns a reference while sort() takes and returns a plain list.
AUTHORS
Jonathan "Duke" Leto <[email protected]> and Thierry Moisan <[email protected]>
COPYRIGHT AND LICENSE
Copyright (C) 2008-2024 Jonathan "Duke" Leto and Thierry Moisan
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.