Update MANIFEST and MANIFEST.SKIP to make "./Build distcheck" useful again.
[Math-GSL.git] / Vector.i
blobdfd4ce4a5cedeb8714a649a47d8c3aece9917a70
1 %module Vector
3 %include "typemaps.i"
5 %apply int *OUTPUT { size_t *imin, size_t *imax };
7 %apply double *OUTPUT { double * min_out, double * max_out };
9 %typemap(in) double *v {
10 AV *tempav;
11 I32 len;
12 int i;
13 SV **tv;
14 if (!SvROK($input))
15 croak("Math::GSL : $input is not a reference!");
16 if (SvTYPE(SvRV($input)) != SVt_PVAV)
17 croak("Math::GSL : $input is not an array ref!");
19 tempav = (AV*)SvRV($input);
20 len = av_len(tempav);
21 $1 = (double *) malloc((len+1)*sizeof(double));
22 for (i = 0; i <= len; i++) {
23 tv = av_fetch(tempav, i, 0);
24 $1[i] = (double) SvNV(*tv);
26 $1[i] = GSL_NAN;
29 FILE * fopen(char *, char *);
30 int fclose(FILE *);
33 #include "/usr/local/include/gsl/gsl_nan.h"
34 #include "/usr/local/include/gsl/gsl_vector.h"
35 #include "/usr/local/include/gsl/gsl_vector_char.h"
36 #include "/usr/local/include/gsl/gsl_vector_complex.h"
37 #include "/usr/local/include/gsl/gsl_vector_complex_double.h"
38 #include "/usr/local/include/gsl/gsl_vector_double.h"
39 #include "/usr/local/include/gsl/gsl_vector_float.h"
40 #include "/usr/local/include/gsl/gsl_vector_int.h"
43 %include "/usr/local/include/gsl/gsl_nan.h"
44 %include "/usr/local/include/gsl/gsl_vector.h"
45 %include "/usr/local/include/gsl/gsl_vector_char.h"
46 %include "/usr/local/include/gsl/gsl_vector_complex.h"
47 %include "/usr/local/include/gsl/gsl_vector_complex_double.h"
48 %include "/usr/local/include/gsl/gsl_vector_double.h"
49 %include "/usr/local/include/gsl/gsl_vector_int.h"
53 %perlcode %{
56 @EXPORT_OK = qw/fopen fclose
57 gsl_vector_alloc gsl_vector_calloc gsl_vector_alloc_from_b gsl_vector_alloc_from_v
58 gsl_vector_free gsl_vector_view_array gsl_vector_view_array_w
59 gsl_vector_const_view_a gsl_vector_subvector gsl_vector_subvector_wi gsl_vector_subvector_with_stride
60 gsl_vector_const_subvec gsl_vector_const_subvec gsl_vector_get gsl_vector_set
61 gsl_vector_ptr gsl_vector_const_ptr gsl_vector_set_zero gsl_vector_set_all
62 gsl_vector_set_basis gsl_vector_fread gsl_vector_fwrite gsl_vector_fscanf
63 gsl_vector_fprintf gsl_vector_memcpy gsl_vector_reverse gsl_vector_swap
64 gsl_vector_swap_elements gsl_vector_max gsl_vector_min gsl_vector_minmax
65 gsl_vector_max_index gsl_vector_min_index gsl_vector_minmax_index
66 gsl_vector_add gsl_vector_sub gsl_vector_mul gsl_vector_div
67 gsl_vector_scale gsl_vector_add_constant gsl_vector_isnull
68 gsl_vector_ispos gsl_vector_isneg gsl_vector_isnonneg
70 %EXPORT_TAGS = ( all => [ @EXPORT_OK ] );
72 sub new {
73 my ($class, $values) = @_;
74 my $length = $#$values;
75 my $vector;
76 die __PACKAGE__.'::new($x) - $x must be an int or nonempty array reference'
77 if( !(defined $values) || ($length == -1));
79 if ( ref $values eq 'ARRAY' ){
80 $vector = gsl_vector_alloc($length+1);
81 map { gsl_vector_set($vector, $_, $values->[$_] ) } (0 .. $length);
82 } elsif ( int $values == $values && $values > 0) {
83 $vector = gsl_vector_alloc($length);
84 } else {
85 die __PACKAGE__.'::new($x) - $x must be an int or array reference';
87 my $self = {};
88 $self->{_vector} = $vector;
89 bless $self, $class;
92 sub get {
93 my ($self, $indices) = @_;
94 return map { gsl_vector_get($self->{_vector}, $_ ) } @$indices ;
97 sub set {
98 my ($self, $indices, $values) = @_;
99 die (__PACKAGE__.'::set($indices, $values) - $indices and $values must be array references of the same length')
100 unless ( ref $indices eq 'ARRAY' && ref $values eq 'ARRAY' && $#$indices == $#$values );
101 eval {
102 map { gsl_vector_set($self->{_vector}, $indices->[$_], $values->[$_] ) } (0..$#$indices);
104 return;
107 __END__
109 =head1 NAME
111 Math::GSL::Vector - Functions concerning vectors
113 =head1 SYPNOPSIS
115 use Math::GSL::Vector qw/:all/;
117 =head1 DESCRIPTION
119 Here is a list of all the functions included in this module :
121 gsl_vector_alloc($x) - create a vector of size $x
123 gsl_vector_calloc($x) - create a vector of size $x and initializes all the elements of the vector to zero
125 gsl_vector_alloc_from_b
127 gsl_vector_alloc_from_v
129 gsl_vector_free($v) - free a previously allocated vector $v
131 gsl_vector_view_array
133 gsl_vector_view_array_w
135 gsl_vector_const_view_a
137 gsl_vector_subvector - return a vector_view type which contains a subvector of $v, with a size of $size, starting from the $offset position
139 gsl_vector_subvector_wi
141 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
143 gsl_vector_const_subvec
145 gsl_vector_get($v, $i) - return the $i-th element of a vector $v
147 gsl_vector_set($v, $i, $x) - return the vector $v with his $i-th element set to $x
149 gsl_vector_ptr
151 gsl_vector_const_ptr
153 gsl_vector_set_zero($v) - set all the elements of $v to 0
155 gsl_vector_set_all($v, $x) - set all the elements of $v to $x
157 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.
159 gsl_vector_fread($file, $v)
161 gsl_vector_fwrite
163 gsl_vector_fscanf
165 gsl_vector_fprintf
167 gsl_vector_memcpy
169 gsl_vector_reverse($v) - reverse the order of the elements of the vector $v and return 0 if the opertaion succeded, 1 otherwise
171 gsl_vector_swap($v, $v2) - swap the values of the vectors $v and $v2 and return 0 if the opertaion succeded, 1 otherwise
173 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.
175 gsl_vector_max($v) - return the maximum value in the vector $v
177 gsl_vector_min($v) - return the minimum value in the vector $v
179 gsl_vector_minmax
181 gsl_vector_max_index($v) - return the position of the maximum value in the vector $v
183 gsl_vector_min_index - return the position of the minimum value in the vector $v
185 gsl_vector_minmax_index
187 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.
189 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.
191 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.
193 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.
195 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.
197 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.
199 gsl_vector_isnull($v) - verify if all the elements of the vector $v are null, return 0 if it's the case, 1 otherwise.
201 gsl_vector_ispos($v) - verify if all the elements of the vector $v are positive, return 0 if it's the case, 1 otherwise.
203 gsl_vector_isneg($v) - verify if all the elements of the vector $v are negative, return 0 if it's the case, 1 otherwise.
205 gsl_vector_isnonneg($v) - verify if all the elements the vector $v are not negative, return 0 if it's the case, 1 otherwise.
208 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.
211 Precision on the vector_view type : every modification you'll make on a vector_view will also modify the original vector.
212 For example, the following code will zero the even elements of the vector v of length n, while leaving the odd elements untouched :
214 $v_even= gsl_vector_subvector_with_stride ($v, 0, 2, $size/2);
215 gsl_vector_set_zero ($v_even->{vector});
218 For more informations on the functions, we refer you to the GSL offcial documentation: L<http://www.gnu.org/software/gsl/manual/html_node/>
219 Tip : search on google: site:http://www.gnu.org/software/gsl/manual/html_node/ name_of_the_function_you_want
221 =head1 EXAMPLES
224 =head1 AUTHOR
226 Jonathan Leto <jonathan@leto.net> and Thierry Moisan <thierry.moisan@gmail.com>
228 =head1 COPYRIGHT AND LICENSE
230 Copyright (C) 2008 Jonathan Leto and Thierry Moisan
232 This program is free software; you can redistribute it and/or modify it
233 under the same terms as Perl itself.
235 =cut