Adding documentation and a test to Vector
[Math-GSL.git] / Vector.i
blob224c79f6e15970487ce1545381cc6a3fd4e508ec
1 %module Vector
2 %{
3 #include "/usr/include/stdio.h"
4 #include "/usr/local/include/gsl/gsl_vector.h"
5 #include "/usr/local/include/gsl/gsl_vector_char.h"
6 #include "/usr/local/include/gsl/gsl_vector_complex.h"
7 #include "/usr/local/include/gsl/gsl_vector_complex_double.h"
8 #include "/usr/local/include/gsl/gsl_vector_double.h"
9 #include "/usr/local/include/gsl/gsl_vector_float.h"
10 #include "/usr/local/include/gsl/gsl_vector_int.h"
12 %include "/usr/local/include/gsl/gsl_vector.h"
13 %include "/usr/local/include/gsl/gsl_vector_char.h"
14 %include "/usr/local/include/gsl/gsl_vector_complex.h"
15 %include "/usr/local/include/gsl/gsl_vector_complex_double.h"
16 %include "/usr/local/include/gsl/gsl_vector_double.h"
17 %include "/usr/local/include/gsl/gsl_vector_int.h"
19 FILE *fopen(char *, char *);
20 int fclose(FILE *);
22 %perlcode %{
25 @EXPORT_OK = qw/fopen fclose
26 gsl_vector_alloc gsl_vector_calloc gsl_vector_alloc_from_b gsl_vector_alloc_from_v
27 gsl_vector_free gsl_vector_view_array gsl_vector_view_array_w
28 gsl_vector_const_view_a gsl_vector_subvector gsl_vector_subvector_wi
29 gsl_vector_const_subvec gsl_vector_const_subvec gsl_vector_get gsl_vector_set
30 gsl_vector_ptr gsl_vector_const_ptr gsl_vector_set_zero gsl_vector_set_all
31 gsl_vector_set_basis gsl_vector_fread gsl_vector_fwrite gsl_vector_fscanf
32 gsl_vector_fprintf gsl_vector_memcpy gsl_vector_reverse gsl_vector_swap
33 gsl_vector_swap_element gsl_vector_max gsl_vector_min gsl_vector_minmax
34 gsl_vector_max_index gsl_vector_min_index gsl_vector_minmax_index
35 gsl_vector_add gsl_vector_sub gsl_vector_mul gsl_vector_div
36 gsl_vector_scale gsl_vector_add_constant gsl_vector_isnull
37 gsl_vector_ispos gsl_vector_isneg gsl_vector_isnonneg
39 %EXPORT_TAGS = ( all => [ @EXPORT_OK ] );
41 sub new {
42 my ($class, $values) = @_;
43 my $length = $#$values;
44 my $vector;
45 die __PACKAGE__.'::new($x) - $x must be an int or nonempty array reference'
46 if( !(defined $values) || ($length == -1));
48 if ( ref $values eq 'ARRAY' ){
49 $vector = gsl_vector_alloc($length+1);
50 map { gsl_vector_set($vector, $_, $values->[$_] ) } (0 .. $length);
51 } elsif ( int $values == $values && $values > 0) {
52 $vector = gsl_vector_alloc($length);
53 } else {
54 die __PACKAGE__.'::new($x) - $x must be an int or array reference';
56 my $self = {};
57 $self->{_vector} = $vector;
58 bless $self, $class;
61 sub get {
62 my ($self, $indices) = @_;
63 return map { gsl_vector_get($self->{_vector}, $_ ) } @$indices ;
66 sub set {
67 my ($self, $indices, $values) = @_;
68 die (__PACKAGE__.'::set($indices, $values) - $indices and $values must be array references of the same length')
69 unless ( ref $indices eq 'ARRAY' && ref $values eq 'ARRAY' && $#$indices == $#$values );
70 eval {
71 map { gsl_vector_set($self->{_vector}, $indices->[$_], $values->[$_] ) } (0..$#$indices);
72 };
73 return;
76 __END__
78 =head1 NAME
80 Math::GSL::Vector
81 Functions concerning Vectors.
83 =head1 SYPNOPSIS
85 use Math::GSL::Vector qw/:all/;
87 =head1 DESCRIPTION
89 Here is a list of all the functions included in this module :
91 gsl_vector_alloc($x) - create a vector of size $x
93 gsl_vector_calloc($x) - create a vector of size $x and initializes all the elements of the vector to zero
95 gsl_vector_alloc_from_b
97 gsl_vector_alloc_from_v
99 gsl_vector_free($v) - free a previously allocated vector $v
101 gsl_vector_view_array
103 gsl_vector_view_array_w
105 gsl_vector_const_view_a
107 gsl_vector_subvector
109 gsl_vector_subvector_wi
111 gsl_vector_const_subvec
113 gsl_vector_const_subvec
115 gsl_vector_get($v, $i) - return the $i-th element of a vector $v
117 gsl_vector_set($v, $i, $x) - return the vector $v with his $i-th element set to $x
119 gsl_vector_ptr
121 gsl_vector_const_ptr
123 gsl_vector_set_zero
125 gsl_vector_set_all
127 gsl_vector_set_basis
129 gsl_vector_fread
131 gsl_vector_fwrite
133 gsl_vector_fscanf
135 gsl_vector_fprintf
137 gsl_vector_memcpy
139 gsl_vector_reverse
141 gsl_vector_swap
143 gsl_vector_swap_element
145 gsl_vector_max
147 gsl_vector_min
149 gsl_vector_minmax
151 gsl_vector_max_index
153 gsl_vector_min_index
155 gsl_vector_minmax_index
157 gsl_vector_add
159 gsl_vector_sub
161 gsl_vector_mul
163 gsl_vector_div
165 gsl_vector_scale
167 gsl_vector_add_constant
169 gsl_vector_isnull
171 gsl_vector_ispos
173 gsl_vector_isneg
175 gsl_vector_isnonneg
177 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.
179 For more informations on the functions, we refer you to the GSL offcial documentation: http://www.gnu.org/software/gsl/manual/html_node/
180 Tip : search on google: site:http://www.gnu.org/software/gsl/manual/html_node/ name_of_the_function_you_want
182 =head1 EXAMPLES
185 =head1 AUTHOR
187 Jonathan Leto <jonathan@leto.net> and Thierry Moisan <thierry.moisan@gmail.com>
189 =head1 COPYRIGHT AND LICENSE
191 Copyright (C) 2008 Jonathan Leto and Thierry Moisan
193 This program is free software; you can redistribute it and/or modify it
194 under the same terms as Perl itself.
196 =cut