1# This file was automatically generated by SWIG (http://www.swig.org).
2# Version 4.0.1
3#
4# Do not make changes to this file unless you know what you are doing--modify
5# the SWIG interface file instead.
6
7package Math::GSL::Vector;
8use base qw(Exporter);
9use base qw(DynaLoader);
10package Math::GSL::Vectorc;
11bootstrap Math::GSL::Vector;
12package Math::GSL::Vector;
13@EXPORT = qw();
14
15# ---------- BASE METHODS -------------
16
17package Math::GSL::Vector;
18
19sub TIEHASH {
20    my ($classname,$obj) = @_;
21    return bless $obj, $classname;
22}
23
24sub CLEAR { }
25
26sub FIRSTKEY { }
27
28sub NEXTKEY { }
29
30sub FETCH {
31    my ($self,$field) = @_;
32    my $member_func = "swig_${field}_get";
33    $self->$member_func();
34}
35
36sub STORE {
37    my ($self,$field,$newval) = @_;
38    my $member_func = "swig_${field}_set";
39    $self->$member_func($newval);
40}
41
42sub this {
43    my $ptr = shift;
44    return tied(%$ptr);
45}
46
47
48# ------- FUNCTION WRAPPERS --------
49
50package Math::GSL::Vector;
51
52*gsl_error = *Math::GSL::Vectorc::gsl_error;
53*gsl_stream_printf = *Math::GSL::Vectorc::gsl_stream_printf;
54*gsl_strerror = *Math::GSL::Vectorc::gsl_strerror;
55*gsl_set_error_handler = *Math::GSL::Vectorc::gsl_set_error_handler;
56*gsl_set_error_handler_off = *Math::GSL::Vectorc::gsl_set_error_handler_off;
57*gsl_set_stream_handler = *Math::GSL::Vectorc::gsl_set_stream_handler;
58*gsl_set_stream = *Math::GSL::Vectorc::gsl_set_stream;
59*fopen = *Math::GSL::Vectorc::fopen;
60*fclose = *Math::GSL::Vectorc::fclose;
61*gsl_vector_char_alloc = *Math::GSL::Vectorc::gsl_vector_char_alloc;
62*gsl_vector_char_calloc = *Math::GSL::Vectorc::gsl_vector_char_calloc;
63*gsl_vector_char_alloc_from_block = *Math::GSL::Vectorc::gsl_vector_char_alloc_from_block;
64*gsl_vector_char_alloc_from_vector = *Math::GSL::Vectorc::gsl_vector_char_alloc_from_vector;
65*gsl_vector_char_free = *Math::GSL::Vectorc::gsl_vector_char_free;
66*gsl_vector_char_view_array = *Math::GSL::Vectorc::gsl_vector_char_view_array;
67*gsl_vector_char_view_array_with_stride = *Math::GSL::Vectorc::gsl_vector_char_view_array_with_stride;
68*gsl_vector_char_const_view_array = *Math::GSL::Vectorc::gsl_vector_char_const_view_array;
69*gsl_vector_char_const_view_array_with_stride = *Math::GSL::Vectorc::gsl_vector_char_const_view_array_with_stride;
70*gsl_vector_char_subvector = *Math::GSL::Vectorc::gsl_vector_char_subvector;
71*gsl_vector_char_subvector_with_stride = *Math::GSL::Vectorc::gsl_vector_char_subvector_with_stride;
72*gsl_vector_char_const_subvector = *Math::GSL::Vectorc::gsl_vector_char_const_subvector;
73*gsl_vector_char_const_subvector_with_stride = *Math::GSL::Vectorc::gsl_vector_char_const_subvector_with_stride;
74*gsl_vector_char_set_zero = *Math::GSL::Vectorc::gsl_vector_char_set_zero;
75*gsl_vector_char_set_all = *Math::GSL::Vectorc::gsl_vector_char_set_all;
76*gsl_vector_char_set_basis = *Math::GSL::Vectorc::gsl_vector_char_set_basis;
77*gsl_vector_char_fread = *Math::GSL::Vectorc::gsl_vector_char_fread;
78*gsl_vector_char_fwrite = *Math::GSL::Vectorc::gsl_vector_char_fwrite;
79*gsl_vector_char_fscanf = *Math::GSL::Vectorc::gsl_vector_char_fscanf;
80*gsl_vector_char_fprintf = *Math::GSL::Vectorc::gsl_vector_char_fprintf;
81*gsl_vector_char_memcpy = *Math::GSL::Vectorc::gsl_vector_char_memcpy;
82*gsl_vector_char_reverse = *Math::GSL::Vectorc::gsl_vector_char_reverse;
83*gsl_vector_char_swap = *Math::GSL::Vectorc::gsl_vector_char_swap;
84*gsl_vector_char_swap_elements = *Math::GSL::Vectorc::gsl_vector_char_swap_elements;
85*gsl_vector_char_max = *Math::GSL::Vectorc::gsl_vector_char_max;
86*gsl_vector_char_min = *Math::GSL::Vectorc::gsl_vector_char_min;
87*gsl_vector_char_minmax = *Math::GSL::Vectorc::gsl_vector_char_minmax;
88*gsl_vector_char_max_index = *Math::GSL::Vectorc::gsl_vector_char_max_index;
89*gsl_vector_char_min_index = *Math::GSL::Vectorc::gsl_vector_char_min_index;
90*gsl_vector_char_minmax_index = *Math::GSL::Vectorc::gsl_vector_char_minmax_index;
91*gsl_vector_char_add = *Math::GSL::Vectorc::gsl_vector_char_add;
92*gsl_vector_char_sub = *Math::GSL::Vectorc::gsl_vector_char_sub;
93*gsl_vector_char_mul = *Math::GSL::Vectorc::gsl_vector_char_mul;
94*gsl_vector_char_div = *Math::GSL::Vectorc::gsl_vector_char_div;
95*gsl_vector_char_scale = *Math::GSL::Vectorc::gsl_vector_char_scale;
96*gsl_vector_char_add_constant = *Math::GSL::Vectorc::gsl_vector_char_add_constant;
97*gsl_vector_char_equal = *Math::GSL::Vectorc::gsl_vector_char_equal;
98*gsl_vector_char_isnull = *Math::GSL::Vectorc::gsl_vector_char_isnull;
99*gsl_vector_char_ispos = *Math::GSL::Vectorc::gsl_vector_char_ispos;
100*gsl_vector_char_isneg = *Math::GSL::Vectorc::gsl_vector_char_isneg;
101*gsl_vector_char_isnonneg = *Math::GSL::Vectorc::gsl_vector_char_isnonneg;
102*gsl_vector_char_get = *Math::GSL::Vectorc::gsl_vector_char_get;
103*gsl_vector_char_set = *Math::GSL::Vectorc::gsl_vector_char_set;
104*gsl_vector_char_ptr = *Math::GSL::Vectorc::gsl_vector_char_ptr;
105*gsl_vector_char_const_ptr = *Math::GSL::Vectorc::gsl_vector_char_const_ptr;
106*gsl_vector_complex_alloc = *Math::GSL::Vectorc::gsl_vector_complex_alloc;
107*gsl_vector_complex_calloc = *Math::GSL::Vectorc::gsl_vector_complex_calloc;
108*gsl_vector_complex_alloc_from_block = *Math::GSL::Vectorc::gsl_vector_complex_alloc_from_block;
109*gsl_vector_complex_alloc_from_vector = *Math::GSL::Vectorc::gsl_vector_complex_alloc_from_vector;
110*gsl_vector_complex_free = *Math::GSL::Vectorc::gsl_vector_complex_free;
111*gsl_vector_complex_view_array = *Math::GSL::Vectorc::gsl_vector_complex_view_array;
112*gsl_vector_complex_view_array_with_stride = *Math::GSL::Vectorc::gsl_vector_complex_view_array_with_stride;
113*gsl_vector_complex_const_view_array = *Math::GSL::Vectorc::gsl_vector_complex_const_view_array;
114*gsl_vector_complex_const_view_array_with_stride = *Math::GSL::Vectorc::gsl_vector_complex_const_view_array_with_stride;
115*gsl_vector_complex_subvector = *Math::GSL::Vectorc::gsl_vector_complex_subvector;
116*gsl_vector_complex_subvector_with_stride = *Math::GSL::Vectorc::gsl_vector_complex_subvector_with_stride;
117*gsl_vector_complex_const_subvector = *Math::GSL::Vectorc::gsl_vector_complex_const_subvector;
118*gsl_vector_complex_const_subvector_with_stride = *Math::GSL::Vectorc::gsl_vector_complex_const_subvector_with_stride;
119*gsl_vector_complex_real = *Math::GSL::Vectorc::gsl_vector_complex_real;
120*gsl_vector_complex_imag = *Math::GSL::Vectorc::gsl_vector_complex_imag;
121*gsl_vector_complex_const_real = *Math::GSL::Vectorc::gsl_vector_complex_const_real;
122*gsl_vector_complex_const_imag = *Math::GSL::Vectorc::gsl_vector_complex_const_imag;
123*gsl_vector_complex_set_zero = *Math::GSL::Vectorc::gsl_vector_complex_set_zero;
124*gsl_vector_complex_set_all = *Math::GSL::Vectorc::gsl_vector_complex_set_all;
125*gsl_vector_complex_set_basis = *Math::GSL::Vectorc::gsl_vector_complex_set_basis;
126*gsl_vector_complex_fread = *Math::GSL::Vectorc::gsl_vector_complex_fread;
127*gsl_vector_complex_fwrite = *Math::GSL::Vectorc::gsl_vector_complex_fwrite;
128*gsl_vector_complex_fscanf = *Math::GSL::Vectorc::gsl_vector_complex_fscanf;
129*gsl_vector_complex_fprintf = *Math::GSL::Vectorc::gsl_vector_complex_fprintf;
130*gsl_vector_complex_memcpy = *Math::GSL::Vectorc::gsl_vector_complex_memcpy;
131*gsl_vector_complex_reverse = *Math::GSL::Vectorc::gsl_vector_complex_reverse;
132*gsl_vector_complex_swap = *Math::GSL::Vectorc::gsl_vector_complex_swap;
133*gsl_vector_complex_swap_elements = *Math::GSL::Vectorc::gsl_vector_complex_swap_elements;
134*gsl_vector_complex_equal = *Math::GSL::Vectorc::gsl_vector_complex_equal;
135*gsl_vector_complex_isnull = *Math::GSL::Vectorc::gsl_vector_complex_isnull;
136*gsl_vector_complex_ispos = *Math::GSL::Vectorc::gsl_vector_complex_ispos;
137*gsl_vector_complex_isneg = *Math::GSL::Vectorc::gsl_vector_complex_isneg;
138*gsl_vector_complex_isnonneg = *Math::GSL::Vectorc::gsl_vector_complex_isnonneg;
139*gsl_vector_complex_add = *Math::GSL::Vectorc::gsl_vector_complex_add;
140*gsl_vector_complex_sub = *Math::GSL::Vectorc::gsl_vector_complex_sub;
141*gsl_vector_complex_mul = *Math::GSL::Vectorc::gsl_vector_complex_mul;
142*gsl_vector_complex_div = *Math::GSL::Vectorc::gsl_vector_complex_div;
143*gsl_vector_complex_scale = *Math::GSL::Vectorc::gsl_vector_complex_scale;
144*gsl_vector_complex_add_constant = *Math::GSL::Vectorc::gsl_vector_complex_add_constant;
145*gsl_vector_complex_get = *Math::GSL::Vectorc::gsl_vector_complex_get;
146*gsl_vector_complex_set = *Math::GSL::Vectorc::gsl_vector_complex_set;
147*gsl_vector_complex_ptr = *Math::GSL::Vectorc::gsl_vector_complex_ptr;
148*gsl_vector_complex_const_ptr = *Math::GSL::Vectorc::gsl_vector_complex_const_ptr;
149*gsl_vector_alloc = *Math::GSL::Vectorc::gsl_vector_alloc;
150*gsl_vector_calloc = *Math::GSL::Vectorc::gsl_vector_calloc;
151*gsl_vector_alloc_from_block = *Math::GSL::Vectorc::gsl_vector_alloc_from_block;
152*gsl_vector_alloc_from_vector = *Math::GSL::Vectorc::gsl_vector_alloc_from_vector;
153*gsl_vector_free = *Math::GSL::Vectorc::gsl_vector_free;
154*gsl_vector_view_array = *Math::GSL::Vectorc::gsl_vector_view_array;
155*gsl_vector_view_array_with_stride = *Math::GSL::Vectorc::gsl_vector_view_array_with_stride;
156*gsl_vector_const_view_array = *Math::GSL::Vectorc::gsl_vector_const_view_array;
157*gsl_vector_const_view_array_with_stride = *Math::GSL::Vectorc::gsl_vector_const_view_array_with_stride;
158*gsl_vector_subvector = *Math::GSL::Vectorc::gsl_vector_subvector;
159*gsl_vector_subvector_with_stride = *Math::GSL::Vectorc::gsl_vector_subvector_with_stride;
160*gsl_vector_const_subvector = *Math::GSL::Vectorc::gsl_vector_const_subvector;
161*gsl_vector_const_subvector_with_stride = *Math::GSL::Vectorc::gsl_vector_const_subvector_with_stride;
162*gsl_vector_set_zero = *Math::GSL::Vectorc::gsl_vector_set_zero;
163*gsl_vector_set_all = *Math::GSL::Vectorc::gsl_vector_set_all;
164*gsl_vector_set_basis = *Math::GSL::Vectorc::gsl_vector_set_basis;
165*gsl_vector_fread = *Math::GSL::Vectorc::gsl_vector_fread;
166*gsl_vector_fwrite = *Math::GSL::Vectorc::gsl_vector_fwrite;
167*gsl_vector_fscanf = *Math::GSL::Vectorc::gsl_vector_fscanf;
168*gsl_vector_fprintf = *Math::GSL::Vectorc::gsl_vector_fprintf;
169*gsl_vector_memcpy = *Math::GSL::Vectorc::gsl_vector_memcpy;
170*gsl_vector_reverse = *Math::GSL::Vectorc::gsl_vector_reverse;
171*gsl_vector_swap = *Math::GSL::Vectorc::gsl_vector_swap;
172*gsl_vector_swap_elements = *Math::GSL::Vectorc::gsl_vector_swap_elements;
173*gsl_vector_max = *Math::GSL::Vectorc::gsl_vector_max;
174*gsl_vector_min = *Math::GSL::Vectorc::gsl_vector_min;
175*gsl_vector_minmax = *Math::GSL::Vectorc::gsl_vector_minmax;
176*gsl_vector_max_index = *Math::GSL::Vectorc::gsl_vector_max_index;
177*gsl_vector_min_index = *Math::GSL::Vectorc::gsl_vector_min_index;
178*gsl_vector_minmax_index = *Math::GSL::Vectorc::gsl_vector_minmax_index;
179*gsl_vector_add = *Math::GSL::Vectorc::gsl_vector_add;
180*gsl_vector_sub = *Math::GSL::Vectorc::gsl_vector_sub;
181*gsl_vector_mul = *Math::GSL::Vectorc::gsl_vector_mul;
182*gsl_vector_div = *Math::GSL::Vectorc::gsl_vector_div;
183*gsl_vector_scale = *Math::GSL::Vectorc::gsl_vector_scale;
184*gsl_vector_add_constant = *Math::GSL::Vectorc::gsl_vector_add_constant;
185*gsl_vector_equal = *Math::GSL::Vectorc::gsl_vector_equal;
186*gsl_vector_isnull = *Math::GSL::Vectorc::gsl_vector_isnull;
187*gsl_vector_ispos = *Math::GSL::Vectorc::gsl_vector_ispos;
188*gsl_vector_isneg = *Math::GSL::Vectorc::gsl_vector_isneg;
189*gsl_vector_isnonneg = *Math::GSL::Vectorc::gsl_vector_isnonneg;
190*gsl_vector_get = *Math::GSL::Vectorc::gsl_vector_get;
191*gsl_vector_set = *Math::GSL::Vectorc::gsl_vector_set;
192*gsl_vector_ptr = *Math::GSL::Vectorc::gsl_vector_ptr;
193*gsl_vector_const_ptr = *Math::GSL::Vectorc::gsl_vector_const_ptr;
194*gsl_vector_int_alloc = *Math::GSL::Vectorc::gsl_vector_int_alloc;
195*gsl_vector_int_calloc = *Math::GSL::Vectorc::gsl_vector_int_calloc;
196*gsl_vector_int_alloc_from_block = *Math::GSL::Vectorc::gsl_vector_int_alloc_from_block;
197*gsl_vector_int_alloc_from_vector = *Math::GSL::Vectorc::gsl_vector_int_alloc_from_vector;
198*gsl_vector_int_free = *Math::GSL::Vectorc::gsl_vector_int_free;
199*gsl_vector_int_view_array = *Math::GSL::Vectorc::gsl_vector_int_view_array;
200*gsl_vector_int_view_array_with_stride = *Math::GSL::Vectorc::gsl_vector_int_view_array_with_stride;
201*gsl_vector_int_const_view_array = *Math::GSL::Vectorc::gsl_vector_int_const_view_array;
202*gsl_vector_int_const_view_array_with_stride = *Math::GSL::Vectorc::gsl_vector_int_const_view_array_with_stride;
203*gsl_vector_int_subvector = *Math::GSL::Vectorc::gsl_vector_int_subvector;
204*gsl_vector_int_subvector_with_stride = *Math::GSL::Vectorc::gsl_vector_int_subvector_with_stride;
205*gsl_vector_int_const_subvector = *Math::GSL::Vectorc::gsl_vector_int_const_subvector;
206*gsl_vector_int_const_subvector_with_stride = *Math::GSL::Vectorc::gsl_vector_int_const_subvector_with_stride;
207*gsl_vector_int_set_zero = *Math::GSL::Vectorc::gsl_vector_int_set_zero;
208*gsl_vector_int_set_all = *Math::GSL::Vectorc::gsl_vector_int_set_all;
209*gsl_vector_int_set_basis = *Math::GSL::Vectorc::gsl_vector_int_set_basis;
210*gsl_vector_int_fread = *Math::GSL::Vectorc::gsl_vector_int_fread;
211*gsl_vector_int_fwrite = *Math::GSL::Vectorc::gsl_vector_int_fwrite;
212*gsl_vector_int_fscanf = *Math::GSL::Vectorc::gsl_vector_int_fscanf;
213*gsl_vector_int_fprintf = *Math::GSL::Vectorc::gsl_vector_int_fprintf;
214*gsl_vector_int_memcpy = *Math::GSL::Vectorc::gsl_vector_int_memcpy;
215*gsl_vector_int_reverse = *Math::GSL::Vectorc::gsl_vector_int_reverse;
216*gsl_vector_int_swap = *Math::GSL::Vectorc::gsl_vector_int_swap;
217*gsl_vector_int_swap_elements = *Math::GSL::Vectorc::gsl_vector_int_swap_elements;
218*gsl_vector_int_max = *Math::GSL::Vectorc::gsl_vector_int_max;
219*gsl_vector_int_min = *Math::GSL::Vectorc::gsl_vector_int_min;
220*gsl_vector_int_minmax = *Math::GSL::Vectorc::gsl_vector_int_minmax;
221*gsl_vector_int_max_index = *Math::GSL::Vectorc::gsl_vector_int_max_index;
222*gsl_vector_int_min_index = *Math::GSL::Vectorc::gsl_vector_int_min_index;
223*gsl_vector_int_minmax_index = *Math::GSL::Vectorc::gsl_vector_int_minmax_index;
224*gsl_vector_int_add = *Math::GSL::Vectorc::gsl_vector_int_add;
225*gsl_vector_int_sub = *Math::GSL::Vectorc::gsl_vector_int_sub;
226*gsl_vector_int_mul = *Math::GSL::Vectorc::gsl_vector_int_mul;
227*gsl_vector_int_div = *Math::GSL::Vectorc::gsl_vector_int_div;
228*gsl_vector_int_scale = *Math::GSL::Vectorc::gsl_vector_int_scale;
229*gsl_vector_int_add_constant = *Math::GSL::Vectorc::gsl_vector_int_add_constant;
230*gsl_vector_int_equal = *Math::GSL::Vectorc::gsl_vector_int_equal;
231*gsl_vector_int_isnull = *Math::GSL::Vectorc::gsl_vector_int_isnull;
232*gsl_vector_int_ispos = *Math::GSL::Vectorc::gsl_vector_int_ispos;
233*gsl_vector_int_isneg = *Math::GSL::Vectorc::gsl_vector_int_isneg;
234*gsl_vector_int_isnonneg = *Math::GSL::Vectorc::gsl_vector_int_isnonneg;
235*gsl_vector_int_get = *Math::GSL::Vectorc::gsl_vector_int_get;
236*gsl_vector_int_set = *Math::GSL::Vectorc::gsl_vector_int_set;
237*gsl_vector_int_ptr = *Math::GSL::Vectorc::gsl_vector_int_ptr;
238*gsl_vector_int_const_ptr = *Math::GSL::Vectorc::gsl_vector_int_const_ptr;
239
240############# Class : Math::GSL::Vector::gsl_vector_char ##############
241
242package Math::GSL::Vector::gsl_vector_char;
243use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
244@ISA = qw( Math::GSL::Vector );
245%OWNER = ();
246%ITERATORS = ();
247*swig_size_get = *Math::GSL::Vectorc::gsl_vector_char_size_get;
248*swig_size_set = *Math::GSL::Vectorc::gsl_vector_char_size_set;
249*swig_stride_get = *Math::GSL::Vectorc::gsl_vector_char_stride_get;
250*swig_stride_set = *Math::GSL::Vectorc::gsl_vector_char_stride_set;
251*swig_data_get = *Math::GSL::Vectorc::gsl_vector_char_data_get;
252*swig_data_set = *Math::GSL::Vectorc::gsl_vector_char_data_set;
253*swig_block_get = *Math::GSL::Vectorc::gsl_vector_char_block_get;
254*swig_block_set = *Math::GSL::Vectorc::gsl_vector_char_block_set;
255*swig_owner_get = *Math::GSL::Vectorc::gsl_vector_char_owner_get;
256*swig_owner_set = *Math::GSL::Vectorc::gsl_vector_char_owner_set;
257sub new {
258    my $pkg = shift;
259    my $self = Math::GSL::Vectorc::new_gsl_vector_char(@_);
260    bless $self, $pkg if defined($self);
261}
262
263sub DESTROY {
264    return unless $_[0]->isa('HASH');
265    my $self = tied(%{$_[0]});
266    return unless defined $self;
267    delete $ITERATORS{$self};
268    if (exists $OWNER{$self}) {
269        Math::GSL::Vectorc::delete_gsl_vector_char($self);
270        delete $OWNER{$self};
271    }
272}
273
274sub DISOWN {
275    my $self = shift;
276    my $ptr = tied(%$self);
277    delete $OWNER{$ptr};
278}
279
280sub ACQUIRE {
281    my $self = shift;
282    my $ptr = tied(%$self);
283    $OWNER{$ptr} = 1;
284}
285
286
287############# Class : Math::GSL::Vector::_gsl_vector_char_view ##############
288
289package Math::GSL::Vector::_gsl_vector_char_view;
290use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
291@ISA = qw( Math::GSL::Vector );
292%OWNER = ();
293%ITERATORS = ();
294*swig_vector_get = *Math::GSL::Vectorc::_gsl_vector_char_view_vector_get;
295*swig_vector_set = *Math::GSL::Vectorc::_gsl_vector_char_view_vector_set;
296sub new {
297    my $pkg = shift;
298    my $self = Math::GSL::Vectorc::new__gsl_vector_char_view(@_);
299    bless $self, $pkg if defined($self);
300}
301
302sub DESTROY {
303    return unless $_[0]->isa('HASH');
304    my $self = tied(%{$_[0]});
305    return unless defined $self;
306    delete $ITERATORS{$self};
307    if (exists $OWNER{$self}) {
308        Math::GSL::Vectorc::delete__gsl_vector_char_view($self);
309        delete $OWNER{$self};
310    }
311}
312
313sub DISOWN {
314    my $self = shift;
315    my $ptr = tied(%$self);
316    delete $OWNER{$ptr};
317}
318
319sub ACQUIRE {
320    my $self = shift;
321    my $ptr = tied(%$self);
322    $OWNER{$ptr} = 1;
323}
324
325
326############# Class : Math::GSL::Vector::_gsl_vector_char_const_view ##############
327
328package Math::GSL::Vector::_gsl_vector_char_const_view;
329use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
330@ISA = qw( Math::GSL::Vector );
331%OWNER = ();
332%ITERATORS = ();
333*swig_vector_get = *Math::GSL::Vectorc::_gsl_vector_char_const_view_vector_get;
334*swig_vector_set = *Math::GSL::Vectorc::_gsl_vector_char_const_view_vector_set;
335sub new {
336    my $pkg = shift;
337    my $self = Math::GSL::Vectorc::new__gsl_vector_char_const_view(@_);
338    bless $self, $pkg if defined($self);
339}
340
341sub DESTROY {
342    return unless $_[0]->isa('HASH');
343    my $self = tied(%{$_[0]});
344    return unless defined $self;
345    delete $ITERATORS{$self};
346    if (exists $OWNER{$self}) {
347        Math::GSL::Vectorc::delete__gsl_vector_char_const_view($self);
348        delete $OWNER{$self};
349    }
350}
351
352sub DISOWN {
353    my $self = shift;
354    my $ptr = tied(%$self);
355    delete $OWNER{$ptr};
356}
357
358sub ACQUIRE {
359    my $self = shift;
360    my $ptr = tied(%$self);
361    $OWNER{$ptr} = 1;
362}
363
364
365############# Class : Math::GSL::Vector::gsl_vector_complex ##############
366
367package Math::GSL::Vector::gsl_vector_complex;
368use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
369@ISA = qw( Math::GSL::Vector );
370%OWNER = ();
371%ITERATORS = ();
372*swig_size_get = *Math::GSL::Vectorc::gsl_vector_complex_size_get;
373*swig_size_set = *Math::GSL::Vectorc::gsl_vector_complex_size_set;
374*swig_stride_get = *Math::GSL::Vectorc::gsl_vector_complex_stride_get;
375*swig_stride_set = *Math::GSL::Vectorc::gsl_vector_complex_stride_set;
376*swig_data_get = *Math::GSL::Vectorc::gsl_vector_complex_data_get;
377*swig_data_set = *Math::GSL::Vectorc::gsl_vector_complex_data_set;
378*swig_block_get = *Math::GSL::Vectorc::gsl_vector_complex_block_get;
379*swig_block_set = *Math::GSL::Vectorc::gsl_vector_complex_block_set;
380*swig_owner_get = *Math::GSL::Vectorc::gsl_vector_complex_owner_get;
381*swig_owner_set = *Math::GSL::Vectorc::gsl_vector_complex_owner_set;
382sub new {
383    my $pkg = shift;
384    my $self = Math::GSL::Vectorc::new_gsl_vector_complex(@_);
385    bless $self, $pkg if defined($self);
386}
387
388sub DESTROY {
389    return unless $_[0]->isa('HASH');
390    my $self = tied(%{$_[0]});
391    return unless defined $self;
392    delete $ITERATORS{$self};
393    if (exists $OWNER{$self}) {
394        Math::GSL::Vectorc::delete_gsl_vector_complex($self);
395        delete $OWNER{$self};
396    }
397}
398
399sub DISOWN {
400    my $self = shift;
401    my $ptr = tied(%$self);
402    delete $OWNER{$ptr};
403}
404
405sub ACQUIRE {
406    my $self = shift;
407    my $ptr = tied(%$self);
408    $OWNER{$ptr} = 1;
409}
410
411
412############# Class : Math::GSL::Vector::_gsl_vector_complex_view ##############
413
414package Math::GSL::Vector::_gsl_vector_complex_view;
415use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
416@ISA = qw( Math::GSL::Vector );
417%OWNER = ();
418%ITERATORS = ();
419*swig_vector_get = *Math::GSL::Vectorc::_gsl_vector_complex_view_vector_get;
420*swig_vector_set = *Math::GSL::Vectorc::_gsl_vector_complex_view_vector_set;
421sub new {
422    my $pkg = shift;
423    my $self = Math::GSL::Vectorc::new__gsl_vector_complex_view(@_);
424    bless $self, $pkg if defined($self);
425}
426
427sub DESTROY {
428    return unless $_[0]->isa('HASH');
429    my $self = tied(%{$_[0]});
430    return unless defined $self;
431    delete $ITERATORS{$self};
432    if (exists $OWNER{$self}) {
433        Math::GSL::Vectorc::delete__gsl_vector_complex_view($self);
434        delete $OWNER{$self};
435    }
436}
437
438sub DISOWN {
439    my $self = shift;
440    my $ptr = tied(%$self);
441    delete $OWNER{$ptr};
442}
443
444sub ACQUIRE {
445    my $self = shift;
446    my $ptr = tied(%$self);
447    $OWNER{$ptr} = 1;
448}
449
450
451############# Class : Math::GSL::Vector::_gsl_vector_complex_const_view ##############
452
453package Math::GSL::Vector::_gsl_vector_complex_const_view;
454use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
455@ISA = qw( Math::GSL::Vector );
456%OWNER = ();
457%ITERATORS = ();
458*swig_vector_get = *Math::GSL::Vectorc::_gsl_vector_complex_const_view_vector_get;
459*swig_vector_set = *Math::GSL::Vectorc::_gsl_vector_complex_const_view_vector_set;
460sub new {
461    my $pkg = shift;
462    my $self = Math::GSL::Vectorc::new__gsl_vector_complex_const_view(@_);
463    bless $self, $pkg if defined($self);
464}
465
466sub DESTROY {
467    return unless $_[0]->isa('HASH');
468    my $self = tied(%{$_[0]});
469    return unless defined $self;
470    delete $ITERATORS{$self};
471    if (exists $OWNER{$self}) {
472        Math::GSL::Vectorc::delete__gsl_vector_complex_const_view($self);
473        delete $OWNER{$self};
474    }
475}
476
477sub DISOWN {
478    my $self = shift;
479    my $ptr = tied(%$self);
480    delete $OWNER{$ptr};
481}
482
483sub ACQUIRE {
484    my $self = shift;
485    my $ptr = tied(%$self);
486    $OWNER{$ptr} = 1;
487}
488
489
490############# Class : Math::GSL::Vector::gsl_vector ##############
491
492package Math::GSL::Vector::gsl_vector;
493use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
494@ISA = qw( Math::GSL::Vector );
495%OWNER = ();
496%ITERATORS = ();
497*swig_size_get = *Math::GSL::Vectorc::gsl_vector_size_get;
498*swig_size_set = *Math::GSL::Vectorc::gsl_vector_size_set;
499*swig_stride_get = *Math::GSL::Vectorc::gsl_vector_stride_get;
500*swig_stride_set = *Math::GSL::Vectorc::gsl_vector_stride_set;
501*swig_data_get = *Math::GSL::Vectorc::gsl_vector_data_get;
502*swig_data_set = *Math::GSL::Vectorc::gsl_vector_data_set;
503*swig_block_get = *Math::GSL::Vectorc::gsl_vector_block_get;
504*swig_block_set = *Math::GSL::Vectorc::gsl_vector_block_set;
505*swig_owner_get = *Math::GSL::Vectorc::gsl_vector_owner_get;
506*swig_owner_set = *Math::GSL::Vectorc::gsl_vector_owner_set;
507sub new {
508    my $pkg = shift;
509    my $self = Math::GSL::Vectorc::new_gsl_vector(@_);
510    bless $self, $pkg if defined($self);
511}
512
513sub DESTROY {
514    return unless $_[0]->isa('HASH');
515    my $self = tied(%{$_[0]});
516    return unless defined $self;
517    delete $ITERATORS{$self};
518    if (exists $OWNER{$self}) {
519        Math::GSL::Vectorc::delete_gsl_vector($self);
520        delete $OWNER{$self};
521    }
522}
523
524sub DISOWN {
525    my $self = shift;
526    my $ptr = tied(%$self);
527    delete $OWNER{$ptr};
528}
529
530sub ACQUIRE {
531    my $self = shift;
532    my $ptr = tied(%$self);
533    $OWNER{$ptr} = 1;
534}
535
536
537############# Class : Math::GSL::Vector::_gsl_vector_view ##############
538
539package Math::GSL::Vector::_gsl_vector_view;
540use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
541@ISA = qw( Math::GSL::Vector );
542%OWNER = ();
543%ITERATORS = ();
544*swig_vector_get = *Math::GSL::Vectorc::_gsl_vector_view_vector_get;
545*swig_vector_set = *Math::GSL::Vectorc::_gsl_vector_view_vector_set;
546sub new {
547    my $pkg = shift;
548    my $self = Math::GSL::Vectorc::new__gsl_vector_view(@_);
549    bless $self, $pkg if defined($self);
550}
551
552sub DESTROY {
553    return unless $_[0]->isa('HASH');
554    my $self = tied(%{$_[0]});
555    return unless defined $self;
556    delete $ITERATORS{$self};
557    if (exists $OWNER{$self}) {
558        Math::GSL::Vectorc::delete__gsl_vector_view($self);
559        delete $OWNER{$self};
560    }
561}
562
563sub DISOWN {
564    my $self = shift;
565    my $ptr = tied(%$self);
566    delete $OWNER{$ptr};
567}
568
569sub ACQUIRE {
570    my $self = shift;
571    my $ptr = tied(%$self);
572    $OWNER{$ptr} = 1;
573}
574
575
576############# Class : Math::GSL::Vector::_gsl_vector_const_view ##############
577
578package Math::GSL::Vector::_gsl_vector_const_view;
579use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
580@ISA = qw( Math::GSL::Vector );
581%OWNER = ();
582%ITERATORS = ();
583*swig_vector_get = *Math::GSL::Vectorc::_gsl_vector_const_view_vector_get;
584*swig_vector_set = *Math::GSL::Vectorc::_gsl_vector_const_view_vector_set;
585sub new {
586    my $pkg = shift;
587    my $self = Math::GSL::Vectorc::new__gsl_vector_const_view(@_);
588    bless $self, $pkg if defined($self);
589}
590
591sub DESTROY {
592    return unless $_[0]->isa('HASH');
593    my $self = tied(%{$_[0]});
594    return unless defined $self;
595    delete $ITERATORS{$self};
596    if (exists $OWNER{$self}) {
597        Math::GSL::Vectorc::delete__gsl_vector_const_view($self);
598        delete $OWNER{$self};
599    }
600}
601
602sub DISOWN {
603    my $self = shift;
604    my $ptr = tied(%$self);
605    delete $OWNER{$ptr};
606}
607
608sub ACQUIRE {
609    my $self = shift;
610    my $ptr = tied(%$self);
611    $OWNER{$ptr} = 1;
612}
613
614
615############# Class : Math::GSL::Vector::gsl_vector_int ##############
616
617package Math::GSL::Vector::gsl_vector_int;
618use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
619@ISA = qw( Math::GSL::Vector );
620%OWNER = ();
621%ITERATORS = ();
622*swig_size_get = *Math::GSL::Vectorc::gsl_vector_int_size_get;
623*swig_size_set = *Math::GSL::Vectorc::gsl_vector_int_size_set;
624*swig_stride_get = *Math::GSL::Vectorc::gsl_vector_int_stride_get;
625*swig_stride_set = *Math::GSL::Vectorc::gsl_vector_int_stride_set;
626*swig_data_get = *Math::GSL::Vectorc::gsl_vector_int_data_get;
627*swig_data_set = *Math::GSL::Vectorc::gsl_vector_int_data_set;
628*swig_block_get = *Math::GSL::Vectorc::gsl_vector_int_block_get;
629*swig_block_set = *Math::GSL::Vectorc::gsl_vector_int_block_set;
630*swig_owner_get = *Math::GSL::Vectorc::gsl_vector_int_owner_get;
631*swig_owner_set = *Math::GSL::Vectorc::gsl_vector_int_owner_set;
632sub new {
633    my $pkg = shift;
634    my $self = Math::GSL::Vectorc::new_gsl_vector_int(@_);
635    bless $self, $pkg if defined($self);
636}
637
638sub DESTROY {
639    return unless $_[0]->isa('HASH');
640    my $self = tied(%{$_[0]});
641    return unless defined $self;
642    delete $ITERATORS{$self};
643    if (exists $OWNER{$self}) {
644        Math::GSL::Vectorc::delete_gsl_vector_int($self);
645        delete $OWNER{$self};
646    }
647}
648
649sub DISOWN {
650    my $self = shift;
651    my $ptr = tied(%$self);
652    delete $OWNER{$ptr};
653}
654
655sub ACQUIRE {
656    my $self = shift;
657    my $ptr = tied(%$self);
658    $OWNER{$ptr} = 1;
659}
660
661
662############# Class : Math::GSL::Vector::_gsl_vector_int_view ##############
663
664package Math::GSL::Vector::_gsl_vector_int_view;
665use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
666@ISA = qw( Math::GSL::Vector );
667%OWNER = ();
668%ITERATORS = ();
669*swig_vector_get = *Math::GSL::Vectorc::_gsl_vector_int_view_vector_get;
670*swig_vector_set = *Math::GSL::Vectorc::_gsl_vector_int_view_vector_set;
671sub new {
672    my $pkg = shift;
673    my $self = Math::GSL::Vectorc::new__gsl_vector_int_view(@_);
674    bless $self, $pkg if defined($self);
675}
676
677sub DESTROY {
678    return unless $_[0]->isa('HASH');
679    my $self = tied(%{$_[0]});
680    return unless defined $self;
681    delete $ITERATORS{$self};
682    if (exists $OWNER{$self}) {
683        Math::GSL::Vectorc::delete__gsl_vector_int_view($self);
684        delete $OWNER{$self};
685    }
686}
687
688sub DISOWN {
689    my $self = shift;
690    my $ptr = tied(%$self);
691    delete $OWNER{$ptr};
692}
693
694sub ACQUIRE {
695    my $self = shift;
696    my $ptr = tied(%$self);
697    $OWNER{$ptr} = 1;
698}
699
700
701############# Class : Math::GSL::Vector::_gsl_vector_int_const_view ##############
702
703package Math::GSL::Vector::_gsl_vector_int_const_view;
704use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
705@ISA = qw( Math::GSL::Vector );
706%OWNER = ();
707%ITERATORS = ();
708*swig_vector_get = *Math::GSL::Vectorc::_gsl_vector_int_const_view_vector_get;
709*swig_vector_set = *Math::GSL::Vectorc::_gsl_vector_int_const_view_vector_set;
710sub new {
711    my $pkg = shift;
712    my $self = Math::GSL::Vectorc::new__gsl_vector_int_const_view(@_);
713    bless $self, $pkg if defined($self);
714}
715
716sub DESTROY {
717    return unless $_[0]->isa('HASH');
718    my $self = tied(%{$_[0]});
719    return unless defined $self;
720    delete $ITERATORS{$self};
721    if (exists $OWNER{$self}) {
722        Math::GSL::Vectorc::delete__gsl_vector_int_const_view($self);
723        delete $OWNER{$self};
724    }
725}
726
727sub DISOWN {
728    my $self = shift;
729    my $ptr = tied(%$self);
730    delete $OWNER{$ptr};
731}
732
733sub ACQUIRE {
734    my $self = shift;
735    my $ptr = tied(%$self);
736    $OWNER{$ptr} = 1;
737}
738
739
740# ------- VARIABLE STUBS --------
741
742package Math::GSL::Vector;
743
744*GSL_VERSION = *Math::GSL::Vectorc::GSL_VERSION;
745*GSL_MAJOR_VERSION = *Math::GSL::Vectorc::GSL_MAJOR_VERSION;
746*GSL_MINOR_VERSION = *Math::GSL::Vectorc::GSL_MINOR_VERSION;
747*GSL_POSZERO = *Math::GSL::Vectorc::GSL_POSZERO;
748*GSL_NEGZERO = *Math::GSL::Vectorc::GSL_NEGZERO;
749*GSL_SUCCESS = *Math::GSL::Vectorc::GSL_SUCCESS;
750*GSL_FAILURE = *Math::GSL::Vectorc::GSL_FAILURE;
751*GSL_CONTINUE = *Math::GSL::Vectorc::GSL_CONTINUE;
752*GSL_EDOM = *Math::GSL::Vectorc::GSL_EDOM;
753*GSL_ERANGE = *Math::GSL::Vectorc::GSL_ERANGE;
754*GSL_EFAULT = *Math::GSL::Vectorc::GSL_EFAULT;
755*GSL_EINVAL = *Math::GSL::Vectorc::GSL_EINVAL;
756*GSL_EFAILED = *Math::GSL::Vectorc::GSL_EFAILED;
757*GSL_EFACTOR = *Math::GSL::Vectorc::GSL_EFACTOR;
758*GSL_ESANITY = *Math::GSL::Vectorc::GSL_ESANITY;
759*GSL_ENOMEM = *Math::GSL::Vectorc::GSL_ENOMEM;
760*GSL_EBADFUNC = *Math::GSL::Vectorc::GSL_EBADFUNC;
761*GSL_ERUNAWAY = *Math::GSL::Vectorc::GSL_ERUNAWAY;
762*GSL_EMAXITER = *Math::GSL::Vectorc::GSL_EMAXITER;
763*GSL_EZERODIV = *Math::GSL::Vectorc::GSL_EZERODIV;
764*GSL_EBADTOL = *Math::GSL::Vectorc::GSL_EBADTOL;
765*GSL_ETOL = *Math::GSL::Vectorc::GSL_ETOL;
766*GSL_EUNDRFLW = *Math::GSL::Vectorc::GSL_EUNDRFLW;
767*GSL_EOVRFLW = *Math::GSL::Vectorc::GSL_EOVRFLW;
768*GSL_ELOSS = *Math::GSL::Vectorc::GSL_ELOSS;
769*GSL_EROUND = *Math::GSL::Vectorc::GSL_EROUND;
770*GSL_EBADLEN = *Math::GSL::Vectorc::GSL_EBADLEN;
771*GSL_ENOTSQR = *Math::GSL::Vectorc::GSL_ENOTSQR;
772*GSL_ESING = *Math::GSL::Vectorc::GSL_ESING;
773*GSL_EDIVERGE = *Math::GSL::Vectorc::GSL_EDIVERGE;
774*GSL_EUNSUP = *Math::GSL::Vectorc::GSL_EUNSUP;
775*GSL_EUNIMPL = *Math::GSL::Vectorc::GSL_EUNIMPL;
776*GSL_ECACHE = *Math::GSL::Vectorc::GSL_ECACHE;
777*GSL_ETABLE = *Math::GSL::Vectorc::GSL_ETABLE;
778*GSL_ENOPROG = *Math::GSL::Vectorc::GSL_ENOPROG;
779*GSL_ENOPROGJ = *Math::GSL::Vectorc::GSL_ENOPROGJ;
780*GSL_ETOLF = *Math::GSL::Vectorc::GSL_ETOLF;
781*GSL_ETOLX = *Math::GSL::Vectorc::GSL_ETOLX;
782*GSL_ETOLG = *Math::GSL::Vectorc::GSL_ETOLG;
783*GSL_EOF = *Math::GSL::Vectorc::GSL_EOF;
784
785use Scalar::Util 'blessed';
786use Data::Dumper;
787use Carp qw/croak/;
788use Math::GSL::Errno qw/$GSL_SUCCESS gsl_strerror/;
789use Math::GSL::BLAS qw/gsl_blas_ddot/;
790use Math::GSL::Test qw/is_similar/;
791
792use overload
793    '*'      => \&_multiplication,
794    '+'      => \&_addition,
795    '-'      => \&_subtract,
796    'abs'    => \&_abs,
797    '=='     => \&_equal,
798    '!='     => \&_not_equal,
799    fallback => 1,
800;
801
802@EXPORT_all  = qw/fopen fclose
803                 gsl_vector_alloc gsl_vector_calloc gsl_vector_alloc_from_block gsl_vector_alloc_from_vector
804                 gsl_vector_free gsl_vector_view_array gsl_vector_const_view_array gsl_vector_view_array_with_stride
805                 gsl_vector_const_view_array_with_stride gsl_vector_subvector gsl_vector_subvector_wi gsl_vector_subvector_with_stride
806                 gsl_vector_const_subvector gsl_vector_const_subvec gsl_vector_get gsl_vector_set
807                 gsl_vector_ptr gsl_vector_const_ptr gsl_vector_set_zero gsl_vector_set_all
808                 gsl_vector_set_basis gsl_vector_fread gsl_vector_fwrite gsl_vector_fscanf
809                 gsl_vector_fprintf gsl_vector_memcpy gsl_vector_reverse gsl_vector_swap
810                 gsl_vector_swap_elements gsl_vector_max gsl_vector_min gsl_vector_minmax
811                 gsl_vector_max_index gsl_vector_min_index gsl_vector_minmax_index
812                 gsl_vector_add gsl_vector_sub gsl_vector_mul gsl_vector_div
813                 gsl_vector_scale gsl_vector_add_constant gsl_vector_isnull
814                 gsl_vector_ispos gsl_vector_isneg gsl_vector_isnonneg
815                 gsl_vector_float_alloc gsl_vector_float_calloc gsl_vector_float_alloc_from_block
816                 gsl_vector_float_alloc_from_vector gsl_vector_float_free gsl_vector_float_view_array
817                 gsl_vector_float_view_array_with_stride gsl_vector_float_const_view_array gsl_vector_float_const_view_array_with_stride
818                 gsl_vector_float_subvector gsl_vector_float_subvector_with_stride gsl_vector_float_const_subvector
819                 gsl_vector_float_const_subvector_with_stride gsl_vector_float_get gsl_vector_float_set gsl_vector_float_ptr
820                 gsl_vector_float_const_ptr gsl_vector_float_set_zero gsl_vector_float_set_all gsl_vector_float_set_basis
821                 gsl_vector_float_fread gsl_vector_float_fwrite gsl_vector_float_fscanf gsl_vector_float_fprintf
822                 gsl_vector_float_memcpy gsl_vector_float_reverse gsl_vector_float_swap gsl_vector_float_swap_elements
823                 gsl_vector_float_max gsl_vector_float_min gsl_vector_float_minmax gsl_vector_float_max_index gsl_vector_float_min_index
824                 gsl_vector_float_minmax_index gsl_vector_float_add gsl_vector_float_sub gsl_vector_float_mul gsl_vector_float_div gsl_vector_float_scale
825                 gsl_vector_float_add_constant gsl_vector_float_isnull gsl_vector_float_ispos gsl_vector_float_isneg gsl_vector_float_isnonneg
826/;
827
828@EXPORT_file =qw/ fopen fclose/;
829@EXPORT_OK = (@EXPORT_all, @EXPORT_file);
830%EXPORT_TAGS = ( file => \@EXPORT_file, all => \@EXPORT_all );
831
832=encoding utf8
833
834=head1 NAME
835
836Math::GSL::Vector - Functions concerning vectors
837
838=head1 SYNOPSIS
839
840    use Math::GSL::Vector qw/:all/;
841    my $vec1 = Math::GSL::Vector->new([1, 7, 94, 15 ]);
842    my $vec2 = $vec1 * 5;
843    my $vec3 = Math::GSL::Vector>new(10);   # 10 element zero vector
844    my $vec4 = $vec1 + $vec2;
845
846    # set the element at index 1 to 9
847    # and the element at index 3 to 8
848    $vec3->set([ 1, 3 ], [ 9, 8 ]);
849
850    my @vec = $vec2->as_list;               # return elements as Perl list
851
852    my $dot_product = $vec1 * $vec2;
853    my $length      = $vec2->length;
854    my $first       = $vec1->get(0);
855
856    # access raw GSL object to call low-level functions
857    my $raw         = $vec1->raw;
858    my $element     = gsl_vector_get($raw, 2);
859
860=cut
861
862=head1 Objected Oriented Interface to GSL Math::GSL::Vector
863
864=head2 Math::GSL::Vector->new()
865
866Creates a new Vector of the given size.
867
868    my $vector = Math::GSL::Vector->new(3);
869
870You can also create and set directly the values of the vector like this :
871
872   my $vector = Math::GSL::Vector->new([2,4,1]);
873
874=cut
875
876sub new {
877    my ($class, $values) = @_;
878    my $length  = $#$values;
879    my $this = {};
880    my $vector;
881    if ( ref $values eq 'ARRAY' ){
882        die __PACKAGE__.'::new($x) - $x must be a nonempty array reference' if $length == -1;
883        $vector  = gsl_vector_alloc($length+1);
884        map { gsl_vector_set($vector, $_, $values->[$_] ) }  (0 .. $length);
885        $this->{_length} = $length+1;
886    } elsif ( (int($values) == $values) && ($values > 0)) {
887        $vector  = gsl_vector_alloc($values);
888        gsl_vector_set_zero($vector);
889        $this->{_length} = $values;
890    } else {
891        die __PACKAGE__.'::new($x) - $x must be an int or array reference';
892    }
893    $this->{_vector} = $vector;
894    bless $this, $class;
895}
896=head2 raw()
897
898Get the underlying GSL vector object created by SWIG, useful for using gsl_vector_* functions which do not have an OO counterpart.
899
900    my $vector    = Math::GSL::Vector->new(3);
901    my $gsl_vector = $vector->raw;
902    my $stuff      = gsl_vector_get($gsl_vector, 1);
903
904=cut
905
906sub raw {
907    my $self = shift;
908    return $self->{_vector};
909}
910
911=head2 swap()
912
913Exchanges the values in the vectors $v with $w by copying.
914
915    my $v = Math::GSL::Vector->new([1..5]);
916    my $w = Math::GSL::Vector->new([3..7]);
917    $v->swap( $w );
918
919=cut
920
921sub swap() {
922    my ($self,$other) = @_;
923    croak "Math::GSL::Vector: \$v->swap(\$w) : \$w must be a Math::GSL::Vector"
924        unless ref $other eq 'Math::GSL::Vector';
925    gsl_vector_swap( $self->raw, $other->raw );
926    return $self;
927}
928
929=head2 reverse()
930
931Reverse the elements in the vector.
932
933    $v->reverse;
934
935=cut
936
937sub reverse() {
938    my $self = shift;
939    gsl_vector_reverse($self->raw);
940    return $self;
941}
942
943=head2 min()
944
945Returns the minimum value contained in the vector.
946
947   my $vector = Math::GSL::Vector->new([2,4,1]);
948   my $minimum = $vector->min;
949
950=cut
951
952sub min {
953    my $self=shift;
954    return gsl_vector_min($self->raw);
955}
956
957=head2 max()
958
959Returns the minimum value contained in the vector.
960
961   my $vector = Math::GSL::Vector->new([2,4,1]);
962   my $maximum = $vector->max;
963
964=cut
965
966sub max {
967    my $self=shift;
968    return gsl_vector_max($self->raw);
969}
970
971=head2 length()
972
973Returns the number of elements contained in the vector.
974
975   my $vector = Math::GSL::Vector->new([2,4,1]);
976   my $length = $vector->length;
977
978=cut
979
980sub length { my $self=shift; $self->{_length} }
981
982=head2 $v->norm($p)
983
984Returns the p-norm of $v, which defaults to the Euclidean (p=2) norm when no argument is given.
985
986    my $euclidean_distance = $v->norm;
987
988=cut
989
990sub norm($;$)
991{
992    my ($self,$p) = @_;
993    my $norm = 0;
994    $p ||= 2;
995
996    map { $norm += $p == 1 ? abs $_ : $_ ** $p } ($self->as_list);
997    return $norm **  (1 / $p);
998}
999
1000=head2 normalize($p)
1001
1002Divide each element of a vector by its norm, hence creating a unit vector.
1003Returns the vector for chaining.  If you just want the value of the norm
1004without changing the vector, use C<norm()>. The default value for C<$p> is 2,
1005which gives the familiar Euclidean distance norm.
1006
1007    my $unit_vector = $vector->normalize(2);
1008
1009is the same as
1010
1011    my $unit_vector = $vector->normalize;
1012
1013=cut
1014
1015sub normalize($;$)
1016{
1017    my ($self,$p) = @_;
1018    $p ||= 2;
1019    my $norm = $self->norm($p);
1020    return $self if ($norm == 0);
1021
1022    my $status = gsl_vector_scale( $self->raw, 1/$norm );
1023    croak "Math::GSL::Vector - could not scale vectr" unless $status == $GSL_SUCCESS;
1024    return $self;
1025}
1026
1027=head2  as_list()
1028
1029Gets the content of a Math::GSL::Vector object as a Perl list.
1030
1031    my $vector = Math::GSL::Vector->new(3);
1032    ...
1033    my @values = $vector->as_list;
1034
1035=cut
1036
1037sub as_list {
1038    my $self=shift;
1039    $self->get( [ 0 .. $self->length - 1  ] );
1040}
1041
1042=head2  get()
1043
1044Gets the value of an of a Math::GSL::Vector object.
1045
1046    my $vector = Math::GSL::Vector->new(3);
1047    ...
1048    my @values = $vector->get(2);
1049
1050You can also enter an array of indices to receive their corresponding values:
1051
1052    my $vector = Math::GSL::Vector->new(3);
1053    ...
1054    my @values = $vector->get([0,2]);
1055
1056=cut
1057
1058sub get {
1059    my ($self, $indices) = @_;
1060
1061    return gsl_vector_get($self->raw, $indices) unless ref $indices;
1062
1063    return  map {  gsl_vector_get($self->raw, $_ ) } @$indices ;
1064}
1065
1066=head2  set()
1067
1068Sets values of an of a Math::GSL::Vector object.
1069
1070    my $vector = Math::GSL::Vector->new(3);
1071    $vector->set([1,2], [8,23]);
1072
1073This sets the second and third value to 8 and 23.
1074
1075=cut
1076
1077sub set {
1078    my ($self, $indices, $values) = @_;
1079    die (__PACKAGE__.'::set($indices, $values) - $indices and $values must be array references of the same length')
1080        unless ( ref $indices eq 'ARRAY' && ref $values eq 'ARRAY' &&  $#$indices == $#$values );
1081    eval {
1082        map {  gsl_vector_set($self->{_vector}, $indices->[$_], $values->[$_] ) } (0..$#$indices);
1083    };
1084    return;
1085}
1086
1087=head2 copy()
1088
1089Returns a copy of the vector, which has the same length and values but resides at a different location in memory.
1090
1091    my $vector = Math::GSL::Vector->new([10 .. 20]);
1092    my $copy   = $vector->copy;
1093
1094=cut
1095
1096
1097sub copy {
1098    my $self = shift;
1099    my $copy = Math::GSL::Vector->new( $self->length );
1100    if ( gsl_vector_memcpy($copy->raw, $self->raw) != $GSL_SUCCESS ) {
1101        croak "Math::GSL - error copying memory, aborting";
1102    }
1103    return $copy;
1104}
1105
1106sub _multiplication {
1107    my ($left,$right) = @_;
1108    my $lcopy = $left->copy;
1109
1110    if ( blessed $right && $right->isa('Math::GSL::Vector') ) {
1111        return $lcopy->dot_product($right);
1112    } else {
1113        gsl_vector_scale($lcopy->raw, $right);
1114    }
1115    return $lcopy;
1116}
1117
1118sub _subtract {
1119    my ($left, $right, $flip) = @_;
1120
1121    if ($flip) {
1122        my $lcopy = $left->copy;
1123        gsl_vector_scale($lcopy->raw, -1 );
1124        gsl_vector_add_constant($lcopy->raw, $right);
1125        return $lcopy;
1126    } else {
1127        return _addition($left, -1.0*$right);
1128    }
1129}
1130
1131sub _abs {
1132    my $self = shift;
1133    $self->norm;
1134}
1135
1136sub _addition {
1137    my ($left, $right, $flip) = @_;
1138
1139    my $lcopy = $left->copy;
1140
1141    if ( blessed $right && $right->isa('Math::GSL::Vector') && blessed $left && $left->isa('Math::GSL::Vector') ) {
1142        if ( $left->length == $right->length ) {
1143            gsl_vector_add($lcopy->raw, $right->raw);
1144        } else {
1145            croak "Math::GSL - addition of vectors must be called with two objects vectors and must have the same length";
1146        }
1147    } else {
1148        gsl_vector_add_constant($lcopy->raw, $right);
1149    }
1150    return $lcopy;
1151}
1152
1153sub dot_product_pp {
1154    my ($left,$right) = @_;
1155    my $sum=0;
1156    if ( blessed $right && $right->isa('Math::GSL::Vector') &&
1157         $left->length == $right->length ) {
1158         my @l = $left->as_list;
1159         my @r = $right->as_list;
1160         map { $sum += $l[$_] * $r[$_] } (0..$#l);
1161        return $sum;
1162    } else {
1163        croak "dot_product() must be called with two vectors";
1164    }
1165}
1166
1167sub dot_product {
1168    my ($left,$right) = @_;
1169
1170    my ($status, $product) = gsl_blas_ddot($left->raw,$right->raw);
1171    croak sprintf "Math::GSL::dot_product - %s", gsl_strerror($status) if ($status != $GSL_SUCCESS);
1172    return $product;
1173}
1174
1175sub _equal {
1176    my ($left,$right) = @_;
1177
1178    return 0 if ($left->length != $right->length);
1179
1180    return is_similar(  [$left->as_list ], [$right->as_list ]);
1181}
1182
1183sub _not_equal {
1184    my ($left, $right) = @_;
1185    return !_equal($left,$right);
1186}
1187
1188=head1 DESCRIPTION
1189
1190Here is a list of all the functions included in this module :
1191
1192=over 1
1193
1194=item C<gsl_vector_alloc($x)>
1195
1196Create a vector of size $x
1197
1198=item C<gsl_vector_calloc($x)>
1199
1200Create a vector of size $x and initializes all the elements of the vector to zero
1201
1202=item C<gsl_vector_alloc_from_block>
1203
1204=item C<gsl_vector_alloc_from_vector>
1205
1206=item C<gsl_vector_free($v)>
1207
1208Free a previously allocated vector $v
1209
1210=item C<gsl_vector_view_array($base, $n)>
1211
1212This function returns a vector view of an array reference $base. The start of
1213the new vector is given by $base and has $n elements. Mathematically, the i-th
1214element of the new vector v' is given by, v'(i) = $base->[i] where the index i
1215runs from 0 to $n-1. The array containing the elements of v is not owned by the
1216new vector view. When the view goes out of scope the original array will
1217continue to exist. The original memory can only be deallocated by freeing the
1218original pointer base. Of course, the original array should not be deallocated
1219while the view is still in use.
1220
1221=item C<gsl_vector_const_view_array($base, $n)>
1222
1223This function is equivalent to gsl_vector_view_array but can be used for arrays which are declared const.
1224
1225=item C<gsl_vector_view_array_with_stride($base, $stride, $n)>
1226
1227This function returns a vector view of an array reference $base with an
1228additional $stride argument. The subvector is formed in the same way as for
1229gsl_vector_view_array but the new vector has $n elements with a step-size of
1230$stride from one element to the next in the original array. Mathematically,
1231the i-th element of the new vector v' is given by, v'(i) = $base->[i*$stride]
1232where the index i runs from 0 to $n-1. Note that the view gives direct access
1233to the underlying elements of the original array. A vector view $view can be
1234passed to any subroutine which takes a vector argument just as a directly
1235allocated vector would be, using $view->{vector}.
1236
1237=item C<gsl_vector_const_view_array_with_stride($base, $stride, $n)>
1238
1239This function is equivalent to gsl_vector_view_array_with_stride but can be
1240used for arrays which are declared const.
1241
1242=item C<gsl_vector_subvector($v, $offset, $n)>
1243
1244Return a vector_view type which contains a subvector of $v, with a size of $size, starting from the $offset position
1245
1246=item C<gsl_vector_subvector_with_stride($v, $offset, $stride, $size)>
1247
1248Return a vector_view type which contains a subvector of $v, with a size of
1249$size, starting from the $offset position and with a $stride step between each
1250element of $v
1251
1252=item C<gsl_vector_const_subvector>
1253
1254
1255=item C<gsl_vector_get($v, $i)>
1256
1257Return the $i-th element of a raw vector $v, where $v is a Math::GSL::Vector object. For example:
1258
1259    my $third_element = gsl_vector_get($v->raw, 3);
1260
1261=item C<gsl_vector_set($v, $i, $x)>
1262
1263Return the vector $v with his $i-th element set to $x
1264
1265=item C<gsl_vector_ptr>
1266
1267=item C<gsl_vector_const_ptr>
1268
1269=item C<gsl_vector_set_zero($v)>
1270
1271 set all the elements of $v to 0
1272
1273=item C<gsl_vector_set_all($v, $x)>
1274
1275set all the elements of $v to $x
1276
1277=item C<gsl_vector_set_basis($v, $i)>
1278
1279set all the elements of $v to 0 except for the $i-th element which is set to 1
1280and return 0 if the operation succeded, 1 otherwise.
1281
1282=item C<gsl_vector_fread($file, $v)>
1283
1284This function reads into the vector $v from the open stream $file opened with
1285gsl_fopen function from the Math::GSL module in binary format. The vector $v
1286must be preallocated with the correct length since the function uses the size
1287of $v to determine how many bytes to read. The return value is 0 for success
1288and 1 if there was a problem reading from the file.
1289
1290=item C<gsl_vector_fwrite($file, $v)>
1291
1292This function writes the elements of the vector $v to the stream $file opened
1293with gsl_fopen function from the Math::GSL module in binary format. The return
1294value is 0 for success and 1 if there was a problem writing to the file. Since
1295the data is written in the native binary format it may not be portable between
1296different architectures.
1297
1298=item C<gsl_vector_fscanf($file, $v)>
1299
1300This function reads formatted data from the stream $file opened with gsl_fopen
1301function from the Math::GSL module into the vector $v. The vector $v must be
1302preallocated with the correct length since the function uses the size of $v to
1303determine how many numbers to read. The function returns 0 for success and 1 if
1304there was a problem reading from the file.
1305
1306=item C<gsl_vector_fprintf($file, $v, $format)>
1307
1308This function writes the elements of the vector $v line-by-line to the stream
1309$file opened with gsl_fopen function from the Math::GSL module using the format
1310specifier $format, which should be one of the "%g", "%e" or "%f" formats for
1311floating point numbers and "%d" for integers. The function returns 0 for
1312success and 1 if there was a problem writing to the file.
1313
1314=item C<gsl_vector_memcpy($dest, $src)>
1315
1316This function copies the elements of the vector $src into the vector $dest and
1317return 0 if the opertaion succeded, 1 otherwise. The two vectors must have the
1318same length.
1319
1320=item C<gsl_vector_reverse($v)>
1321
1322reverse the order of the elements of the vector $v and return 0 if the
1323opertaion succeded, 1 otherwise
1324
1325=item C<gsl_vector_swap($v, $v2)>
1326
1327swap the values of the vectors $v and $v2 and return 0 if the opertaion
1328succeded, 1 otherwise
1329
1330=item C<gsl_vector_swap_elements($v, $i, $j)>
1331
1332permute the elements at position $i and $j in the vector $v and return 0 if the
1333operation succeded, 1 otherwise.
1334
1335=item C<gsl_vector_max($v)>
1336
1337 return the maximum value in the vector $v
1338
1339=item C<gsl_vector_min($v)>
1340
1341return the minimum value in the vector $v
1342
1343=item C<gsl_vector_minmax($v)>
1344
1345return two values, the first is the minimum value in the vector $v and the
1346second is the maximum value.
1347
1348=item C<gsl_vector_max_index($v)>
1349
1350return the position of the maximum value in the vector $v
1351
1352=item C<gsl_vector_min_index($v)>
1353
1354return the position of the minimum value in the vector $v
1355
1356=item C<gsl_vector_minmax_index>
1357
1358return two values, the first is the position of the minimum value in the vector
1359$v and the second is the position of the maximum value.
1360
1361=item C<gsl_vector_add($v, $v2)>
1362
1363add the elements of $v2 to the elements of $v, the two vectors must have the
1364same length and return 0 if the operation succeded, 1 otherwise.
1365
1366=item C<gsl_vector_sub($v, $v2)>
1367
1368substract the elements of $v2 from the elements of $v, the two vectors must
1369have the same length and return 0 if the operation succeded, 1 otherwise.
1370
1371=item C<gsl_vector_mul($v, $v2)>
1372
1373multiply the elements of $v by the elements of $v2, the two vectors must have
1374the same length and return 0 if the operation succeded, 1 otherwise.
1375
1376=item C<gsl_vector_div($v, $v2)>
1377
1378divides the elements of $v by the elements of $v2, the two vectors must have
1379the same length and return 0 if the operation succeded, 1 otherwise.
1380
1381=item C<gsl_vector_scale($v, $x)>
1382
1383multiplty the elements of the vector $v by a constant $x and return 0 if the
1384operation succeded, 1 otherwise.
1385
1386=item C<gsl_vector_add_constant($v, $x)>
1387
1388add a constant $x to the elements of the vector $v and return 0 if the
1389operation succeded, 1 otherwise.
1390
1391=item C<gsl_vector_isnull($v)>
1392
1393verify if all the elements of the vector $v are null, return 0 if it's the
1394case, 1 otherwise.
1395
1396=item C<gsl_vector_ispos($v)>
1397
1398verify if all the elements of the vector $v are positive, return 0 if it's the
1399case, 1 otherwise.
1400
1401=item C<gsl_vector_isneg($v)>
1402
1403verify if all the elements of the vector $v are negative, return 0 if it's the
1404case, 1 otherwise.
1405
1406=item C<gsl_vector_isnonneg($v)>
1407
1408verify if all the elements the vector $v are not negative, return 0 if it's the
1409case, 1 otherwise.
1410
1411=back
1412
1413Precision on the vector_view type : every modification you'll make on a
1414vector_view will also modify the original vector.  For example, the following
1415code will zero the even elements of the vector $v of length $size, while
1416leaving the odd elements untouched :
1417
1418=over 1
1419
1420=item C<$v_even= gsl_vector_subvector_with_stride ($v, 0, 2, $size/2);>
1421
1422=item C<gsl_vector_set_zero ($v_even-E<gt>{vector});>
1423
1424=back
1425
1426For more informations on the functions, we refer you to the GSL official documentation:
1427L<http://www.gnu.org/software/gsl/manual/html_node/>
1428
1429=head1 EXAMPLES
1430
1431Here is an example using both interfaces.
1432
1433    use Math::GSL::Vector qw/:all/;
1434
1435    print "We'll create this vector : [0,1,4,9,16] \n";
1436    my $vector = Math::GSL::Vector->new([0,1,4,9,16]);
1437    my ($min, $max) = gsl_vector_minmax_index($vector->raw);
1438
1439    print "We then check the index value of the maximum and minimum values of the vector. \n";
1440    print "The index of the maximum should be 4 and we received $max \n";
1441    print "The index of the minimum should be 0 and we received $min \n";
1442    print "We'll then swap the first and the third elements of the vector \n";
1443
1444    gsl_vector_swap_elements($vector->raw, 0, 3);
1445    my @got = $vector->as_list;
1446    print "The vector should now be like this : [9,1,4,0,16] \n";
1447    print "and we received : [ @got ]\n";
1448
1449=head1 AUTHORS
1450
1451Jonathan "Duke" Leto <jonathan@leto.net> and Thierry Moisan <thierry.moisan@gmail.com>
1452
1453=head1 COPYRIGHT AND LICENSE
1454
1455Copyright (C) 2008-2021 Jonathan "Duke" Leto and Thierry Moisan
1456
1457This program is free software; you can redistribute it and/or modify it
1458under the same terms as Perl itself.
1459
1460=cut
14611;
1462