Math::GSL::Permutation(3pm) | User Contributed Perl Documentation | Math::GSL::Permutation(3pm) |
Math::GSL::Permutation - functions for creating and manipulating permutations
use Math::GSL::Permutation qw/:all/; my $permutation = Math::GSL::Permutation->new(30); # allocate and initialize a permutation of size 30 my $length = $permutation->length; # returns the length of the permutation object, here it is 30 gsl_permutation_swap($permutation->raw, 2,7); # the raw method is made to use the underlying permutation structure of the permutation object my $value = $permutation->get(2); # returns the third value (starting from 0) of the permutation my @values = $permutation->as_list; # returns all the values of the permutation my @set = $permutation->get([0,1,2,3]); # returns the four first values of the permutation
Here is a list of all the functions included in this module :
You have to add the functions you want to use inside the qw/put_function_here/ with spaces between each function. You can also write use Math::GSL::CDF qw/:all/ to use all available functions of the module. Other tags are also available, here is a complete list of all tags for this module. For more information on the functions, we refer you to the GSL official documentation: L<http://www.gnu.org/software/gsl/manual/html_node/>
use Math::GSL::Permutation qw/:all/; $p->{permutation} = gsl_permutation_calloc(5); print "The permutation contains ["; map { print gsl_permutation_get($p->{permutation}, $_) . ", " } (0..3); print gsl_permutation_get($p->{permutation}, 4); print "] \n"; print "We'll then swap the first and last elements of the permutation...\n"; gsl_permutation_swap($p->{permutation}, 0, 4); print "The permutation now contains ["; map { print gsl_permutation_get($p->{permutation},$_) . ", " } (0..3); print gsl_permutation_get($p->{permutation}, 4); print "] \n"; use Math::GSL::Permutation qw/:all/; use Math::GSL::Vector qw/:all/; my $p->{permutation} = gsl_permutation_calloc(6); gsl_permutation_init($p->{permutation}); gsl_permutation_swap($p->{permutation}, 0, 1); print "The permutation has his first and second elements swapped : ["; map { print gsl_permutation_get($p->{permutation}, $_) . "," } (0..4); print gsl_permutation_get($p->{permutation}, 5) . "] \n"; my $vec->{vector} = gsl_vector_alloc(6); map { gsl_vector_set($vec->{vector}, $_, $_) } (0..5); print "We will now apply the permutation to this vector : ["; map { print gsl_vector_get($vec->{vector}, $_) . "," } (0..4); print gsl_vector_get($vec->{vector}, 5) . "] \n"; gsl_permute_vector($p->{permutation}, $vec->{vector}); print "The vector is now : ["; map { print gsl_vector_get($vec->{vector}, $_) . "," } (0..4); print gsl_vector_get($vec->{vector}, 5) . "] \n";
Jonathan "Duke" Leto <jonathan@leto.net> and Thierry Moisan <thierry.moisan@gmail.com>
Copyright (C) 2008-2021 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.
2022-10-20 | perl v5.36.0 |