Fixed sort tests with a typemap
[Math-GSL.git] / Sort.i
blob2f27a6c537862b80d8ca80ffad15b4c53669a188
1 %module "Math::GSL::Sort"
2 /* Danger Will Robinson! */
3 %include "typemaps.i"
4 %include "gsl_typemaps.i"
6 %typemap(argout) (double * data, const size_t stride, const size_t n) {
7 int i=0;
8 AV* tempav = newAV();
10 while( i < $3 ) {
11 av_push(tempav, newSVnv((double) $1[i]));
12 i++;
15 $result = sv_2mortal( newRV_noinc( (SV*) tempav) );
16 //Perl_sv_dump($result);
17 argvi++;
19 %typemap(argout) (double * dest, const size_t k, const gsl_vector * v) {
20 int i=0;
21 AV* tempav = newAV();
23 while( i < $2 ) {
24 av_push(tempav, newSVnv((double) $1[i]));
25 i++;
28 $result = sv_2mortal( newRV_noinc( (SV*) tempav) );
29 argvi++;
32 %typemap(argout) (double * dest, const size_t k, const double * src, const size_t stride, const size_t n) {
33 int i=0;
34 AV* tempav = newAV();
35 while( i < $2 ) {
36 av_push(tempav, newSVnv((double) $1[i]));
37 i++;
40 $result = sv_2mortal( newRV_noinc( (SV*) tempav) );
41 argvi++;
44 %apply double * { double *data, double *dest };
47 #include "gsl/gsl_nan.h"
48 #include "gsl/gsl_sort.h"
49 #include "gsl/gsl_sort_double.h"
50 #include "gsl/gsl_sort_int.h"
51 #include "gsl/gsl_sort_vector.h"
52 #include "gsl/gsl_sort_vector_double.h"
53 #include "gsl/gsl_sort_vector_int.h"
54 #include "gsl/gsl_permutation.h"
56 %include "gsl/gsl_nan.h"
57 %include "gsl/gsl_sort.h"
58 %include "gsl/gsl_sort_double.h"
59 %include "gsl/gsl_sort_int.h"
60 %include "gsl/gsl_sort_vector.h"
61 %include "gsl/gsl_sort_vector_double.h"
62 %include "gsl/gsl_sort_vector_int.h"
63 %include "gsl/gsl_permutation.h"
66 %perlcode %{
67 @EXPORT_plain = qw/
68 gsl_sort gsl_sort_index
69 gsl_sort_smallest gsl_sort_smallest_index
70 gsl_sort_largest gsl_sort_largest_index
72 @EXPORT_vector= qw/
73 gsl_sort_vector gsl_sort_vector_index
74 gsl_sort_vector_smallest gsl_sort_vector_smallest_index
75 gsl_sort_vector_largest gsl_sort_vector_largest_index
77 @EXPORT_OK = ( @EXPORT_plain, @EXPORT_vector );
78 %EXPORT_TAGS = (
79 all => [ @EXPORT_OK ],
80 plain => [ @EXPORT_plain ],
81 vector => [ @EXPORT_vector ],
83 __END__
85 =head1 NAME
87 Math::GSL::Sort - Functions for sorting data
89 =head1 SYNOPSIS
91 use Math::GSL::Sort qw/:all/;
92 my $x = [ 2**15, 1.67, 20e5,
93 -17, 6900, 1/3 , 42e-10 ];
94 my $sorted = gsl_sort($x, 1, $#$x+1 );
97 =head1 DESCRIPTION
99 Here is a list of all the functions included in this module :
101 =over
103 =item * gsl_sort_vector($v) - This function sorts the elements of the vector $v into ascending numerical order.
105 =item * gsl_sort_vector_index($p, $v) - This function indirectly sorts the elements of the vector $v into ascending order, storing the resulting permutation in $p. The elements of $p give 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 $p gives the index of the least element in $v, and the last element of $p gives the index of the greatest element in $v. The vector $v is not changed.
107 =item * gsl_sort_vector_smallest
109 =item * gsl_sort_vector_smallest_index
111 =item * gsl_sort_vector_largest
113 =item * gsl_sort_vector_largest_index
115 =item * gsl_sort($data, $stride, $n) - This function returns an array reference to the sorted $n elements of the array $data with stride $stride into ascending numerical order.
117 =item * gsl_sort_index
119 =item * gsl_sort_smallest
121 =item * gsl_sort_smallest_index
123 =item * gsl_sort_largest
125 =item * gsl_sort_largest_index
127 =back
129 You have to add the functions you want to use inside the qw /put_funtion_here /.
130 You can also write use Math::GSL::Sort qw/:all/ to use all avaible functions of the module.
131 Other tags are also avaible, here is a complete list of all tags for this module :
133 =over
135 =item all
137 =item plain
139 =item vector
141 =back
143 For more informations on the functions, we refer you to the GSL offcial documentation:
144 L<http://www.gnu.org/software/gsl/manual/html_node/>
146 Tip : search on google: site:http://www.gnu.org/software/gsl/manual/html_node/ name_of_the_function_you_want
148 =head1 AUTHORS
150 Jonathan Leto <jonathan@leto.net> and Thierry Moisan <thierry.moisan@gmail.com>
152 =head1 COPYRIGHT AND LICENSE
154 Copyright (C) 2008 Jonathan Leto and Thierry Moisan
156 This program is free software; you can redistribute it and/or modify it
157 under the same terms as Perl itself.
159 =cut