Adding tests to QRNG and switching the RNG tests to Test::Class
[Math-GSL.git] / Vector.i
blobc14754dd3fd3506ac894e3ca991c831f87edf6fd
1 %module Vector
3 %{
4 #include "/usr/include/stdio.h"
5 #include "/usr/local/include/gsl/gsl_vector.h"
6 #include "/usr/local/include/gsl/gsl_vector_char.h"
7 #include "/usr/local/include/gsl/gsl_vector_complex.h"
8 #include "/usr/local/include/gsl/gsl_vector_complex_double.h"
9 #include "/usr/local/include/gsl/gsl_vector_double.h"
10 #include "/usr/local/include/gsl/gsl_vector_float.h"
11 #include "/usr/local/include/gsl/gsl_vector_int.h"
13 %include "/usr/local/include/gsl/gsl_vector.h"
14 %include "/usr/local/include/gsl/gsl_vector_char.h"
15 %include "/usr/local/include/gsl/gsl_vector_complex.h"
16 %include "/usr/local/include/gsl/gsl_vector_complex_double.h"
17 %include "/usr/local/include/gsl/gsl_vector_double.h"
18 %include "/usr/local/include/gsl/gsl_vector_int.h"
21 %include "typemaps.i"
23 %apply int *OUTPUT { size_t *imin, size_t *imax };
24 extern void gsl_vector_minmax_index (const gsl_vector * v, size_t *imax, size_t *imin);
26 %apply double *INPUT { double * base };
27 extern gsl_vector_view gsl_vector_view_array (double * base, size_t n);
29 /*%apply double *OUTPUT { double *min_out, double *max_out };*/
30 extern void gsl_vector_minmax (const gsl_vector *INPUT, double *OUTPUT, double *OUTPUT);
32 FILE * fopen(char *, char *);
33 int fclose(FILE *);
35 %perlcode %{
38 @EXPORT_OK = qw/fopen fclose
39 gsl_vector_alloc gsl_vector_calloc gsl_vector_alloc_from_b gsl_vector_alloc_from_v
40 gsl_vector_free gsl_vector_view_array gsl_vector_view_array_w
41 gsl_vector_const_view_a gsl_vector_subvector gsl_vector_subvector_wi gsl_vector_subvector_with_stride
42 gsl_vector_const_subvec gsl_vector_const_subvec gsl_vector_get gsl_vector_set
43 gsl_vector_ptr gsl_vector_const_ptr gsl_vector_set_zero gsl_vector_set_all
44 gsl_vector_set_basis gsl_vector_fread gsl_vector_fwrite gsl_vector_fscanf
45 gsl_vector_fprintf gsl_vector_memcpy gsl_vector_reverse gsl_vector_swap
46 gsl_vector_swap_elements gsl_vector_max gsl_vector_min gsl_vector_minmax
47 gsl_vector_max_index gsl_vector_min_index gsl_vector_minmax_index
48 gsl_vector_add gsl_vector_sub gsl_vector_mul gsl_vector_div
49 gsl_vector_scale gsl_vector_add_constant gsl_vector_isnull
50 gsl_vector_ispos gsl_vector_isneg gsl_vector_isnonneg
52 %EXPORT_TAGS = ( all => [ @EXPORT_OK ] );
54 sub new {
55 my ($class, $values) = @_;
56 my $length = $#$values;
57 my $vector;
58 die __PACKAGE__.'::new($x) - $x must be an int or nonempty array reference'
59 if( !(defined $values) || ($length == -1));
61 if ( ref $values eq 'ARRAY' ){
62 $vector = gsl_vector_alloc($length+1);
63 map { gsl_vector_set($vector, $_, $values->[$_] ) } (0 .. $length);
64 } elsif ( int $values == $values && $values > 0) {
65 $vector = gsl_vector_alloc($length);
66 } else {
67 die __PACKAGE__.'::new($x) - $x must be an int or array reference';
69 my $self = {};
70 $self->{_vector} = $vector;
71 bless $self, $class;
74 sub get {
75 my ($self, $indices) = @_;
76 return map { gsl_vector_get($self->{_vector}, $_ ) } @$indices ;
79 sub set {
80 my ($self, $indices, $values) = @_;
81 die (__PACKAGE__.'::set($indices, $values) - $indices and $values must be array references of the same length')
82 unless ( ref $indices eq 'ARRAY' && ref $values eq 'ARRAY' && $#$indices == $#$values );
83 eval {
84 map { gsl_vector_set($self->{_vector}, $indices->[$_], $values->[$_] ) } (0..$#$indices);
85 };
86 return;
89 __END__
91 =head1 NAME
93 Math::GSL::Vector
94 Functions concerning Vectors.
96 =head1 SYPNOPSIS
98 use Math::GSL::Vector qw/:all/;
100 =head1 DESCRIPTION
102 Here is a list of all the functions included in this module :
104 gsl_vector_alloc($x) - create a vector of size $x
106 gsl_vector_calloc($x) - create a vector of size $x and initializes all the elements of the vector to zero
108 gsl_vector_alloc_from_b
110 gsl_vector_alloc_from_v
112 gsl_vector_free($v) - free a previously allocated vector $v
114 gsl_vector_view_array
116 gsl_vector_view_array_w
118 gsl_vector_const_view_a
120 gsl_vector_subvector - return a vector_view type which contains a subvector of $v, with a size of $size, starting from the $offset position
122 gsl_vector_subvector_wi
124 gsl_vector_subvector_with_stride($v, $offset, $stride, $size) - return a vector_view type which contains a subvector of $v, with a size of $size, starting from the $offset position and with a $stride step between each element of $v
126 gsl_vector_const_subvec
128 gsl_vector_get($v, $i) - return the $i-th element of a vector $v
130 gsl_vector_set($v, $i, $x) - return the vector $v with his $i-th element set to $x
132 gsl_vector_ptr
134 gsl_vector_const_ptr
136 gsl_vector_set_zero($v) - set all the elements of $v to 0
138 gsl_vector_set_all($v, $x) - set all the elements of $v to $x
140 gsl_vector_set_basis($v, $i) - set all the elements of $v to 0 except for the $i-th element which is set to 1 and return 0 if the operation succeded, 1 otherwise.
142 gsl_vector_fread($file, $v)
144 gsl_vector_fwrite
146 gsl_vector_fscanf
148 gsl_vector_fprintf
150 gsl_vector_memcpy
152 gsl_vector_reverse($v) - reverse the order of the elements of the vector $v and return 0 if the opertaion succeded, 1 otherwise
154 gsl_vector_swap($v, $v2) - swap the values of the vectors $v and $v2 and return 0 if the opertaion succeded, 1 otherwise
156 gsl_vector_swap_elements($v, $i, $j) - permute the elements at position $i and $j in the vector $v and return 0 if the operation succeded, 1 otherwise.
158 gsl_vector_max($v) - return the maximum value in the vector $v
160 gsl_vector_min($v) - return the minimum value in the vector $v
162 gsl_vector_minmax
164 gsl_vector_max_index($v) - return the position of the maximum value in the vector $v
166 gsl_vector_min_index - return the position of the minimum value in the vector $v
168 gsl_vector_minmax_index
170 gsl_vector_add($v, $v2) - add the elements of $v2 to the elements of $v, the two vectors must have the same lenght and return 0 if the operation succeded, 1 otherwise.
172 gsl_vector_sub($v, $v2) - substract the elements of $v2 from the elements of $v, the two vectors must have the same lenght and return 0 if the operation succeded, 1 otherwise.
174 gsl_vector_mul($v, $v2) - multiply the elements of $v by the elements of $v2, the two vectors must have the same lenght and return 0 if the operation succeded, 1 otherwise.
176 gsl_vector_div($v, $v2) - divides the elements of $v by the elements of $v2, the two vectors must have the same lenght and return 0 if the operation succeded, 1 otherwise.
178 gsl_vector_scale($v, $x) - multiplty the elements of the vector $v by a constant $x and return 0 if the operation succeded, 1 otherwise.
180 gsl_vector_add_constant($v, $x) - add a constant $x to the elements of the vector $v and return 0 if the operation succeded, 1 otherwise.
182 gsl_vector_isnull($v) - verify if all the elements of the vector $v are null, return 0 if it's the case, 1 otherwise.
184 gsl_vector_ispos($v) - verify if all the elements of the vector $v are positive, return 0 if it's the case, 1 otherwise.
186 gsl_vector_isneg($v) - verify if all the elements of the vector $v are negative, return 0 if it's the case, 1 otherwise.
188 gsl_vector_isnonneg($v) - verify if all the elements the vector $v are not negative, return 0 if it's the case, 1 otherwise.
191 You have to add the functions you want to use inside the qw /put_funtion_here / with spaces between each function. You can also write use Math::GSL::Complex qw/:all/ to use all avaible functions of the module.
194 Precision on the vector_view type : every modification you'll make on a vector_view will also modify the original vector.
195 For example, the following code will zero the even elements of the vector v of length n, while leaving the odd elements untouched :
197 $v_even= gsl_vector_subvector_with_stride ($v, 0, 2, $size/2);
198 gsl_vector_set_zero ($v_even->{vector});
201 For more informations on the functions, we refer you to the GSL offcial documentation: http://www.gnu.org/software/gsl/manual/html_node/
202 Tip : search on google: site:http://www.gnu.org/software/gsl/manual/html_node/ name_of_the_function_you_want
204 =head1 EXAMPLES
207 =head1 AUTHOR
209 Jonathan Leto <jonathan@leto.net> and Thierry Moisan <thierry.moisan@gmail.com>
211 =head1 COPYRIGHT AND LICENSE
213 Copyright (C) 2008 Jonathan Leto and Thierry Moisan
215 This program is free software; you can redistribute it and/or modify it
216 under the same terms as Perl itself.
218 =cut