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::MatrixComplex;
8use base qw(Exporter);
9use base qw(DynaLoader);
10package Math::GSL::MatrixComplexc;
11bootstrap Math::GSL::MatrixComplex;
12package Math::GSL::MatrixComplex;
13@EXPORT = qw();
14
15# ---------- BASE METHODS -------------
16
17package Math::GSL::MatrixComplex;
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::MatrixComplex;
51
52*gsl_error = *Math::GSL::MatrixComplexc::gsl_error;
53*gsl_stream_printf = *Math::GSL::MatrixComplexc::gsl_stream_printf;
54*gsl_strerror = *Math::GSL::MatrixComplexc::gsl_strerror;
55*gsl_set_error_handler = *Math::GSL::MatrixComplexc::gsl_set_error_handler;
56*gsl_set_error_handler_off = *Math::GSL::MatrixComplexc::gsl_set_error_handler_off;
57*gsl_set_stream_handler = *Math::GSL::MatrixComplexc::gsl_set_stream_handler;
58*gsl_set_stream = *Math::GSL::MatrixComplexc::gsl_set_stream;
59*gsl_vector_alloc = *Math::GSL::MatrixComplexc::gsl_vector_alloc;
60*gsl_vector_calloc = *Math::GSL::MatrixComplexc::gsl_vector_calloc;
61*gsl_vector_alloc_from_block = *Math::GSL::MatrixComplexc::gsl_vector_alloc_from_block;
62*gsl_vector_alloc_from_vector = *Math::GSL::MatrixComplexc::gsl_vector_alloc_from_vector;
63*gsl_vector_free = *Math::GSL::MatrixComplexc::gsl_vector_free;
64*gsl_vector_view_array = *Math::GSL::MatrixComplexc::gsl_vector_view_array;
65*gsl_vector_view_array_with_stride = *Math::GSL::MatrixComplexc::gsl_vector_view_array_with_stride;
66*gsl_vector_const_view_array = *Math::GSL::MatrixComplexc::gsl_vector_const_view_array;
67*gsl_vector_const_view_array_with_stride = *Math::GSL::MatrixComplexc::gsl_vector_const_view_array_with_stride;
68*gsl_vector_subvector = *Math::GSL::MatrixComplexc::gsl_vector_subvector;
69*gsl_vector_subvector_with_stride = *Math::GSL::MatrixComplexc::gsl_vector_subvector_with_stride;
70*gsl_vector_const_subvector = *Math::GSL::MatrixComplexc::gsl_vector_const_subvector;
71*gsl_vector_const_subvector_with_stride = *Math::GSL::MatrixComplexc::gsl_vector_const_subvector_with_stride;
72*gsl_vector_set_zero = *Math::GSL::MatrixComplexc::gsl_vector_set_zero;
73*gsl_vector_set_all = *Math::GSL::MatrixComplexc::gsl_vector_set_all;
74*gsl_vector_set_basis = *Math::GSL::MatrixComplexc::gsl_vector_set_basis;
75*gsl_vector_fread = *Math::GSL::MatrixComplexc::gsl_vector_fread;
76*gsl_vector_fwrite = *Math::GSL::MatrixComplexc::gsl_vector_fwrite;
77*gsl_vector_fscanf = *Math::GSL::MatrixComplexc::gsl_vector_fscanf;
78*gsl_vector_fprintf = *Math::GSL::MatrixComplexc::gsl_vector_fprintf;
79*gsl_vector_memcpy = *Math::GSL::MatrixComplexc::gsl_vector_memcpy;
80*gsl_vector_reverse = *Math::GSL::MatrixComplexc::gsl_vector_reverse;
81*gsl_vector_swap = *Math::GSL::MatrixComplexc::gsl_vector_swap;
82*gsl_vector_swap_elements = *Math::GSL::MatrixComplexc::gsl_vector_swap_elements;
83*gsl_vector_max = *Math::GSL::MatrixComplexc::gsl_vector_max;
84*gsl_vector_min = *Math::GSL::MatrixComplexc::gsl_vector_min;
85*gsl_vector_minmax = *Math::GSL::MatrixComplexc::gsl_vector_minmax;
86*gsl_vector_max_index = *Math::GSL::MatrixComplexc::gsl_vector_max_index;
87*gsl_vector_min_index = *Math::GSL::MatrixComplexc::gsl_vector_min_index;
88*gsl_vector_minmax_index = *Math::GSL::MatrixComplexc::gsl_vector_minmax_index;
89*gsl_vector_add = *Math::GSL::MatrixComplexc::gsl_vector_add;
90*gsl_vector_sub = *Math::GSL::MatrixComplexc::gsl_vector_sub;
91*gsl_vector_mul = *Math::GSL::MatrixComplexc::gsl_vector_mul;
92*gsl_vector_div = *Math::GSL::MatrixComplexc::gsl_vector_div;
93*gsl_vector_scale = *Math::GSL::MatrixComplexc::gsl_vector_scale;
94*gsl_vector_add_constant = *Math::GSL::MatrixComplexc::gsl_vector_add_constant;
95*gsl_vector_axpby = *Math::GSL::MatrixComplexc::gsl_vector_axpby;
96*gsl_vector_sum = *Math::GSL::MatrixComplexc::gsl_vector_sum;
97*gsl_vector_equal = *Math::GSL::MatrixComplexc::gsl_vector_equal;
98*gsl_vector_isnull = *Math::GSL::MatrixComplexc::gsl_vector_isnull;
99*gsl_vector_ispos = *Math::GSL::MatrixComplexc::gsl_vector_ispos;
100*gsl_vector_isneg = *Math::GSL::MatrixComplexc::gsl_vector_isneg;
101*gsl_vector_isnonneg = *Math::GSL::MatrixComplexc::gsl_vector_isnonneg;
102*gsl_vector_get = *Math::GSL::MatrixComplexc::gsl_vector_get;
103*gsl_vector_set = *Math::GSL::MatrixComplexc::gsl_vector_set;
104*gsl_vector_ptr = *Math::GSL::MatrixComplexc::gsl_vector_ptr;
105*gsl_vector_const_ptr = *Math::GSL::MatrixComplexc::gsl_vector_const_ptr;
106*gsl_matrix_complex_alloc = *Math::GSL::MatrixComplexc::gsl_matrix_complex_alloc;
107*gsl_matrix_complex_calloc = *Math::GSL::MatrixComplexc::gsl_matrix_complex_calloc;
108*gsl_matrix_complex_alloc_from_block = *Math::GSL::MatrixComplexc::gsl_matrix_complex_alloc_from_block;
109*gsl_matrix_complex_alloc_from_matrix = *Math::GSL::MatrixComplexc::gsl_matrix_complex_alloc_from_matrix;
110*gsl_vector_complex_alloc_row_from_matrix = *Math::GSL::MatrixComplexc::gsl_vector_complex_alloc_row_from_matrix;
111*gsl_vector_complex_alloc_col_from_matrix = *Math::GSL::MatrixComplexc::gsl_vector_complex_alloc_col_from_matrix;
112*gsl_matrix_complex_free = *Math::GSL::MatrixComplexc::gsl_matrix_complex_free;
113*gsl_matrix_complex_submatrix = *Math::GSL::MatrixComplexc::gsl_matrix_complex_submatrix;
114*gsl_matrix_complex_row = *Math::GSL::MatrixComplexc::gsl_matrix_complex_row;
115*gsl_matrix_complex_column = *Math::GSL::MatrixComplexc::gsl_matrix_complex_column;
116*gsl_matrix_complex_diagonal = *Math::GSL::MatrixComplexc::gsl_matrix_complex_diagonal;
117*gsl_matrix_complex_subdiagonal = *Math::GSL::MatrixComplexc::gsl_matrix_complex_subdiagonal;
118*gsl_matrix_complex_superdiagonal = *Math::GSL::MatrixComplexc::gsl_matrix_complex_superdiagonal;
119*gsl_matrix_complex_subrow = *Math::GSL::MatrixComplexc::gsl_matrix_complex_subrow;
120*gsl_matrix_complex_subcolumn = *Math::GSL::MatrixComplexc::gsl_matrix_complex_subcolumn;
121*gsl_matrix_complex_view_array = *Math::GSL::MatrixComplexc::gsl_matrix_complex_view_array;
122*gsl_matrix_complex_view_array_with_tda = *Math::GSL::MatrixComplexc::gsl_matrix_complex_view_array_with_tda;
123*gsl_matrix_complex_view_vector = *Math::GSL::MatrixComplexc::gsl_matrix_complex_view_vector;
124*gsl_matrix_complex_view_vector_with_tda = *Math::GSL::MatrixComplexc::gsl_matrix_complex_view_vector_with_tda;
125*gsl_matrix_complex_const_submatrix = *Math::GSL::MatrixComplexc::gsl_matrix_complex_const_submatrix;
126*gsl_matrix_complex_const_row = *Math::GSL::MatrixComplexc::gsl_matrix_complex_const_row;
127*gsl_matrix_complex_const_column = *Math::GSL::MatrixComplexc::gsl_matrix_complex_const_column;
128*gsl_matrix_complex_const_diagonal = *Math::GSL::MatrixComplexc::gsl_matrix_complex_const_diagonal;
129*gsl_matrix_complex_const_subdiagonal = *Math::GSL::MatrixComplexc::gsl_matrix_complex_const_subdiagonal;
130*gsl_matrix_complex_const_superdiagonal = *Math::GSL::MatrixComplexc::gsl_matrix_complex_const_superdiagonal;
131*gsl_matrix_complex_const_subrow = *Math::GSL::MatrixComplexc::gsl_matrix_complex_const_subrow;
132*gsl_matrix_complex_const_subcolumn = *Math::GSL::MatrixComplexc::gsl_matrix_complex_const_subcolumn;
133*gsl_matrix_complex_const_view_array = *Math::GSL::MatrixComplexc::gsl_matrix_complex_const_view_array;
134*gsl_matrix_complex_const_view_array_with_tda = *Math::GSL::MatrixComplexc::gsl_matrix_complex_const_view_array_with_tda;
135*gsl_matrix_complex_const_view_vector = *Math::GSL::MatrixComplexc::gsl_matrix_complex_const_view_vector;
136*gsl_matrix_complex_const_view_vector_with_tda = *Math::GSL::MatrixComplexc::gsl_matrix_complex_const_view_vector_with_tda;
137*gsl_matrix_complex_set_zero = *Math::GSL::MatrixComplexc::gsl_matrix_complex_set_zero;
138*gsl_matrix_complex_set_identity = *Math::GSL::MatrixComplexc::gsl_matrix_complex_set_identity;
139*gsl_matrix_complex_set_all = *Math::GSL::MatrixComplexc::gsl_matrix_complex_set_all;
140*gsl_matrix_complex_fread = *Math::GSL::MatrixComplexc::gsl_matrix_complex_fread;
141*gsl_matrix_complex_fwrite = *Math::GSL::MatrixComplexc::gsl_matrix_complex_fwrite;
142*gsl_matrix_complex_fscanf = *Math::GSL::MatrixComplexc::gsl_matrix_complex_fscanf;
143*gsl_matrix_complex_fprintf = *Math::GSL::MatrixComplexc::gsl_matrix_complex_fprintf;
144*gsl_matrix_complex_memcpy = *Math::GSL::MatrixComplexc::gsl_matrix_complex_memcpy;
145*gsl_matrix_complex_swap = *Math::GSL::MatrixComplexc::gsl_matrix_complex_swap;
146*gsl_matrix_complex_tricpy = *Math::GSL::MatrixComplexc::gsl_matrix_complex_tricpy;
147*gsl_matrix_complex_swap_rows = *Math::GSL::MatrixComplexc::gsl_matrix_complex_swap_rows;
148*gsl_matrix_complex_swap_columns = *Math::GSL::MatrixComplexc::gsl_matrix_complex_swap_columns;
149*gsl_matrix_complex_swap_rowcol = *Math::GSL::MatrixComplexc::gsl_matrix_complex_swap_rowcol;
150*gsl_matrix_complex_transpose = *Math::GSL::MatrixComplexc::gsl_matrix_complex_transpose;
151*gsl_matrix_complex_transpose_memcpy = *Math::GSL::MatrixComplexc::gsl_matrix_complex_transpose_memcpy;
152*gsl_matrix_complex_transpose_tricpy = *Math::GSL::MatrixComplexc::gsl_matrix_complex_transpose_tricpy;
153*gsl_matrix_complex_conjtrans_memcpy = *Math::GSL::MatrixComplexc::gsl_matrix_complex_conjtrans_memcpy;
154*gsl_matrix_complex_equal = *Math::GSL::MatrixComplexc::gsl_matrix_complex_equal;
155*gsl_matrix_complex_isnull = *Math::GSL::MatrixComplexc::gsl_matrix_complex_isnull;
156*gsl_matrix_complex_ispos = *Math::GSL::MatrixComplexc::gsl_matrix_complex_ispos;
157*gsl_matrix_complex_isneg = *Math::GSL::MatrixComplexc::gsl_matrix_complex_isneg;
158*gsl_matrix_complex_isnonneg = *Math::GSL::MatrixComplexc::gsl_matrix_complex_isnonneg;
159*gsl_matrix_complex_add = *Math::GSL::MatrixComplexc::gsl_matrix_complex_add;
160*gsl_matrix_complex_sub = *Math::GSL::MatrixComplexc::gsl_matrix_complex_sub;
161*gsl_matrix_complex_mul_elements = *Math::GSL::MatrixComplexc::gsl_matrix_complex_mul_elements;
162*gsl_matrix_complex_div_elements = *Math::GSL::MatrixComplexc::gsl_matrix_complex_div_elements;
163*gsl_matrix_complex_scale = *Math::GSL::MatrixComplexc::gsl_matrix_complex_scale;
164*gsl_matrix_complex_scale_rows = *Math::GSL::MatrixComplexc::gsl_matrix_complex_scale_rows;
165*gsl_matrix_complex_scale_columns = *Math::GSL::MatrixComplexc::gsl_matrix_complex_scale_columns;
166*gsl_matrix_complex_add_constant = *Math::GSL::MatrixComplexc::gsl_matrix_complex_add_constant;
167*gsl_matrix_complex_add_diagonal = *Math::GSL::MatrixComplexc::gsl_matrix_complex_add_diagonal;
168*gsl_matrix_complex_get_row = *Math::GSL::MatrixComplexc::gsl_matrix_complex_get_row;
169*gsl_matrix_complex_get_col = *Math::GSL::MatrixComplexc::gsl_matrix_complex_get_col;
170*gsl_matrix_complex_set_row = *Math::GSL::MatrixComplexc::gsl_matrix_complex_set_row;
171*gsl_matrix_complex_set_col = *Math::GSL::MatrixComplexc::gsl_matrix_complex_set_col;
172*gsl_matrix_complex_get = *Math::GSL::MatrixComplexc::gsl_matrix_complex_get;
173*gsl_matrix_complex_set = *Math::GSL::MatrixComplexc::gsl_matrix_complex_set;
174*gsl_matrix_complex_ptr = *Math::GSL::MatrixComplexc::gsl_matrix_complex_ptr;
175*gsl_matrix_complex_const_ptr = *Math::GSL::MatrixComplexc::gsl_matrix_complex_const_ptr;
176
177############# Class : Math::GSL::MatrixComplex::gsl_complex ##############
178
179package Math::GSL::MatrixComplex::gsl_complex;
180use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
181@ISA = qw( Math::GSL::MatrixComplex );
182%OWNER = ();
183%ITERATORS = ();
184*swig_dat_get = *Math::GSL::MatrixComplexc::gsl_complex_dat_get;
185*swig_dat_set = *Math::GSL::MatrixComplexc::gsl_complex_dat_set;
186sub new {
187    my $pkg = shift;
188    my $self = Math::GSL::MatrixComplexc::new_gsl_complex(@_);
189    bless $self, $pkg if defined($self);
190}
191
192sub DESTROY {
193    return unless $_[0]->isa('HASH');
194    my $self = tied(%{$_[0]});
195    return unless defined $self;
196    delete $ITERATORS{$self};
197    if (exists $OWNER{$self}) {
198        Math::GSL::MatrixComplexc::delete_gsl_complex($self);
199        delete $OWNER{$self};
200    }
201}
202
203sub DISOWN {
204    my $self = shift;
205    my $ptr = tied(%$self);
206    delete $OWNER{$ptr};
207}
208
209sub ACQUIRE {
210    my $self = shift;
211    my $ptr = tied(%$self);
212    $OWNER{$ptr} = 1;
213}
214
215
216############# Class : Math::GSL::MatrixComplex::gsl_complex_long_double ##############
217
218package Math::GSL::MatrixComplex::gsl_complex_long_double;
219use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
220@ISA = qw( Math::GSL::MatrixComplex );
221%OWNER = ();
222%ITERATORS = ();
223*swig_dat_get = *Math::GSL::MatrixComplexc::gsl_complex_long_double_dat_get;
224*swig_dat_set = *Math::GSL::MatrixComplexc::gsl_complex_long_double_dat_set;
225sub new {
226    my $pkg = shift;
227    my $self = Math::GSL::MatrixComplexc::new_gsl_complex_long_double(@_);
228    bless $self, $pkg if defined($self);
229}
230
231sub DESTROY {
232    return unless $_[0]->isa('HASH');
233    my $self = tied(%{$_[0]});
234    return unless defined $self;
235    delete $ITERATORS{$self};
236    if (exists $OWNER{$self}) {
237        Math::GSL::MatrixComplexc::delete_gsl_complex_long_double($self);
238        delete $OWNER{$self};
239    }
240}
241
242sub DISOWN {
243    my $self = shift;
244    my $ptr = tied(%$self);
245    delete $OWNER{$ptr};
246}
247
248sub ACQUIRE {
249    my $self = shift;
250    my $ptr = tied(%$self);
251    $OWNER{$ptr} = 1;
252}
253
254
255############# Class : Math::GSL::MatrixComplex::gsl_complex_float ##############
256
257package Math::GSL::MatrixComplex::gsl_complex_float;
258use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
259@ISA = qw( Math::GSL::MatrixComplex );
260%OWNER = ();
261%ITERATORS = ();
262*swig_dat_get = *Math::GSL::MatrixComplexc::gsl_complex_float_dat_get;
263*swig_dat_set = *Math::GSL::MatrixComplexc::gsl_complex_float_dat_set;
264sub new {
265    my $pkg = shift;
266    my $self = Math::GSL::MatrixComplexc::new_gsl_complex_float(@_);
267    bless $self, $pkg if defined($self);
268}
269
270sub DESTROY {
271    return unless $_[0]->isa('HASH');
272    my $self = tied(%{$_[0]});
273    return unless defined $self;
274    delete $ITERATORS{$self};
275    if (exists $OWNER{$self}) {
276        Math::GSL::MatrixComplexc::delete_gsl_complex_float($self);
277        delete $OWNER{$self};
278    }
279}
280
281sub DISOWN {
282    my $self = shift;
283    my $ptr = tied(%$self);
284    delete $OWNER{$ptr};
285}
286
287sub ACQUIRE {
288    my $self = shift;
289    my $ptr = tied(%$self);
290    $OWNER{$ptr} = 1;
291}
292
293
294############# Class : Math::GSL::MatrixComplex::gsl_vector ##############
295
296package Math::GSL::MatrixComplex::gsl_vector;
297use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
298@ISA = qw( Math::GSL::MatrixComplex );
299%OWNER = ();
300%ITERATORS = ();
301*swig_size_get = *Math::GSL::MatrixComplexc::gsl_vector_size_get;
302*swig_size_set = *Math::GSL::MatrixComplexc::gsl_vector_size_set;
303*swig_stride_get = *Math::GSL::MatrixComplexc::gsl_vector_stride_get;
304*swig_stride_set = *Math::GSL::MatrixComplexc::gsl_vector_stride_set;
305*swig_data_get = *Math::GSL::MatrixComplexc::gsl_vector_data_get;
306*swig_data_set = *Math::GSL::MatrixComplexc::gsl_vector_data_set;
307*swig_block_get = *Math::GSL::MatrixComplexc::gsl_vector_block_get;
308*swig_block_set = *Math::GSL::MatrixComplexc::gsl_vector_block_set;
309*swig_owner_get = *Math::GSL::MatrixComplexc::gsl_vector_owner_get;
310*swig_owner_set = *Math::GSL::MatrixComplexc::gsl_vector_owner_set;
311sub new {
312    my $pkg = shift;
313    my $self = Math::GSL::MatrixComplexc::new_gsl_vector(@_);
314    bless $self, $pkg if defined($self);
315}
316
317sub DESTROY {
318    return unless $_[0]->isa('HASH');
319    my $self = tied(%{$_[0]});
320    return unless defined $self;
321    delete $ITERATORS{$self};
322    if (exists $OWNER{$self}) {
323        Math::GSL::MatrixComplexc::delete_gsl_vector($self);
324        delete $OWNER{$self};
325    }
326}
327
328sub DISOWN {
329    my $self = shift;
330    my $ptr = tied(%$self);
331    delete $OWNER{$ptr};
332}
333
334sub ACQUIRE {
335    my $self = shift;
336    my $ptr = tied(%$self);
337    $OWNER{$ptr} = 1;
338}
339
340
341############# Class : Math::GSL::MatrixComplex::_gsl_vector_view ##############
342
343package Math::GSL::MatrixComplex::_gsl_vector_view;
344use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
345@ISA = qw( Math::GSL::MatrixComplex );
346%OWNER = ();
347%ITERATORS = ();
348*swig_vector_get = *Math::GSL::MatrixComplexc::_gsl_vector_view_vector_get;
349*swig_vector_set = *Math::GSL::MatrixComplexc::_gsl_vector_view_vector_set;
350sub new {
351    my $pkg = shift;
352    my $self = Math::GSL::MatrixComplexc::new__gsl_vector_view(@_);
353    bless $self, $pkg if defined($self);
354}
355
356sub DESTROY {
357    return unless $_[0]->isa('HASH');
358    my $self = tied(%{$_[0]});
359    return unless defined $self;
360    delete $ITERATORS{$self};
361    if (exists $OWNER{$self}) {
362        Math::GSL::MatrixComplexc::delete__gsl_vector_view($self);
363        delete $OWNER{$self};
364    }
365}
366
367sub DISOWN {
368    my $self = shift;
369    my $ptr = tied(%$self);
370    delete $OWNER{$ptr};
371}
372
373sub ACQUIRE {
374    my $self = shift;
375    my $ptr = tied(%$self);
376    $OWNER{$ptr} = 1;
377}
378
379
380############# Class : Math::GSL::MatrixComplex::_gsl_vector_const_view ##############
381
382package Math::GSL::MatrixComplex::_gsl_vector_const_view;
383use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
384@ISA = qw( Math::GSL::MatrixComplex );
385%OWNER = ();
386%ITERATORS = ();
387*swig_vector_get = *Math::GSL::MatrixComplexc::_gsl_vector_const_view_vector_get;
388*swig_vector_set = *Math::GSL::MatrixComplexc::_gsl_vector_const_view_vector_set;
389sub new {
390    my $pkg = shift;
391    my $self = Math::GSL::MatrixComplexc::new__gsl_vector_const_view(@_);
392    bless $self, $pkg if defined($self);
393}
394
395sub DESTROY {
396    return unless $_[0]->isa('HASH');
397    my $self = tied(%{$_[0]});
398    return unless defined $self;
399    delete $ITERATORS{$self};
400    if (exists $OWNER{$self}) {
401        Math::GSL::MatrixComplexc::delete__gsl_vector_const_view($self);
402        delete $OWNER{$self};
403    }
404}
405
406sub DISOWN {
407    my $self = shift;
408    my $ptr = tied(%$self);
409    delete $OWNER{$ptr};
410}
411
412sub ACQUIRE {
413    my $self = shift;
414    my $ptr = tied(%$self);
415    $OWNER{$ptr} = 1;
416}
417
418
419############# Class : Math::GSL::MatrixComplex::gsl_matrix_complex ##############
420
421package Math::GSL::MatrixComplex::gsl_matrix_complex;
422use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
423@ISA = qw( Math::GSL::MatrixComplex );
424%OWNER = ();
425%ITERATORS = ();
426*swig_size1_get = *Math::GSL::MatrixComplexc::gsl_matrix_complex_size1_get;
427*swig_size1_set = *Math::GSL::MatrixComplexc::gsl_matrix_complex_size1_set;
428*swig_size2_get = *Math::GSL::MatrixComplexc::gsl_matrix_complex_size2_get;
429*swig_size2_set = *Math::GSL::MatrixComplexc::gsl_matrix_complex_size2_set;
430*swig_tda_get = *Math::GSL::MatrixComplexc::gsl_matrix_complex_tda_get;
431*swig_tda_set = *Math::GSL::MatrixComplexc::gsl_matrix_complex_tda_set;
432*swig_data_get = *Math::GSL::MatrixComplexc::gsl_matrix_complex_data_get;
433*swig_data_set = *Math::GSL::MatrixComplexc::gsl_matrix_complex_data_set;
434*swig_block_get = *Math::GSL::MatrixComplexc::gsl_matrix_complex_block_get;
435*swig_block_set = *Math::GSL::MatrixComplexc::gsl_matrix_complex_block_set;
436*swig_owner_get = *Math::GSL::MatrixComplexc::gsl_matrix_complex_owner_get;
437*swig_owner_set = *Math::GSL::MatrixComplexc::gsl_matrix_complex_owner_set;
438sub new {
439    my $pkg = shift;
440    my $self = Math::GSL::MatrixComplexc::new_gsl_matrix_complex(@_);
441    bless $self, $pkg if defined($self);
442}
443
444sub DESTROY {
445    return unless $_[0]->isa('HASH');
446    my $self = tied(%{$_[0]});
447    return unless defined $self;
448    delete $ITERATORS{$self};
449    if (exists $OWNER{$self}) {
450        Math::GSL::MatrixComplexc::delete_gsl_matrix_complex($self);
451        delete $OWNER{$self};
452    }
453}
454
455sub DISOWN {
456    my $self = shift;
457    my $ptr = tied(%$self);
458    delete $OWNER{$ptr};
459}
460
461sub ACQUIRE {
462    my $self = shift;
463    my $ptr = tied(%$self);
464    $OWNER{$ptr} = 1;
465}
466
467
468############# Class : Math::GSL::MatrixComplex::_gsl_matrix_complex_view ##############
469
470package Math::GSL::MatrixComplex::_gsl_matrix_complex_view;
471use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
472@ISA = qw( Math::GSL::MatrixComplex );
473%OWNER = ();
474%ITERATORS = ();
475*swig_matrix_get = *Math::GSL::MatrixComplexc::_gsl_matrix_complex_view_matrix_get;
476*swig_matrix_set = *Math::GSL::MatrixComplexc::_gsl_matrix_complex_view_matrix_set;
477sub new {
478    my $pkg = shift;
479    my $self = Math::GSL::MatrixComplexc::new__gsl_matrix_complex_view(@_);
480    bless $self, $pkg if defined($self);
481}
482
483sub DESTROY {
484    return unless $_[0]->isa('HASH');
485    my $self = tied(%{$_[0]});
486    return unless defined $self;
487    delete $ITERATORS{$self};
488    if (exists $OWNER{$self}) {
489        Math::GSL::MatrixComplexc::delete__gsl_matrix_complex_view($self);
490        delete $OWNER{$self};
491    }
492}
493
494sub DISOWN {
495    my $self = shift;
496    my $ptr = tied(%$self);
497    delete $OWNER{$ptr};
498}
499
500sub ACQUIRE {
501    my $self = shift;
502    my $ptr = tied(%$self);
503    $OWNER{$ptr} = 1;
504}
505
506
507############# Class : Math::GSL::MatrixComplex::_gsl_matrix_complex_const_view ##############
508
509package Math::GSL::MatrixComplex::_gsl_matrix_complex_const_view;
510use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
511@ISA = qw( Math::GSL::MatrixComplex );
512%OWNER = ();
513%ITERATORS = ();
514*swig_matrix_get = *Math::GSL::MatrixComplexc::_gsl_matrix_complex_const_view_matrix_get;
515*swig_matrix_set = *Math::GSL::MatrixComplexc::_gsl_matrix_complex_const_view_matrix_set;
516sub new {
517    my $pkg = shift;
518    my $self = Math::GSL::MatrixComplexc::new__gsl_matrix_complex_const_view(@_);
519    bless $self, $pkg if defined($self);
520}
521
522sub DESTROY {
523    return unless $_[0]->isa('HASH');
524    my $self = tied(%{$_[0]});
525    return unless defined $self;
526    delete $ITERATORS{$self};
527    if (exists $OWNER{$self}) {
528        Math::GSL::MatrixComplexc::delete__gsl_matrix_complex_const_view($self);
529        delete $OWNER{$self};
530    }
531}
532
533sub DISOWN {
534    my $self = shift;
535    my $ptr = tied(%$self);
536    delete $OWNER{$ptr};
537}
538
539sub ACQUIRE {
540    my $self = shift;
541    my $ptr = tied(%$self);
542    $OWNER{$ptr} = 1;
543}
544
545
546# ------- VARIABLE STUBS --------
547
548package Math::GSL::MatrixComplex;
549
550*GSL_VERSION = *Math::GSL::MatrixComplexc::GSL_VERSION;
551*GSL_MAJOR_VERSION = *Math::GSL::MatrixComplexc::GSL_MAJOR_VERSION;
552*GSL_MINOR_VERSION = *Math::GSL::MatrixComplexc::GSL_MINOR_VERSION;
553*GSL_POSZERO = *Math::GSL::MatrixComplexc::GSL_POSZERO;
554*GSL_NEGZERO = *Math::GSL::MatrixComplexc::GSL_NEGZERO;
555*GSL_SUCCESS = *Math::GSL::MatrixComplexc::GSL_SUCCESS;
556*GSL_FAILURE = *Math::GSL::MatrixComplexc::GSL_FAILURE;
557*GSL_CONTINUE = *Math::GSL::MatrixComplexc::GSL_CONTINUE;
558*GSL_EDOM = *Math::GSL::MatrixComplexc::GSL_EDOM;
559*GSL_ERANGE = *Math::GSL::MatrixComplexc::GSL_ERANGE;
560*GSL_EFAULT = *Math::GSL::MatrixComplexc::GSL_EFAULT;
561*GSL_EINVAL = *Math::GSL::MatrixComplexc::GSL_EINVAL;
562*GSL_EFAILED = *Math::GSL::MatrixComplexc::GSL_EFAILED;
563*GSL_EFACTOR = *Math::GSL::MatrixComplexc::GSL_EFACTOR;
564*GSL_ESANITY = *Math::GSL::MatrixComplexc::GSL_ESANITY;
565*GSL_ENOMEM = *Math::GSL::MatrixComplexc::GSL_ENOMEM;
566*GSL_EBADFUNC = *Math::GSL::MatrixComplexc::GSL_EBADFUNC;
567*GSL_ERUNAWAY = *Math::GSL::MatrixComplexc::GSL_ERUNAWAY;
568*GSL_EMAXITER = *Math::GSL::MatrixComplexc::GSL_EMAXITER;
569*GSL_EZERODIV = *Math::GSL::MatrixComplexc::GSL_EZERODIV;
570*GSL_EBADTOL = *Math::GSL::MatrixComplexc::GSL_EBADTOL;
571*GSL_ETOL = *Math::GSL::MatrixComplexc::GSL_ETOL;
572*GSL_EUNDRFLW = *Math::GSL::MatrixComplexc::GSL_EUNDRFLW;
573*GSL_EOVRFLW = *Math::GSL::MatrixComplexc::GSL_EOVRFLW;
574*GSL_ELOSS = *Math::GSL::MatrixComplexc::GSL_ELOSS;
575*GSL_EROUND = *Math::GSL::MatrixComplexc::GSL_EROUND;
576*GSL_EBADLEN = *Math::GSL::MatrixComplexc::GSL_EBADLEN;
577*GSL_ENOTSQR = *Math::GSL::MatrixComplexc::GSL_ENOTSQR;
578*GSL_ESING = *Math::GSL::MatrixComplexc::GSL_ESING;
579*GSL_EDIVERGE = *Math::GSL::MatrixComplexc::GSL_EDIVERGE;
580*GSL_EUNSUP = *Math::GSL::MatrixComplexc::GSL_EUNSUP;
581*GSL_EUNIMPL = *Math::GSL::MatrixComplexc::GSL_EUNIMPL;
582*GSL_ECACHE = *Math::GSL::MatrixComplexc::GSL_ECACHE;
583*GSL_ETABLE = *Math::GSL::MatrixComplexc::GSL_ETABLE;
584*GSL_ENOPROG = *Math::GSL::MatrixComplexc::GSL_ENOPROG;
585*GSL_ENOPROGJ = *Math::GSL::MatrixComplexc::GSL_ENOPROGJ;
586*GSL_ETOLF = *Math::GSL::MatrixComplexc::GSL_ETOLF;
587*GSL_ETOLX = *Math::GSL::MatrixComplexc::GSL_ETOLX;
588*GSL_ETOLG = *Math::GSL::MatrixComplexc::GSL_ETOLG;
589*GSL_EOF = *Math::GSL::MatrixComplexc::GSL_EOF;
590
591
592use strict;
593use Carp qw/croak/;
594use Scalar::Util 'blessed';
595use Math::Complex;
596use Data::Dumper;
597
598use Math::GSL           qw/:all/;
599use Math::GSL::Errno    qw/:all/;
600use Math::GSL::Eigen    qw/:all/;
601use Math::GSL::Test     qw/is_similar/;
602use Math::GSL::BLAS     qw/gsl_blas_zgemm/;
603use Math::GSL::CBLAS    qw/$CblasNoTrans/;
604use Math::GSL::Complex  qw/:all/;
605use Math::GSL::Permutation;
606use Math::GSL::VectorComplex qw/:all/;
607
608use Math::GSL::Linalg qw/
609    gsl_linalg_complex_LU_decomp
610    gsl_linalg_complex_LU_det
611    gsl_linalg_complex_LU_lndet
612    gsl_linalg_complex_LU_invert
613/;
614
615use overload
616    '*'      => \&_multiplication,
617    '+'      => \&_addition,
618    '-'      => \&_subtract,
619    '=='     => \&_equal,
620    '!='     => \&_not_equal,
621#    'abs'    => \&_abs,
622    fallback => 1;
623
624our @EXPORT_OK = qw/
625                gsl_matrix_complex_alloc
626                gsl_matrix_complex_calloc
627                gsl_matrix_complex_alloc_from_block
628                gsl_matrix_complex_alloc_from_matrix
629                gsl_vector_complex_alloc_row_from_matrix
630                gsl_vector_complex_alloc_col_from_matrix
631                gsl_matrix_complex_free
632                gsl_matrix_complex_submatrix
633                gsl_matrix_complex_row
634                gsl_matrix_complex_column
635                gsl_matrix_complex_diagonal
636                gsl_matrix_complex_subdiagonal
637                gsl_matrix_complex_superdiagonal
638                gsl_matrix_complex_subrow
639                gsl_matrix_complex_subcolumn
640                gsl_matrix_complex_view_array
641                gsl_matrix_complex_view_array_with_tda
642                gsl_matrix_complex_view_vector
643                gsl_matrix_complex_view_vector_with_tda
644                gsl_matrix_complex_const_submatrix
645                gsl_matrix_complex_const_row
646                gsl_matrix_complex_const_column
647                gsl_matrix_complex_const_diagonal
648                gsl_matrix_complex_const_subdiagonal
649                gsl_matrix_complex_const_superdiagonal
650                gsl_matrix_complex_const_subrow
651                gsl_matrix_complex_const_subcolumn
652                gsl_matrix_complex_const_view_array
653                gsl_matrix_complex_const_view_array_with_tda
654                gsl_matrix_complex_const_view_vector
655                gsl_matrix_complex_const_view_vector_with_tda
656                gsl_matrix_complex_get
657                gsl_matrix_complex_set
658                gsl_matrix_complex_ptr
659                gsl_matrix_complex_const_ptr
660                gsl_matrix_complex_set_zero
661                gsl_matrix_complex_set_identity
662                gsl_matrix_complex_set_all
663                gsl_matrix_complex_fread
664                gsl_matrix_complex_fwrite
665                gsl_matrix_complex_fscanf
666                gsl_matrix_complex_fprintf
667                gsl_matrix_complex_memcpy
668                gsl_matrix_complex_swap
669                gsl_matrix_complex_swap_rows
670                gsl_matrix_complex_swap_columns
671                gsl_matrix_complex_swap_rowcol
672                gsl_matrix_complex_transpose
673                gsl_matrix_complex_transpose_memcpy
674                gsl_matrix_complex_isnull
675                gsl_matrix_complex_ispos
676                gsl_matrix_complex_isneg
677                gsl_matrix_complex_add
678                gsl_matrix_complex_sub
679                gsl_matrix_complex_mul_elements
680                gsl_matrix_complex_div_elements
681                gsl_matrix_complex_scale
682                gsl_matrix_complex_add_constant
683                gsl_matrix_complex_add_diagonal
684                gsl_matrix_complex_get_row
685                gsl_matrix_complex_get_col
686                gsl_matrix_complex_set_row
687                gsl_matrix_complex_set_col
688/;
689
690sub _multiplication {
691    my ($left,$right) = @_;
692    my $lcopy = $left->copy;
693
694    if ( blessed $right && $right->isa('Math::GSL::MatrixComplex') ) {
695        if ( $left->cols == $right->cols && $left->rows == $right->rows ) {
696            return _dot_product($left,$right);
697            #gsl_matrix_complex_mul_elements($lcopy->raw, $right->raw);
698        } else {
699            croak "Math::GSL::MatrixComplex - multiplication of elements of matrices must be called with two objects matrices and must have the same number of columns and rows";
700        }
701    } else {
702        gsl_matrix_complex_scale($lcopy->raw, $right);
703    }
704    return $lcopy;
705}
706
707sub _dot_product {
708    my ($left,$right) = @_;
709
710    croak "Math::GSL::Matrix - incompatible matrices in multiplication"
711        unless ( blessed $right && $right->isa('Math::GSL::MatrixComplex') and $left->rows == $right->cols );
712    my $C = Math::GSL::MatrixComplex->new($left->rows, $right->cols);
713    my $complex = gsl_complex_rect(1,0);
714    gsl_blas_zgemm($CblasNoTrans, $CblasNoTrans, $complex, $left->raw, $right->raw, $complex, $C->raw);
715    return $C;
716}
717
718sub _addition {
719    my ($left, $right) = @_;
720
721    my $lcopy = $left->copy;
722
723    if ( blessed $right && $right->isa('Math::GSL::MatrixComplex') && blessed $left && $left->isa('Math::GSL::MatrixComplex') ) {
724        if ( $left->cols == $right->cols && $left->rows == $right->rows ) {
725            gsl_matrix_complex_add($lcopy->raw, $right->raw);
726        } else {
727            croak "Math::GSL - addition of matrices must be called with two objects matrices and must have the same number of columns and rows";
728        }
729    } else {
730        gsl_matrix_complex_add_constant($lcopy->raw, $right);
731    }
732    return $lcopy;
733}
734
735sub _subtract {
736    my ($left, $right) = @_;
737
738    my $lcopy = $left->copy;
739
740    if ( blessed $right && $right->isa('Math::GSL::MatrixComplex') && blessed $left && $left->isa('Math::GSL::MatrixComplex') ) {
741        if ( $left->cols == $right->cols && $left->rows == $right->rows ) {
742            gsl_matrix_complex_sub($lcopy->raw, $right->raw);
743        } else {
744            croak "Math::GSL - subtraction of matrices must be called with two objects matrices and must have the same number of columns and rows";
745        }
746    } else {
747        gsl_matrix_complex_add_constant($lcopy->raw, $right*-1);
748    }
749    return $lcopy;
750}
751
752sub _equal {
753    my ($left, $right) = @_;
754    return is_similar( [ map { Re $_ } $left->as_list ],
755                       [ map { Re $_ } $right->as_list ]) &&
756           is_similar( [ map { Im $_ } $left->as_list ],
757                       [ map { Im $_ } $right->as_list ]);
758}
759
760sub _not_equal {
761    my ($left, $right) = @_;
762    return !_equal($left,$right);
763}
764
765sub copy {
766    my $self = shift;
767    my $copy = Math::GSL::MatrixComplex->new( $self->rows, $self->cols );
768    if ( gsl_matrix_complex_memcpy($copy->raw, $self->raw) != $GSL_SUCCESS ) {
769        croak "Math::GSL - error copying memory, aborting";
770    }
771    return $copy;
772}
773our %EXPORT_TAGS = ( all => \@EXPORT_OK  );
774
775=encoding utf8
776
777=head1 NAME
778
779Math::GSL::MatrixComplex - Complex Matrices
780
781=head1 SYNOPSIS
782
783    use Math::GSL::MatrixComplex qw/:all/;
784    my $matrix1 = Math::GSL::MatrixComplex->new(5,5);  # OO interface
785    my $matrix3 = $matrix1 + $matrix1;
786    my $matrix4 = $matrix1 - $matrix1;
787    if($matrix1 == $matrix4) ...
788    if($matrix1 != $matrix3) ...
789
790    my $matrix2 = gsl_matrix_complex_alloc(5,5);        # standard interface
791
792=head1 Objected Oriented Interface to GSL Math::GSL::MatrixComplex
793
794=head2 new()
795
796Creates a new MatrixComplex object of the given size.
797
798    my $matrix = Math::GSL::MatrixComplex->new(10,10);
799=cut
800
801sub new
802{
803    my ($class, $rows, $cols) = @_;
804    my $this = {};
805    my $matrix;
806    if ( defined $rows       && defined $cols &&
807        $rows > 0            && $cols > 0     &&
808        (int $rows == $rows) && (int $cols == $cols)){
809
810        $matrix  = gsl_matrix_complex_alloc($rows,$cols);
811    } else {
812        croak( __PACKAGE__.'::new($x,$y) - $x and $y must be positive integers');
813    }
814    gsl_matrix_complex_set_zero($matrix);
815    $this->{_matrix} = $matrix;
816    ($this->{_rows}, $this->{_cols}) = ($rows,$cols);
817    bless $this, $class;
818}
819=head2 raw()
820
821Get the underlying GSL matrix object created by SWIG, useful for using gsl_matrix_* functions which do not have an OO counterpart.
822
823    my $matrix     = Math::GSL::MatrixComplex->new(3,3);
824    my $gsl_matrix = $matrix->raw;
825    my $stuff      = gsl_matrix_complex_get($gsl_matrix, 1, 2);
826
827=cut
828sub raw  { (shift)->{_matrix} }
829=head2 rows()
830
831Returns the number of rows in the matrix.
832
833    my $rows = $matrix->rows;
834=cut
835
836sub rows { (shift)->{_rows}   }
837
838=head2 cols()
839
840Returns the number of columns in the matrix.
841
842    my $cols = $matrix->cols;
843=cut
844
845sub cols { (shift)->{_cols}   }
846
847=head2 as_vector()
848
849Returns a 1xN or Nx1 matrix as a Math::GSL::VectorComplex object. Dies if called on a matrix that is not a single row or column. Useful for turning the output of C<col()> or C<row()> into a vector, like so:
850
851    my $vector1 = $matrix->col(0)->as_vector;
852    my $vector2 = $matrix->row(1)->as_vector;
853
854=cut
855
856sub as_vector($)
857{
858    my ($self) = @_;
859    croak(__PACKAGE__.'::as_vector() - must be a single row or column matrix') unless ($self->cols == 1 or $self->rows == 1);
860
861    # TODO: there is a faster way to do this
862    return Math::GSL::VectorComplex->new([ $self->as_list ] );
863
864}
865
866=head2  as_list()
867
868Get the contents of a Math::GSL::Matrix object as a Perl list.
869
870    my $matrix = Math::GSL::MatrixComplex->new(3,3);
871    ...
872    my @matrix = $matrix->as_list;
873=cut
874
875sub as_list($)
876{
877    my $self = shift;
878    my @matrix;
879    for my $row ( 0 .. $self->rows-1) {
880       push @matrix, map { gsl_matrix_complex_get($self->raw, $row, $_) } (0 .. $self->cols-1 );
881    }
882    return map {
883            Math::Complex->make(
884                gsl_real($_),
885                gsl_imag($_))
886            } @matrix;
887}
888
889=head2 row()
890
891Returns a row matrix of the row you enter.
892
893    my $matrix = Math::GSL::MatrixComplex->new(3,3);
894    ...
895    my $matrix_row = $matrix->row(0);
896
897=cut
898
899sub row
900{
901    my ($self, $row) = @_;
902    croak (__PACKAGE__.'::$matrix->row($row) - invalid $row value')
903        unless (($row < $self->rows) and $row >= 0);
904
905   my $rowmat = Math::GSL::MatrixComplex->new(1,$self->cols);
906
907   for my $n (0 .. $self->cols-1) {
908        gsl_matrix_complex_set( $rowmat->raw, 0, $n,
909            gsl_matrix_complex_get($self->raw, $row, $n)
910        );
911   }
912
913    return $rowmat;
914}
915
916=head2 col()
917
918Returns a col matrix of the column you enter.
919
920    my $matrix = Math::GSL::MatrixComplex->new(3,3);
921    ...
922    my $matrix_col = $matrix->col(0);
923
924=cut
925
926sub col
927{
928    my ($self, $col) = @_;
929    croak (__PACKAGE__."::\$matrix->col(\$col) - $col not a valid column")
930        unless (defined $col && $col < $self->cols and $col >= 0);
931
932    my $colmat = Math::GSL::MatrixComplex->new($self->rows, 1);
933
934    map { gsl_matrix_complex_set($colmat->raw, $_, 0,
935            gsl_matrix_complex_get($self->raw, $_, $col),
936            )
937        } (0 .. $self->rows-1);
938
939    return $colmat;
940}
941
942=head2 set_row()
943
944Sets a the values of a row with the elements of an array.
945
946    my $matrix = Math::GSL::MatrixComplex->new(3,3);
947    $matrix->set_row(0, [8, 6, 2]);
948
949You can also set multiple rows at once with chained calls:
950    my $matrix = Math::GSL::MatrixComplex->new(3,3);
951    $matrix->set_row(0, [8, 6, 2])
952           ->set_row(1, [2, 4, 1]);
953    ...
954
955=cut
956
957sub set_row {
958    my ($self, $row, $values) = @_;
959    my $length = $#$values;
960    die __PACKAGE__.'::set_row($x, $values) - $values must be a nonempty array reference' if $length == -1;
961    die __PACKAGE__.'::set_row($x, $values) - $x must be a valid row number' if ($row < 0 || $row >= $self->rows);
962    die __PACKAGE__.'::set_row($x, $values) - $values must contains the same number of elements as there is columns in the matrix' if($length != $self->cols-1);
963    # $values may have Math::Complex objects
964    @$values = map { Math::GSL::Complex::gsl_complex_rect(Re($_), Im($_)) } @$values;
965    # warn Dumper [ @$values ];
966    map { gsl_matrix_complex_set($self->raw, $row, $_, $values->[$_]) } (0..$length);
967    return $self;
968}
969
970=head2 set_col()
971
972Sets a the values of a column with the elements of an array.
973
974    my $matrix = Math::GSL::MatrixComplex->new(3,3);
975    $matrix->set_col(0, [8, 6, 2]);
976
977You can also set multiple columns at once with chained calls:
978    my $matrix = Math::GSL::MatrixComplex->new(3,3);
979    $matrix->set_col(0, [8, 6, 2])
980           ->set_col(1, [2, 4, 1]);
981    ...
982
983=cut
984
985sub set_col {
986    my ($self, $col, $values) = @_;
987    my $length = $#$values;
988    die __PACKAGE__.'::set_col($x, $values) - $values must be a nonempty array reference' if $length == -1;
989    die __PACKAGE__.'::set_col($x, $values) - $x must be a valid column number' if ($col < 0 || $col >= $self->cols);
990    die __PACKAGE__.'::set_col($x, $values) - $values must contains the same number of elements as there is rowss in the matrix' if($length != $self->rows-1);
991    # $values may have Math::Complex objects
992    @$values = map { gsl_complex_rect(Re($_), Im($_)) } @$values;
993    map { gsl_matrix_complex_set($self->raw, $_, $col, $values->[$_]) } (0..$length);
994    return $self;
995}
996
997=head2 is_square()
998
999Returns true if a matrix is square, i.e. it has the same number of rows as columns, false otherwise.
1000
1001=cut
1002
1003sub is_square($)
1004{
1005    my $self = shift;
1006    return ($self->rows == $self->cols) ? 1 : 0 ;
1007}
1008
1009=head2 det()
1010
1011Returns the determinant of a matrix (computed by LU decomposition) or dies if called on a non-square matrix.
1012
1013    my $det = $matrix->det();
1014
1015=cut
1016
1017sub det($)
1018{
1019    my $self = shift;
1020    croak(__PACKAGE__."- determinant only exists for square matrices") unless $self->is_square;
1021
1022    my $p  = Math::GSL::Permutation->new( $self->rows );
1023    my $LU = $self->copy;
1024
1025    my $s = gsl_linalg_complex_LU_decomp($LU->raw, $p->raw);
1026
1027    # $z is a gsl_complex
1028    my $z = gsl_linalg_complex_LU_det($LU->raw, $s );
1029    return Math::Complex->make( gsl_real($z), gsl_imag($z) );
1030}
1031
1032=head2 zero()
1033
1034Set a matrix to the zero matrix.
1035
1036    $matrix->zero;
1037
1038=cut
1039
1040sub zero # brrr!
1041{
1042    my $self=shift;
1043    gsl_matrix_complex_set_zero($self->raw);
1044    return $self;
1045}
1046
1047=head2 identity()
1048
1049Set a matrix to the identity matrix, i.e. one on the diagonal and zero elsewhere.
1050
1051    my $I = $matrix->identity;
1052
1053=cut
1054
1055sub identity
1056{
1057    my $self=shift;
1058    gsl_matrix_complex_set_identity($self->raw);
1059    return $self;
1060}
1061
1062=head2 inverse()
1063
1064Returns the inverse of a matrix or dies when called on a non-square matrix.
1065
1066    my $inverse = $matrix->inverse;
1067
1068=cut
1069
1070sub inverse($)
1071{
1072    my $self = shift;
1073    croak(__PACKAGE__."- inverse only exists for square matrices") unless $self->is_square;
1074
1075    my $p  = Math::GSL::Permutation->new( $self->rows );
1076    my $LU = $self->copy;
1077    my $inverse = $self->copy;
1078
1079    # should check return status
1080    gsl_linalg_complex_LU_decomp($LU->raw, $p->raw);
1081    gsl_linalg_complex_LU_invert($LU->raw, $p->raw,$inverse->raw);
1082
1083    return $inverse;
1084
1085}
1086
1087=head2 is_hermitian()
1088
1089Returns true if the matrix is hermitian, false otherwise
1090
1091    my $test = $matrix->is_hermitian;
1092
1093=cut
1094
1095sub is_hermitian()
1096{
1097    my ($self) = @_;
1098    my $test = $self->is_square;
1099    my $transpose = $self->copy;
1100    gsl_matrix_complex_transpose($transpose->raw);
1101
1102    if($test == 1) {
1103        for my $row (0..$self->rows - 1) {
1104            map { gsl_matrix_complex_set($transpose->raw, $row, $_, gsl_complex_conjugate(gsl_matrix_complex_get($transpose->raw, $row, $_))) } (0..$self->cols - 1);
1105        }
1106        if($self != $transpose){
1107            $test = 0;
1108        }
1109    }
1110    return $test;
1111}
1112=head2 eigenvalues()
1113
1114=cut
1115
1116
1117sub eigenvalues($)
1118{
1119    my $self=shift;
1120    my ($r,$c) = ($self->rows,$self->cols);
1121    croak "Math::GSL::MatrixComplex : \$matrix->eigenvalues - \$matrix must be square" unless ($r == $c);
1122    my $vector = Math::GSL::Vector->new($r);
1123    my $eigen  = gsl_eigen_herm_alloc($r);
1124
1125
1126    # GSL has no generalized complex matrix routines
1127    # can only continue if the matrix is hermitian
1128    croak (__PACKAGE__."::eigenvalues : non-hermitian matrices are not currently supported")  unless $self->is_hermitian;
1129    gsl_eigen_herm($self->raw, $vector->raw, $eigen);
1130
1131    return $vector->as_list;
1132}
1133
1134=head2 lndet()
1135
1136Returns the natural log of the absolute value of the determinant of a matrix (computed by LU decomposition) or dies if called on a non-square matrix.
1137
1138    my $lndet = $matrix->lndet();
1139
1140=cut
1141
1142sub lndet($)
1143{
1144    my $self = shift;
1145    croak(__PACKAGE__."- log determinant only exists for square matrices") unless $self->is_square;
1146
1147    my $p  = Math::GSL::Permutation->new( $self->rows );
1148    my $LU = $self->copy;
1149
1150    gsl_linalg_complex_LU_decomp($LU->raw, $p->raw);
1151    return gsl_linalg_complex_LU_lndet($LU->raw);
1152}
1153=head1 DESCRIPTION
1154
1155=over 1
1156
1157=item C<gsl_matrix_complex_alloc >
1158
1159=item C<gsl_matrix_complex_calloc >
1160
1161=item C<gsl_matrix_complex_alloc_from_block >
1162
1163=item C<gsl_matrix_complex_alloc_from_matrix >
1164
1165=item C<gsl_vector_complex_alloc_row_from_matrix >
1166
1167=item C<gsl_vector_complex_alloc_col_from_matrix >
1168
1169=item C<gsl_matrix_complex_free >
1170
1171=item C<gsl_matrix_complex_submatrix >
1172
1173=item C<gsl_matrix_complex_row >
1174
1175=item C<gsl_matrix_complex_column >
1176
1177=item C<gsl_matrix_complex_diagonal >
1178
1179=item C<gsl_matrix_complex_subdiagonal >
1180
1181=item C<gsl_matrix_complex_superdiagonal >
1182
1183=item C<gsl_matrix_complex_subrow >
1184
1185=item C<gsl_matrix_complex_subcolumn >
1186
1187=item C<gsl_matrix_complex_view_array >
1188
1189=item C<gsl_matrix_complex_view_array_with_tda >
1190
1191=item C<gsl_matrix_complex_view_vector >
1192
1193=item C<gsl_matrix_complex_view_vector_with_tda >
1194
1195=item C<gsl_matrix_complex_const_submatrix >
1196
1197=item C<gsl_matrix_complex_const_row >
1198
1199=item C<gsl_matrix_complex_const_column >
1200
1201=item C<gsl_matrix_complex_const_diagonal >
1202
1203=item C<gsl_matrix_complex_const_subdiagonal >
1204
1205=item C<gsl_matrix_complex_const_superdiagonal >
1206
1207=item C<gsl_matrix_complex_const_subrow >
1208
1209=item C<gsl_matrix_complex_const_subcolumn >
1210
1211=item C<gsl_matrix_complex_const_view_array >
1212
1213=item C<gsl_matrix_complex_const_view_array_with_tda >
1214
1215=item C<gsl_matrix_complex_const_view_vector >
1216
1217=item C<gsl_matrix_complex_const_view_vector_with_tda >
1218
1219=item C<gsl_matrix_complex_get>
1220
1221=item C<gsl_matrix_complex_set>
1222
1223=item C<gsl_matrix_complex_ptr>
1224
1225=item C<gsl_matrix_complex_const_ptr>
1226
1227=item C<gsl_matrix_complex_set_zero >
1228
1229=item C<gsl_matrix_complex_set_identity >
1230
1231=item C<gsl_matrix_complex_set_all >
1232
1233=item C<gsl_matrix_complex_fread >
1234
1235=item C<gsl_matrix_complex_fwrite >
1236
1237=item C<gsl_matrix_complex_fscanf >
1238
1239=item C<gsl_matrix_complex_fprintf >
1240
1241=item C<gsl_matrix_complex_memcpy>
1242
1243=item C<gsl_matrix_complex_swap>
1244
1245=item C<gsl_matrix_complex_swap_rows>
1246
1247=item C<gsl_matrix_complex_swap_columns>
1248
1249=item C<gsl_matrix_complex_swap_rowcol>
1250
1251=item C<gsl_matrix_complex_transpose >
1252
1253=item C<gsl_matrix_complex_transpose_memcpy >
1254
1255=item C<gsl_matrix_complex_isnull >
1256
1257=item C<gsl_matrix_complex_ispos >
1258
1259=item C<gsl_matrix_complex_isneg >
1260
1261=item C<gsl_matrix_complex_add >
1262
1263=item C<gsl_matrix_complex_sub >
1264
1265=item C<gsl_matrix_complex_mul_elements >
1266
1267=item C<gsl_matrix_complex_div_elements >
1268
1269=item C<gsl_matrix_complex_scale >
1270
1271=item C<gsl_matrix_complex_add_constant >
1272
1273=item C<gsl_matrix_complex_add_diagonal >
1274
1275=item C<gsl_matrix_complex_get_row>
1276
1277=item C<gsl_matrix_complex_get_col>
1278
1279=item C<gsl_matrix_complex_set_row>
1280
1281=item C<gsl_matrix_complex_set_col>
1282
1283=back
1284
1285For more informations on the functions, we refer you to the GSL official documentation
1286L<http://www.gnu.org/software/gsl/manual/html_node/>
1287
1288
1289=head1 AUTHORS
1290
1291Jonathan "Duke" Leto <jonathan@leto.net> and Thierry Moisan <thierry.moisan@gmail.com>
1292
1293=head1 COPYRIGHT AND LICENSE
1294
1295Copyright (C) 2008-2021 Jonathan "Duke" Leto and Thierry Moisan
1296
1297This program is free software; you can redistribute it and/or modify it
1298under the same terms as Perl itself.
1299
1300=cut
1301
13021;
1303