Fixed hardcoded include file location of /usr/local/include, now ExtUtils::PkgConfig...
[Math-GSL.git] / Permutation.i
blobe58db23e02953cda84a2871503a179295fb5f584
1 %module Permutation
3 FILE * fopen(char *, char *);
4 int fclose(FILE *);
6 %{
7 #include "gsl/gsl_permute.h"
8 #include "gsl/gsl_permute_double.h"
9 #include "gsl/gsl_permute_int.h"
10 #include "gsl/gsl_permute_vector.h"
11 #include "gsl/gsl_permute_vector_double.h"
12 #include "gsl/gsl_permute_vector_int.h"
13 #include "gsl/gsl_permutation.h"
15 %include "gsl/gsl_permute.h"
16 %include "gsl/gsl_permute_double.h"
17 %include "gsl/gsl_permute_int.h"
18 %include "gsl/gsl_permute_vector.h"
19 %include "gsl/gsl_permute_vector_double.h"
20 %include "gsl/gsl_permute_vector_int.h"
21 %include "gsl/gsl_permutation.h"
23 %perlcode %{
24 @EXPORT_OK = qw/fopen fclose
25 gsl_permutation_alloc
26 gsl_permutation_calloc
27 gsl_permutation_init
28 gsl_permutation_free
29 gsl_permutation_memcpy
30 gsl_permutation_fread
31 gsl_permutation_fwrite
32 gsl_permutation_fscanf
33 gsl_permutation_fprintf
34 gsl_permutation_size
35 gsl_permutation_data
36 gsl_permutation_get
37 gsl_permutation_swap
38 gsl_permutation_valid
39 gsl_permutation_reverse
40 gsl_permutation_inverse
41 gsl_permutation_next
42 gsl_permutation_prev
43 gsl_permutation_mul
44 gsl_permutation_linear_to_canonical
45 gsl_permutation_canonical_to_linear
46 gsl_permutation_inversions
47 gsl_permutation_linear_cycles
48 gsl_permutation_canonical_cycles
49 gsl_permute
50 gsl_permute_inverse
51 gsl_permute_int
52 gsl_permute_int_inverse
53 gsl_permute_vector
54 gsl_permute_vector_inverse
55 gsl_permute_vector_int
56 gsl_permute_vector_int_inverse
58 %EXPORT_TAGS = ( all => [ @EXPORT_OK ] );
60 ### wrapper interface ###
61 sub new {
62 my ($class, $value) = @_;
63 my $this = {};
64 $this->{_permutation} = gsl_permutation_alloc($value);
65 bless $this, $class;
68 __END__
70 =head1 NAME
72 Math::GSL::Permutation - functions for creating and manipulating permutations
74 =head1 SYPNOPSIS
76 use Math::GSL::Permutation qw/:all/;
78 =head1 DESCRIPTION
80 Here is a list of all the functions included in this module :
82 =over
84 =item gsl_permutation_alloc($n) - return a newly allocated permutation of size $n
86 =item gsl_permutation_calloc($n) - return a newly allocated permutation of size $n which is initialized to the identity
88 =item gsl_permutation_init($p) - initialize the permutation $p to the identity i.e. (0,1,2, ..., n-1)
90 =item gsl_permutation_free($p) - free all the memory use by the permutaion $p
92 =item gsl_permutation_memcpy($dest, $src) - copy the permutation $src into the permutation $dest, the two permutations must have the same lenght and return 0 if the operation suceeded, 1 otherwise
94 =item gsl_permutation_fread($stream, $p) - This function reads into the permutation $p from the open stream $stream (opened with the fopen function) in binary format. The permutation $p must be preallocated with the correct length since the function uses the size of $p to determine how many bytes to read. The function returns 1 if there was a problem reading from the file. The data is assumed to have been written in the native binary format on the same architecture.
96 =item gsl_permutation_fwrite($stream, $p) - This function writes the elements of the permutation $p to the stream $stream (opened with the fopen function) in binary format. The function returns 1 if there was a problem writing to the file. Since the data is written in the native binary format it may not be portable between different architectures.
98 =item gsl_permutation_fscanf($stream, $p) - This function reads formatted data from the stream $stream into the permutation $p. The permutation $p must be preallocated with the correct length since the function uses the size of $p to determine how many numbers to read. The function returns 1 if there was a problem reading from the file.
100 =item gsl_permutation_fprintf($stream, $p, $format) - This function writes the elements of the permutation $p line-by-line to the stream $stream (opened with the fopen function) using the format specifier $format, which should be suitable. "%zu\n" is a suitable format. The function returns 1 if there was a problem writing to the file.
102 =item gsl_permutation_size($p) - return the size of the permutation $p
104 =item gsl_permutation_data
106 =item gsl_permutation_get($p, $i) - return the $i-th element of the permutation $p, return 0 if $i is outside the range of 0 to n-1
108 =item gsl_permutation_swap($p, $i, $j) - exchange the $i-th position and the $j-th position of the permutation $p and return 0 if the operation suceeded, 1 otherwise
110 =item gsl_permutation_valid($p) - return 0 if the permutation $p is valid (if the n elements contain each of the numbers 0 to n-1 once and only once), 1 otherwise
112 =item gsl_permutation_reverse($p) - reverse the elements of the permutation $p
114 =item gsl_permutation_inverse($inv, $p) - compute the inverse of the permutation $p, storing it in $inv and return 0 if the operation succeeded, 1 otherwise
116 =item gsl_permutation_next($p) - advance the permutation $p to the next permutation in lexicographic order and return 0 if the operation succeeded, 1 otherwise
118 =item gsl_permutation_prev($p) - step backward from the permutation $p to the previous permutation in lexicographic order and return 0 if the operation suceeded, 1 otherwise
120 =item gsl_permutation_mul($p, $pa, $pb) - combine the two permutation $pa and $pb into a single permutation $p and return 0 if the operation suceeded, 1 otherwise
122 =item gsl_permutation_linear_to_canonical($q, $p) - compute the canonical form the permutation $p and store it in $q and return 0 if the operation suceeded, 1 otherwise
124 =item gsl_permutation_canonical_to_linear($p, $q) - convert a canonical permutation $q back into linear form and store it in $p and return 0 if the operation suceeded, 1 otherwise
126 =item gsl_permutation_inversions($p) - return the number of inversions in the permutation $p
128 =item gsl_permutation_linear_cycles($p) - return the number of cycles in the permutation $p, given a linear form
130 =item gsl_permute_vector_int_inversegsl_permutation_canonical_cycles($p) - return the number of cycles in the permutation $p, given a canonical form
132 =item gsl_permute
134 =item gsl_permute_inverse
136 =item gsl_permute_int
138 =item gsl_permute_int_inverse
140 =item gsl_permute_vector
142 =item gsl_permute_vector_inverse
144 =item gsl_permute_vector_int
146 =back
148 You have to add the functions you want to use inside the qw/put_funtion_here/ with spaces between each function.
149 You can also write use Math::GSL::CDF qw/:all/ to use all avaible functions of the module.
150 Other tags are also avaible, here is a complete list of all tags for this module.
151 For more informations on the functions, we refer you to the GSL offcial documentation: http://www.gnu.org/software/gsl/manual/html_node/
152 Tip : search on google: site:http://www.gnu.org/software/gsl/manual/html_node/ name_of_the_function_you_want
154 =head1 EXAMPLES
156 use Math::GSL::Permutation qw/:all/;
157 $p->{permutation} = gsl_permutation_calloc(5);
158 print "The permutation contains [";
159 map { print gsl_permutation_get($p->{permutation}, $_) . ", " } (0..3);
160 print gsl_permutation_get($p->{permutation}, 4);
161 print "] \n";
162 print "We'll then swap the first and last elements of the permutation...\n";
163 gsl_permutation_swap($p->{permutation}, 0, 4);
164 print "The permutation now contains [";
165 map { print gsl_permutation_get($p->{permutation},$_) . ", " } (0..3);
166 print gsl_permutation_get($p->{permutation}, 4);
167 print "] \n";
170 use Math::GSL::Permutation qw/:all/;
171 use Math::GSL::Vector qw/:all/;
172 my $p->{permutation} = gsl_permutation_calloc(6);
173 gsl_permutation_init($p->{permutation});
174 gsl_permutation_swap($p->{permutation}, 0, 1);
175 print "The permutation has his first and second elements swapped : [";
176 map { print gsl_permutation_get($p->{permutation}, $_) . "," } (0..4);
177 print gsl_permutation_get($p->{permutation}, 5) . "] \n";
178 my $vec->{vector} = gsl_vector_alloc(6);
179 map { gsl_vector_set($vec->{vector}, $_, $_) } (0..5);
181 print "We will now apply the permutation to this vector : [";
182 map { print gsl_vector_get($vec->{vector}, $_) . "," } (0..4);
183 print gsl_vector_get($vec->{vector}, 5) . "] \n";
184 gsl_permute_vector($p->{permutation}, $vec->{vector});
185 print "The vector is now : [";
186 map { print gsl_vector_get($vec->{vector}, $_) . "," } (0..4);
187 print gsl_vector_get($vec->{vector}, 5) . "] \n";
190 =head1 AUTHOR
192 Jonathan Leto <jonathan@leto.net> and Thierry Moisan <thierry.moisan@gmail.com>
194 =head1 COPYRIGHT AND LICENSE
196 Copyright (C) 2008 Jonathan Leto and Thierry Moisan
198 This program is free software; you can redistribute it and/or modify it
199 under the same terms as Perl itself.
201 =cut