Finish pod separation and add stub tests for remaining subsystems
[Math-GSL.git] / pod / Matrix.pod
blobc34441a1d9761da12270e774c35ca10d6a4e83fe
1 %perlcode %{ 
3 use Carp qw/croak/;
4 use Math::GSL qw/:all/;
5 use Math::GSL::Errno qw/:all/;
7 @EXPORT_OK = qw/
8         gsl_matrix_alloc gsl_matrix_calloc gsl_matrix_alloc_from_block
9         gsl_matrix_alloc_from_matrix gsl_vector_alloc_row_from_matrix
10         gsl_vector_alloc_col_from_matrix gsl_matrix_free gsl_matrix_submatrix
11         gsl_matrix_row gsl_matrix_column gsl_matrix_diagonal
12         gsl_matrix_subdiagonal gsl_matrix_superdiagonal gsl_matrix_subrow
13         gsl_matrix_subcolumn gsl_matrix_view_array
14         gsl_matrix_view_array_with_tda gsl_matrix_view_vector
15         gsl_matrix_view_vector_with_tda gsl_matrix_const_submatrix
16         gsl_matrix_const_row gsl_matrix_const_column gsl_matrix_const_diagonal
17         gsl_matrix_const_subdiagonal gsl_matrix_const_superdiagonal
18         gsl_matrix_const_subrow gsl_matrix_const_subcolumn
19         gsl_matrix_const_view_array gsl_matrix_const_view_array_with_tda
20         gsl_matrix_const_view_vector gsl_matrix_const_view_vector_with_tda
21         gsl_matrix_get gsl_matrix_set gsl_matrix_ptr gsl_matrix_const_ptr
22         gsl_matrix_set_zero gsl_matrix_set_identity gsl_matrix_set_all
23         gsl_matrix_fread gsl_matrix_fwrite gsl_matrix_fscanf gsl_matrix_fprintf
24         gsl_matrix_memcpy gsl_matrix_swap gsl_matrix_swap_rows
25         gsl_matrix_swap_columns gsl_matrix_swap_rowcol gsl_matrix_transpose
26         gsl_matrix_transpose_memcpy gsl_matrix_max gsl_matrix_min
27         gsl_matrix_minmax gsl_matrix_max_index gsl_matrix_min_index
28         gsl_matrix_minmax_index gsl_matrix_isnull gsl_matrix_ispos
29         gsl_matrix_isneg gsl_matrix_isnonneg gsl_matrix_add gsl_matrix_sub
30         gsl_matrix_mul_elements gsl_matrix_div_elements gsl_matrix_scale
31         gsl_matrix_add_constant gsl_matrix_add_diagonal
32         gsl_matrix_char_alloc gsl_matrix_char_calloc  gsl_matrix_char_alloc_from_block
33         gsl_matrix_char_alloc_from_matrix gsl_vector_char_alloc_row_from_matrix gsl_vector_char_alloc_col_from_matrix 
34         gsl_matrix_char_free gsl_matrix_char_submatrix 
35         gsl_matrix_char_row  gsl_matrix_char_column 
36         gsl_matrix_char_diagonal gsl_matrix_char_subdiagonal gsl_matrix_char_superdiagonal 
37         gsl_matrix_char_subrow gsl_matrix_char_subcolumn gsl_matrix_char_view_array 
38         gsl_matrix_char_view_array_with_tda gsl_matrix_char_view_vector gsl_matrix_char_view_vector_with_tda 
39         gsl_matrix_char_const_submatrix gsl_matrix_char_const_row gsl_matrix_char_const_column 
40         gsl_matrix_char_const_diagonal gsl_matrix_char_const_subdiagonal gsl_matrix_char_const_superdiagonal 
41         gsl_matrix_char_const_subrow gsl_matrix_char_const_subcolumn gsl_matrix_char_const_view_array 
42         gsl_matrix_char_const_view_array_with_tda gsl_matrix_char_const_view_vector gsl_matrix_char_const_view_vector_with_tda 
43         gsl_matrix_char_get gsl_matrix_char_set gsl_matrix_char_ptr gsl_matrix_char_const_ptr 
44         gsl_matrix_char_set_zero gsl_matrix_char_set_identity 
45         gsl_matrix_char_set_all  gsl_matrix_char_fread 
46         gsl_matrix_char_fwrite gsl_matrix_char_fscanf gsl_matrix_char_fprintf 
47         gsl_matrix_char_memcpy gsl_matrix_char_swap 
48         gsl_matrix_char_swap_rows gsl_matrix_char_swap_columns
49         gsl_matrix_char_swap_rowcol gsl_matrix_char_transpose gsl_matrix_char_transpose_memcpy 
50         gsl_matrix_char_max gsl_matrix_char_min 
51         gsl_matrix_char_minmax  gsl_matrix_char_max_index 
52         gsl_matrix_char_min_index gsl_matrix_char_minmax_index  
53         gsl_matrix_char_isnull gsl_matrix_char_ispos gsl_matrix_char_isneg 
54         gsl_matrix_char_isnonneg  gsl_matrix_char_add 
55         gsl_matrix_char_sub gsl_matrix_char_mul_elements gsl_matrix_char_div_elements 
56         gsl_matrix_char_scale gsl_matrix_char_add_constant gsl_matrix_char_add_diagonal 
57         gsl_matrix_int_alloc gsl_matrix_int_calloc gsl_matrix_int_alloc_from_block 
58         gsl_matrix_int_alloc_from_matrix gsl_vector_int_alloc_row_from_matrix gsl_vector_int_alloc_col_from_matrix 
59         gsl_matrix_int_free gsl_matrix_int_submatrix gsl_matrix_int_row 
60         gsl_matrix_int_column gsl_matrix_int_diagonal gsl_matrix_int_subdiagonal 
61         gsl_matrix_int_superdiagonal gsl_matrix_int_subrow gsl_matrix_int_subcolumn gsl_matrix_int_view_array 
62         gsl_matrix_int_view_array_with_tda gsl_matrix_int_view_vector gsl_matrix_int_view_vector_with_tda 
63         gsl_matrix_int_const_submatrix gsl_matrix_int_const_row gsl_matrix_int_const_column 
64         gsl_matrix_int_const_diagonal gsl_matrix_int_const_subdiagonal gsl_matrix_int_const_superdiagonal 
65         gsl_matrix_int_const_subrow gsl_matrix_int_const_subcolumn gsl_matrix_int_const_view_array 
66         gsl_matrix_int_const_view_array_with_tda gsl_matrix_int_const_view_vector gsl_matrix_int_const_view_vector_with_tda 
67         gsl_matrix_int_get gsl_matrix_int_set 
68         gsl_matrix_int_ptr gsl_matrix_int_const_ptr 
69         gsl_matrix_int_set_zero gsl_matrix_int_set_identity gsl_matrix_int_set_all 
70         gsl_matrix_int_fread gsl_matrix_int_fwrite 
71         gsl_matrix_int_fscanf gsl_matrix_int_fprintf 
72         gsl_matrix_int_memcpy gsl_matrix_int_swap 
73         gsl_matrix_int_swap_rows gsl_matrix_int_swap_columns gsl_matrix_int_swap_rowcol
74         gsl_matrix_int_transpose gsl_matrix_int_transpose_memcpy  
75         gsl_matrix_int_max gsl_matrix_int_min gsl_matrix_int_minmax 
76         gsl_matrix_int_max_index gsl_matrix_int_min_index 
77         gsl_matrix_int_minmax_index  gsl_matrix_int_isnull 
78         gsl_matrix_int_ispos gsl_matrix_int_isneg gsl_matrix_int_isnonneg 
79         gsl_matrix_int_add gsl_matrix_int_sub 
80         gsl_matrix_int_mul_elements gsl_matrix_int_div_elements gsl_matrix_int_scale 
81         gsl_matrix_int_add_constant gsl_matrix_int_add_diagonal
82         gsl_matrix_get_row gsl_matrix_get_col gsl_matrix_set_row gsl_matrix_set_col
83         gsl_matrix_complex_alloc gsl_matrix_complex_calloc gsl_matrix_complex_alloc_from_block 
84         gsl_matrix_complex_alloc_from_matrix gsl_vector_complex_alloc_row_from_matrix gsl_vector_complex_alloc_col_from_matrix 
85         gsl_matrix_complex_free gsl_matrix_complex_submatrix gsl_matrix_complex_row 
86         gsl_matrix_complex_column gsl_matrix_complex_diagonal gsl_matrix_complex_subdiagonal 
87         gsl_matrix_complex_superdiagonal gsl_matrix_complex_subrow gsl_matrix_complex_subcolumn 
88         gsl_matrix_complex_view_array gsl_matrix_complex_view_array_with_tda gsl_matrix_complex_view_vector 
89         gsl_matrix_complex_view_vector_with_tda gsl_matrix_complex_const_submatrix gsl_matrix_complex_const_row 
90         gsl_matrix_complex_const_column gsl_matrix_complex_const_diagonal gsl_matrix_complex_const_subdiagonal 
91         gsl_matrix_complex_const_superdiagonal gsl_matrix_complex_const_subrow gsl_matrix_complex_const_subcolumn 
92         gsl_matrix_complex_const_view_array gsl_matrix_complex_const_view_array_with_tda gsl_matrix_complex_const_view_vector 
93         gsl_matrix_complex_const_view_vector_with_tda gsl_matrix_complex_get gsl_matrix_complex_set
94         gsl_matrix_complex_ptr gsl_matrix_complex_const_ptr gsl_matrix_complex_set_zero 
95         gsl_matrix_complex_set_identity gsl_matrix_complex_set_all gsl_matrix_complex_fread 
96         gsl_matrix_complex_fwrite gsl_matrix_complex_fscanf gsl_matrix_complex_fprintf 
97         gsl_matrix_complex_memcpy gsl_matrix_complex_swap gsl_matrix_complex_swap_rows
98         gsl_matrix_complex_swap_columns gsl_matrix_complex_swap_rowcol gsl_matrix_complex_transpose 
99         gsl_matrix_complex_transpose_memcpy gsl_matrix_complex_isnull gsl_matrix_complex_ispos 
100         gsl_matrix_complex_isneg gsl_matrix_complex_add gsl_matrix_complex_sub 
101         gsl_matrix_complex_mul_elements gsl_matrix_complex_div_elements gsl_matrix_complex_scale 
102         gsl_matrix_complex_add_constant gsl_matrix_complex_add_diagonal gsl_matrix_complex_get_row
103         gsl_matrix_complex_get_col gsl_matrix_complex_set_row gsl_matrix_complex_set_col /;
107 %EXPORT_TAGS = ( all => [ @EXPORT_OK ], 
108                  char => [ qw/
109                     gsl_matrix_char_alloc
110                     gsl_matrix_char_calloc
111                     gsl_matrix_char_alloc_from_block
112                     gsl_matrix_char_alloc_from_matrix
113                     gsl_vector_char_alloc_row_from_matrix
114                     gsl_vector_char_alloc_col_from_matrix
115                     gsl_matrix_char_free
116                     gsl_matrix_char_submatrix
117                     gsl_matrix_char_row
118                     gsl_matrix_char_column
119                     gsl_matrix_char_diagonal
120                     gsl_matrix_char_subdiagonal
121                     gsl_matrix_char_superdiagonal
122                     gsl_matrix_char_subrow
123                     gsl_matrix_char_subcolumn
124                     gsl_matrix_char_view_array
125                     gsl_matrix_char_view_array_with_tda
126                     gsl_matrix_char_view_vector
127                     gsl_matrix_char_view_vector_with_tda
128                     gsl_matrix_char_const_submatrix
129                     gsl_matrix_char_const_row
130                     gsl_matrix_char_const_column
131                     gsl_matrix_char_const_diagonal
132                     gsl_matrix_char_const_subdiagonal
133                     gsl_matrix_char_const_superdiagonal
134                     gsl_matrix_char_const_subrow
135                     gsl_matrix_char_const_subcolumn
136                     gsl_matrix_char_const_view_array
137                     gsl_matrix_char_const_view_array_with_tda
138                     gsl_matrix_char_const_view_vector
139                     gsl_matrix_char_const_view_vector_with_tda
140                     gsl_matrix_char_get
141                     gsl_matrix_char_set
142                     gsl_matrix_char_ptr
143                     gsl_matrix_char_const_ptr
144                     gsl_matrix_char_set_zero
145                     gsl_matrix_char_set_identity
146                     gsl_matrix_char_set_all
147                     gsl_matrix_char_fread
148                     gsl_matrix_char_fwrite
149                     gsl_matrix_char_fscanf
150                     gsl_matrix_char_fprintf
151                     gsl_matrix_char_memcpy
152                     gsl_matrix_char_swap
153                     gsl_matrix_char_swap_rows
154                     gsl_matrix_char_swap_columns
155                     gsl_matrix_char_swap_rowcol
156                     gsl_matrix_char_transpose
157                     gsl_matrix_char_transpose_memcpy
158                     gsl_matrix_char_max
159                     gsl_matrix_char_min
160                     gsl_matrix_char_minmax
161                     gsl_matrix_char_max_index
162                     gsl_matrix_char_min_index
163                     gsl_matrix_char_minmax_index
164                     gsl_matrix_char_isnull
165                     gsl_matrix_char_ispos
166                     gsl_matrix_char_isneg
167                     gsl_matrix_char_isnonneg
168                     gsl_matrix_char_add
169                     gsl_matrix_char_sub
170                     gsl_matrix_char_mul_elements
171                     gsl_matrix_char_div_elements
172                     gsl_matrix_char_scale
173                     gsl_matrix_char_add_constant
174                     gsl_matrix_char_add_diagonal
175                      /],
177                  double => [ qw/
178                     gsl_matrix_alloc
179                     gsl_matrix_calloc
180                     gsl_matrix_alloc_from_block
181                     gsl_matrix_alloc_from_matrix
182                     gsl_vector_alloc_row_from_matrix
183                     gsl_vector_alloc_col_from_matrix
184                     gsl_matrix_free
185                     gsl_matrix_submatrix
186                     gsl_matrix_row
187                     gsl_matrix_column
188                     gsl_matrix_diagonal
189                     gsl_matrix_subdiagonal
190                     gsl_matrix_superdiagonal
191                     gsl_matrix_subrow
192                     gsl_matrix_subcolumn
193                     gsl_matrix_view_array
194                     gsl_matrix_view_array_with_tda
195                     gsl_matrix_view_vector
196                     gsl_matrix_view_vector_with_tda
197                     gsl_matrix_const_submatrix
198                     gsl_matrix_const_row
199                     gsl_matrix_const_column
200                     gsl_matrix_const_diagonal
201                     gsl_matrix_const_subdiagonal
202                     gsl_matrix_const_superdiagonal
203                     gsl_matrix_const_subrow
204                     gsl_matrix_const_subcolumn
205                     gsl_matrix_const_view_array
206                     gsl_matrix_const_view_array_with_tda
207                     gsl_matrix_const_view_vector
208                     gsl_matrix_const_view_vector_with_tda
209                     gsl_matrix_get
210                     gsl_matrix_set
211                     gsl_matrix_ptr
212                     gsl_matrix_const_ptr
213                     gsl_matrix_set_zero
214                     gsl_matrix_set_identity
215                     gsl_matrix_set_all
216                     gsl_matrix_fread
217                     gsl_matrix_fwrite
218                     gsl_matrix_fscanf
219                     gsl_matrix_fprintf
220                     gsl_matrix_memcpy
221                     gsl_matrix_swap
222                     gsl_matrix_swap_rows
223                     gsl_matrix_swap_columns
224                     gsl_matrix_swap_rowcol
225                     gsl_matrix_transpose
226                     gsl_matrix_transpose_memcpy
227                     gsl_matrix_max
228                     gsl_matrix_minmax
229                     gsl_matrix_max_index
230                     gsl_matrix_min_index
231                     gsl_matrix_minmax_index
232                     gsl_matrix_isnull
233                     gsl_matrix_ispos
234                     gsl_matrix_isneg
235                     gsl_matrix_isnonneg
236                     gsl_matrix_add
237                     gsl_matrix_mul_elements
238                     gsl_matrix_div_elements
239                     gsl_matrix_scale
240                     gsl_matrix_add_constant
241                     gsl_matrix_add_diagonal
242                     /],
243 int => [ qw/
244                  gsl_matrix_int_alloc
245                  gsl_matrix_int_alloc_from_matrix
246                  gsl_matrix_int_free
247                  gsl_matrix_int_column
248                  gsl_matrix_int_superdiagonal
249                  gsl_matrix_int_view_array_with_tda
250                  gsl_matrix_int_const_submatrix
251                  gsl_matrix_int_const_diagonal
252                  gsl_matrix_int_const_subrow
253                  gsl_matrix_int_const_view_array_with_tda
254                  gsl_matrix_int_get
255                  gsl_matrix_int_ptr
256                  gsl_matrix_int_set_zero
257                  gsl_matrix_int_fread
258                  gsl_matrix_int_fscanf
259                  gsl_matrix_int_memcpy
260                  gsl_matrix_int_swap_rows
261                  gsl_matrix_int_transpose
262                  gsl_matrix_int_max
263                  gsl_matrix_int_max_index
264                  gsl_matrix_int_minmax_index
265                  gsl_matrix_int_ispos
266                  gsl_matrix_int_add
267                  gsl_matrix_int_mul_elements
268                  gsl_matrix_int_add_constant
269                  /],
270   complex => [ qw/
271                  gsl_matrix_complex_alloc
272                  gsl_matrix_complex_calloc
273                  gsl_matrix_complex_alloc_from_block
274                  gsl_matrix_complex_alloc_from_matrix
275                  gsl_vector_complex_alloc_row_from_matrix
276                  gsl_vector_complex_alloc_col_from_matrix
277                  gsl_matrix_complex_free
278                  gsl_matrix_complex_submatrix
279                  gsl_matrix_complex_row
280                  gsl_matrix_complex_column
281                  gsl_matrix_complex_diagonal
282                  gsl_matrix_complex_subdiagonal
283                  gsl_matrix_complex_superdiagonal
284                  gsl_matrix_complex_subrow
285                  gsl_matrix_complex_subcolumn
286                  gsl_matrix_complex_view_array
287                  gsl_matrix_complex_view_array_with_tda
288                  gsl_matrix_complex_view_vector
289                  gsl_matrix_complex_view_vector_with_tda
290                  gsl_matrix_complex_const_submatrix
291                  gsl_matrix_complex_const_row
292                  gsl_matrix_complex_const_column
293                  gsl_matrix_complex_const_diagonal
294                  gsl_matrix_complex_const_subdiagonal
295                  gsl_matrix_complex_const_superdiagonal
296                  gsl_matrix_complex_const_subrow
297                  gsl_matrix_complex_const_subcolumn
298                  gsl_matrix_complex_const_view_array
299                  gsl_matrix_complex_const_view_array_with_tda
300                  gsl_matrix_complex_const_view_vector
301                  gsl_matrix_complex_const_view_vector_with_tda
302                  gsl_matrix_complex_get
303                  gsl_matrix_complex_set
304                  gsl_matrix_complex_ptr
305                  gsl_matrix_complex_const_ptr
306                  gsl_matrix_complex_set_zero gsl_matrix_complex_set_identity
307                  gsl_matrix_complex_set_all
308                  gsl_matrix_complex_fread
309                  gsl_matrix_complex_fwrite
310                  gsl_matrix_complex_fscanf
311                  gsl_matrix_complex_fprintf
312                  gsl_matrix_complex_memcpygsl_matrix_complex_swap
313                  gsl_matrix_complex_swap_rows
314                  gsl_matrix_complex_swap_columns
315                  gsl_matrix_complex_swap_rowcol
316                  gsl_matrix_complex_transpose
317                  gsl_matrix_complex_transpose_memcpy
318                  gsl_matrix_complex_isnull
319                  gsl_matrix_complex_ispos
320                  gsl_matrix_complex_isneg
321                  gsl_matrix_complex_add
322                  gsl_matrix_complex_sub
323                  gsl_matrix_complex_mul_elements
324                  gsl_matrix_complex_div_elements
325                  gsl_matrix_complex_scale
326                  gsl_matrix_complex_add_constant
327                  gsl_matrix_complex_add_diagonal
328                  gsl_matrix_complex_get_row
329                  gsl_matrix_complex_get_col
330                  gsl_matrix_complex_set_row
331                  gsl_matrix_complex_set_col
332                  /]);
334 =head1 NAME
336 Math::GSL::Matrix - Mathematical functions concerning Matrices
338 =head1 SYNOPSIS
340     use Math::GSL::Matrix qw/:all/;
341     my $matrix1 = Math::GSL::Matrix->new(5,5);  # OO interface
342     my $matrix2 = gsl_matrix_alloc(5,5);        # standard interface
345 =head1 Objected Oriented Interface to GSL Math::GSL::Matrix
347 =head2 Math::GSL::Matrix->new()
349 Creates a new Matrix of the given size.
351     my $matrix = Math::GSL::Matrix->new(10,10);
352 =cut
354 sub new 
356     my ($class, $rows, $cols) = @_;
357     my $this = {}; 
358     my $matrix;
359     if ( defined $rows       && defined $cols && 
360         $rows > 0            && $cols > 0     && 
361         (int $rows == $rows) && (int $cols == $cols)){
363         $matrix  = gsl_matrix_alloc($rows,$cols);
364     } else {
365         croak( __PACKAGE__.'::new($x,$y) - $x and $y must be positive integers');
366     }
367     gsl_matrix_set_zero($matrix);
368     $this->{_matrix} = $matrix; 
369     ($this->{_rows}, $this->{_cols}) = ($rows,$cols);
370     bless $this, $class;
372 =head2 raw()
374 Get the underlying GSL matrix object created by SWIG, useful for using gsl_matrix_* functions which do not have an OO counterpart.
376     my $matrix     = Math::GSL::Matrix->new(3,3);
377     my $gsl_matrix = $matrix->raw;
378     my $stuff      = gsl_matrix_get($gsl_matrix, 1, 2);
380 =cut
381 sub raw  { (shift)->{_matrix} }
382 =head2 rows()
384 Returns the number of rows in the matrix.
386     my $rows = $matrix->rows;
387 =cut
389 sub rows { (shift)->{_rows}   }
391 =head2 cols()
393 Returns the number of columns in the matrix.
395     my $cols = $matrix->cols;
396 =cut
398 sub cols { (shift)->{_cols}   }
400 =head2  as_list() 
402 Get the contents of a Math::GSL::Matrix object as a Perl list.
404     my $matrix = Math::GSL::Matrix->new(3,3);
405     ...
406     my @matrix = $matrix->as_list;
407 =cut
410 sub as_list 
412     my $self = shift;
413     my $line;
414     my @part;
415     my @total;
416     for($line=0; $line<$self->rows; $line++){
417        @part = map { 
418          gsl_matrix_get($self->raw, $line, $_) 
419        } (0 .. $self->cols-1 );
420        push(@total, @part);
421     }
422     return @total;
425 =head2 row()
427 Returns a row matrix of the row you enter.
429     my $matrix = Math::GSL::Matrix->new(3,3);
430     ...
431     my $matrix_row = $matrix->row(0);
433 =cut
435 sub row
437     my ($self, $row) = @_;
438     croak (__PACKAGE__.'::$matrix->row($row) - invalid $row value') 
439         unless (($row < $self->rows) and $row >= 0);  
441    my $rowmat = Math::GSL::Matrix->new(1,$self->cols);
443    my @got; 
444    for my $n (0 .. $self->cols-1) {
445     push (@got, gsl_matrix_get($self->raw, $row, $n)); 
446    }
447     for my $n (0 .. $self->cols-1) {
448         gsl_matrix_set($rowmat->raw, 0, $n, $got[$n]); }        
450     return $rowmat;
453 =head2 col()
455 Returns a col matrix of the column you enter.
457     my $matrix = Math::GSL::Matrix->new(3,3);
458     ...
459     my $matrix_col = $matrix->col(0);
461 =cut
463 sub col 
465     my ($self, $col) = @_;
466     croak (__PACKAGE__."::\$matrix->col(\$col) - $col not a valid column") 
467         unless ($col < $self->cols and $col >= 0);  
469     my $colvec = Math::GSL::Vector->new($self->cols);
470     my $colmat = Math::GSL::Matrix->new($self->rows, 1);
472    my @got; 
473    for my $n (0 .. $self->rows-1) {
474     push (@got, gsl_matrix_get($self->raw, $n, $col)); 
475    }
476     for my $n (0 .. $self->rows-1) {
477         gsl_matrix_set($colmat->raw, $n, 0, $got[$n]); }        
479     return $colmat;
482 =head2 set_row()
484 Sets a the values of a row with the elements of an array.
486     my $matrix = Math::GSL::Matrix->new(3,3);
487     $matrix->set_row(0, [8, 6, 2]);
489 You can also set multiple rows at once with chained calls:
490     my $matrix = Math::GSL::Matrix->new(3,3);
491     $matrix->set_row(0, [8, 6, 2])
492            ->set_row(1, [2, 4, 1]);
493     ...
495 =cut
497 sub set_row {
498  my ($self, $row, $values) = @_;
499  my $length = $#$values;
500  die __PACKAGE__.'::new($x, $values) - $values must be a nonempty array reference' if $length == -1;
501  die __PACKAGE__.'::set_row($x, $values) - $x must be a valid row number' if ($row < 0 || $row >= $self->rows);
502  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);
503  map { gsl_matrix_set($self->raw, $row, $_, $values->[$_]) } (0..$length);
504  return $self;
507 =head2 set_col()
509 Sets a the values of a column with the elements of an array.
511     my $matrix = Math::GSL::Matrix->new(3,3);
512     $matrix->set_col(0, [8, 6, 2]);
514 You can also set multiple columns at once with chained calls:
515     my $matrix = Math::GSL::Matrix->new(3,3);
516     $matrix->set_col(0, [8, 6, 2])
517            ->set_col(1, [2, 4, 1]);
518     ...
520 =cut
522 sub set_col {
523  my ($self, $col, $values) = @_;
524  my $length = $#$values;
525  die __PACKAGE__.'::new($x, $values) - $values must be a nonempty array reference' if $length == -1;
526  die __PACKAGE__.'::set_row($x, $values) - $x must be a valid column number' if ($col < 0 || $col >= $self->cols);
527  die __PACKAGE__.'::set_row($x, $values) - $values must contains the same number of elements as there is rowss in the matrix' if($length != $self->rows-1);
528  map { gsl_matrix_set($self->raw, $_, $col, $values->[$_]) } (0..$length);
529  return $self;
532 =head1 DESCRIPTION
534 Here is a list of all the functions included in this module :
536 =over 1
538 =item C<gsl_matrix_alloc($i, $j)> - Return a gsl_matrix of $i rows and $j columns
540 =item C<gsl_matrix_calloc($i, $j)> - Return a gsl_matrix of $i rows and $j columns and initialize all of the elements of the matrix to zero
542 =item C<gsl_matrix_alloc_from_block> - 
544 =item C<gsl_matrix_free> - 
546 =item C<gsl_matrix_alloc_from_matrix > - 
548 =item C<gsl_vector_alloc_row_from_matrix> - 
550 =item C<gsl_vector_alloc_col_from_matrix > - 
552 =item C<gsl_matrix_submatrix($m, $k1, $k2, $n1, $n2)> - Return a matrix view of the matrix $m. The upper-left element of the submatrix is the element ($k1,$k2) of the original matrix. The submatrix has $n1 rows and $n2 columns.
554 =item C<gsl_matrix_row($m , $i)> - Return a vector view of the $i-th row of the matrix $m
556 =item C<gsl_matrix_column($m, $j)> - Return a vector view of the $j-th column of the matrix $m
558 =item C<gsl_matrix_diagonal($m)> - Return a vector view of the diagonal of the vector. The matrix doesn't have to be square.
560 =item C<gsl_matrix_subdiagonal($m, $k)> - Return a vector view of the $k-th subdiagonal of the matrix $m. The diagonal of the matrix corresponds to k=0.
562 =item C<gsl_matrix_superdiagonal($m, $k)> - Return a vector view of the $k-th superdiagonal of the matrix $m. The matrix doesn't have to be square.
564 =item C<gsl_matrix_subrow($m, $i, $offset, $n)> - Return a vector view of the $i-th row of the matrix $m beginning at offset elements and containing n elements.
566 =item C<gsl_matrix_subcolumn($m, $j, $offset, $n)> - Return a vector view of the $j-th column of the matrix $m beginning at offset elements and containing n elements.
568 =item C<gsl_matrix_view_array($base, $n1, $n2)> - This function returns a matrix view of the array reference $base. The matrix has $n1 rows and $n2 columns. The physical number of columns in memory is also given by $n2. Mathematically, the (i,j)-th element of the new matrix is given by, m'(i,j) = $base->[i*$n2 + j] where the index i runs from 0 to $n1-1 and the index j runs from 0 to $n2-1. The new matrix is only a view of the array reference $base. When the view goes out of scope the original array reference $base will continue to exist. The original memory can only be deallocated by freeing the original array. Of course, the original array should not be deallocated while the view is still in use. 
570 =item C<gsl_matrix_view_array_with_tda($base, $n1, $n2, $tda)> - This function returns a matrix view of the array reference $base with a physical number of columns $tda which may differ from the corresponding dimension of the matrix. The matrix has $n1 rows and $n2 columns, and the physical number of columns in memory is given by $tda. Mathematically, the (i,j)-th element of the new matrix is given by, m'(i,j) = $base->[i*$tda + j] where the index i runs from 0 to $n1-1 and the index j runs from 0 to $n2-1. The new matrix is only a view of the array reference $base. When the view goes out of scope the original array reference $base will continue to exist. The original memory can only be deallocated by freeing the original array. Of course, the original array should not be deallocated while the view is still in use.  
572 =item C<gsl_matrix_view_vector> - 
574 =item C<gsl_matrix_view_vector_with_tda> - 
576 =item C<gsl_matrix_const_submatrix> - 
578 =item C<gsl_matrix_get($m, $i, $j)> - Return the (i,j)-th element of the matrix $m
580 =item C<gsl_matrix_set($m, $i, $j, $x)> - Set the value of the (i,j)-th element of the matrix $m to $x
582 =item C<gsl_matrix_ptr> - 
584 =item C<gsl_matrix_const_ptr> - 
586 =item C<gsl_matrix_set_zero($m)> - Set all the elements of the matrix $m to zero
588 =item C<gsl_matrix_set_identity($m)> - Set the elements of the matrix $m to the corresponding elements of the identity matrix
590 =item C<gsl_matrix_set_all($m, $x)> - Set all the elements of the matrix $m to the value $x
592 =item C<gsl_matrix_fread($fh, $m)> - Read a file which has been written with gsl_matrix_fwrite from the stream $fh opened with the gsl_fopen function from the Math::GSL module and stores the data inside the matrix $m
594 =item C<gsl_matrix_fwrite($fh, $m)> - Write the elements of the matrix $m in binary format to a stream $fh opened with the gsl_fopen function from the Math::GSL module
596 =item C<gsl_matrix_fscanf($fh, $m)> - Read a file which has been written with gsl_matrix_fprintf from the stream $fh opened with the gsl_fopenfunction from the Math::GSL module and stores the data inside the matrix $m
598 =item C<gsl_matrix_fprintf($fh, $m, $format)> - Write the elements of the matrix $m in the format $format (for example "%f" is the format for double) to a stream $fh opened with the gsl_fopen function from the Math::GSL module
600 =item C<gsl_matrix_memcpy($dest, $src)> - Copy the elements of the matrix $src to the matrix $dest. The two matrices must have the same size.
602 =item C<gsl_matrix_swap($m1, $m2)> - Exchange the elements of the matrices $m1 and $m2 by copying. The two matrices must have the same size.
604 =item C<gsl_matrix_swap_rows($m, $i, $j)> - Exchange the $i-th and $j-th row of the matrix $m. The function returns 0 if the operation suceeded, 1 otherwise.
606 =item C<gsl_matrix_swap_columns($m, $i, $j)> - Exchange the $i-th and $j-th column of the matrix $m. The function returns 0 if the operation suceeded, 1 otherwise.
608 =item C<gsl_matrix_swap_rowcol($m, $i, $j)> - Exchange the $i-th row and the $j-th column of the matrix $m. The matrix must be square. The function returns 0 if the operation suceeded, 1 otherwise.
610 =item C<gsl_matrix_transpose($m)> - This function replaces the matrix m by its transpose by copying the elements of the matrix in-place. The matrix must be square for this operation to be possible.
612 =item C<gsl_matrix_transpose_memcpy($dest, $src)> - Make the matrix $dest the transpose of the matrix $src. This function works for all matrices provided that the dimensions of the matrix dest match the transposed dimensions of the matrix src. 
614 =item C<gsl_matrix_max($m)> - Return the maximum value in the matrix $m
616 =item C<gsl_matrix_min($m)> - Return the minimum value in the matrix $m
618 =item C<gsl_matrix_minmax($m)> - Return two values, the first is the minimum value of the Matrix $m and the second is the maximum of the same the same matrix.
620 =item C<gsl_matrix_max_index($m)> - Return two values, the first is the the i indice of the maximum value of the matrix $m and the second is the j indice of the same value.
622 =item C<gsl_matrix_min_index($m)> - Return two values, the first is the the i indice of the minimum value of the matrix $m and the second is the j indice of the same value.
624 =item C<gsl_matrix_minmax_index($m)> - Return four values, the first is the i indice of the minimum of the matrix $m, the second is the j indice of the same value, the third is the i indice of the maximum of the matrix $m and the fourth is the j indice of the same value
626 =item C<gsl_matrix_isnull($m)> - Return 1 if all the elements of the matrix $m are zero, 0 otherwise
628 =item C<gsl_matrix_ispos($m)> - Return 1 if all the elements of the matrix $m are strictly positve, 0 otherwise
630 =item C<gsl_matrix_isneg($m)> - Return 1 if all the elements of the matrix $m are strictly negative, 0 otherwise
632 =item C<gsl_matrix_isnonneg($m)> - Return 1 if all the elements of the matrix $m are non-negatuive, 0 otherwise
634 =item C<gsl_matrix_add($a, $b)> - Add the elements of matrix $b to the elements of matrix $a
636 =item C<gsl_matrix_sub($a, $b)> - Subtract the elements of matrix $b from the elements of matrix $a
638 =item C<gsl_matrix_mul_elements($a, $b)> - Multiplie the elements of matrix $a by the elements of matrix $b
640 =item C<gsl_matrix_div_elements($a, $b)> - Divide the elements of matrix $a by the elements of matrix $b
642 =item C<gsl_matrix_scale($a, $x)> - Multiplie the elements of matrix $a by the constant factor $x
644 =item C<gsl_matrix_add_constant($a, $x)> - Add the constant value $x to the elements of the matrix $a
646 =item C<gsl_matrix_add_diagonal($a, $x)> - Add the constant value $x to the elements of the diagonal of the matrix $a
648 =item C<gsl_matrix_get_row($v, $m, $i)> - Copy the elements of the $i-th row of the matrix $m into the vector $v. The lenght of the vector must be of the same as the lenght of the row. The function returns 0 if it succeded, 1 otherwise.
650 =item C<gsl_matrix_get_col($v, $m, $i)> - Copy the elements of the $j-th column of the matrix $m into the vector $v. The lenght of the vector must be of the same as the lenght of the column. The function returns 0 if it succeded, 1 otherwise.
652 =item C<gsl_matrix_set_row($m, $i, $v)> - Copy the elements of vector $v into the $i-th row of the matrix $m The lenght of the vector must be of the same as the lenght of the row. The function returns 0 if it succeded, 1 otherwise.
654 =item C<gsl_matrix_set_col($m, $j, $v)> - Copy the elements of vector $v into the $j-th row of the matrix $m The lenght of the vector must be of the same as the lenght of the column. The function returns 0 if it succeded, 1 otherwise.
656 =back
658 The following functions are specific to matrices containing complex numbers : 
660 =over 1
662 =item C<gsl_matrix_complex_alloc >
664 =item C<gsl_matrix_complex_calloc >
666 =item C<gsl_matrix_complex_alloc_from_block >
668 =item C<gsl_matrix_complex_alloc_from_matrix >
670 =item C<gsl_vector_complex_alloc_row_from_matrix >
672 =item C<gsl_vector_complex_alloc_col_from_matrix >
674 =item C<gsl_matrix_complex_free >
676 =item C<gsl_matrix_complex_submatrix >
678 =item C<gsl_matrix_complex_row >
680 =item C<gsl_matrix_complex_column >
682 =item C<gsl_matrix_complex_diagonal >
684 =item C<gsl_matrix_complex_subdiagonal >
686 =item C<gsl_matrix_complex_superdiagonal >
688 =item C<gsl_matrix_complex_subrow >
690 =item C<gsl_matrix_complex_subcolumn >
692 =item C<gsl_matrix_complex_view_array >
694 =item C<gsl_matrix_complex_view_array_with_tda >
696 =item C<gsl_matrix_complex_view_vector >
698 =item C<gsl_matrix_complex_view_vector_with_tda >
700 =item C<gsl_matrix_complex_const_submatrix >
702 =item C<gsl_matrix_complex_const_row >
704 =item C<gsl_matrix_complex_const_column >
706 =item C<gsl_matrix_complex_const_diagonal >
708 =item C<gsl_matrix_complex_const_subdiagonal >
710 =item C<gsl_matrix_complex_const_superdiagonal >
712 =item C<gsl_matrix_complex_const_subrow >
714 =item C<gsl_matrix_complex_const_subcolumn >
716 =item C<gsl_matrix_complex_const_view_array >
718 =item C<gsl_matrix_complex_const_view_array_with_tda >
720 =item C<gsl_matrix_complex_const_view_vector >
722 =item C<gsl_matrix_complex_const_view_vector_with_tda >
724 =item C<gsl_matrix_complex_get>
726 =item C<gsl_matrix_complex_set>
728 =item C<gsl_matrix_complex_ptr>
730 =item C<gsl_matrix_complex_const_ptr>
732 =item C<gsl_matrix_complex_set_zero >
734 =item C<gsl_matrix_complex_set_identity >
736 =item C<gsl_matrix_complex_set_all >
738 =item C<gsl_matrix_complex_fread >
740 =item C<gsl_matrix_complex_fwrite >
742 =item C<gsl_matrix_complex_fscanf >
744 =item C<gsl_matrix_complex_fprintf >
746 =item C<gsl_matrix_complex_memcpy>
748 =item C<gsl_matrix_complex_swap>
750 =item C<gsl_matrix_complex_swap_rows>
752 =item C<gsl_matrix_complex_swap_columns>
754 =item C<gsl_matrix_complex_swap_rowcol>
756 =item C<gsl_matrix_complex_transpose >
758 =item C<gsl_matrix_complex_transpose_memcpy >
760 =item C<gsl_matrix_complex_isnull >
762 =item C<gsl_matrix_complex_ispos >
764 =item C<gsl_matrix_complex_isneg >
766 =item C<gsl_matrix_complex_add >
768 =item C<gsl_matrix_complex_sub >
770 =item C<gsl_matrix_complex_mul_elements >
772 =item C<gsl_matrix_complex_div_elements >
774 =item C<gsl_matrix_complex_scale >
776 =item C<gsl_matrix_complex_add_constant >
778 =item C<gsl_matrix_complex_add_diagonal >
780 =item C<gsl_matrix_complex_get_row>
782 =item C<gsl_matrix_complex_get_col>
784 =item C<gsl_matrix_complex_set_row>
786 =item C<gsl_matrix_complex_set_col>
788 =back 
790 These are related to constant views of a matrix.
792 =over 1
795 =item C<gsl_matrix_const_row>
797 =item C<gsl_matrix_const_colum>
799 =item C<gsl_matrix_const_diagonal>
801 =item C<gsl_matrix_const_subdiagonal>
803 =item C<gsl_matrix_const_superdiagonal>
805 =item C<gsl_matrix_const_subrow>
807 =item C<gsl_matrix_const_subcolumn>
809 =item C<gsl_matrix_const_view_array>
811 =item C<gsl_matrix_const_view_array_with_tda>
813 =back
816 The following functions are similar to those above but work with C<char>'s and C<int>'s. We are not quite
817 sure if anyone wants these. Please speak up if you do and/or submit some patches to this documentation, please!
819 =over 1
822 =item gsl_matrix_const_view_vector 
824 =item gsl_matrix_const_view_vector_with_tda 
826 =item gsl_matrix_char_alloc 
828 =item gsl_matrix_char_calloc  
830 =item gsl_matrix_char_alloc_from_block
832 =item gsl_matrix_char_alloc_from_matrix 
834 =item gsl_vector_char_alloc_row_from_matrix 
836 =item gsl_vector_char_alloc_col_from_matrix 
838 =item gsl_matrix_char_free 
840 =item gsl_matrix_char_submatrix 
842 =item gsl_matrix_char_row  
844 =item gsl_matrix_char_column 
846 =item gsl_matrix_char_diagonal 
848 =item gsl_matrix_char_subdiagonal 
850 =item gsl_matrix_char_superdiagonal 
852 =item gsl_matrix_char_subrow 
854 =item gsl_matrix_char_subcolumn 
856 =item gsl_matrix_char_view_array 
858 =item gsl_matrix_char_view_array_with_tda 
860 =item gsl_matrix_char_view_vector 
862 =item gsl_matrix_char_view_vector_with_tda 
864 =item gsl_matrix_char_const_submatrix 
866 =item gsl_matrix_char_const_row 
868 =item gsl_matrix_char_const_column 
870 =item gsl_matrix_char_const_diagonal 
872 =item gsl_matrix_char_const_subdiagonal 
874 =item gsl_matrix_char_const_superdiagonal 
876 =item gsl_matrix_char_const_subrow 
878 =item gsl_matrix_char_const_subcolumn 
880 =item gsl_matrix_char_const_view_array 
882 =item gsl_matrix_char_const_view_array_with_tda 
884 =item gsl_matrix_char_const_view_vector 
886 =item gsl_matrix_char_const_view_vector_with_tda 
888 =item gsl_matrix_char_get 
890 =item gsl_matrix_char_set 
892 =item gsl_matrix_char_ptr 
894 =item gsl_matrix_char_const_ptr 
896 =item gsl_matrix_char_set_zero 
898 =item gsl_matrix_char_set_identity 
900 =item gsl_matrix_char_set_all  
902 =item gsl_matrix_char_fread 
904 =item gsl_matrix_char_fwrite 
906 =item gsl_matrix_char_fscanf 
908 =item gsl_matrix_char_fprintf 
910 =item gsl_matrix_char_memcpy 
912 =item gsl_matrix_char_swap 
914 =item gsl_matrix_char_swap_rows 
916 =item gsl_matrix_char_swap_columns
918 =item gsl_matrix_char_swap_rowcol 
920 =item gsl_matrix_char_transpose 
922 =item gsl_matrix_char_transpose_memcpy 
924 =item gsl_matrix_char_max 
926 =item gsl_matrix_char_min 
928 =item gsl_matrix_char_minmax  
930 =item gsl_matrix_char_max_index 
932 =item gsl_matrix_char_min_index 
934 =item gsl_matrix_char_minmax_index  
936 =item gsl_matrix_char_isnull 
938 =item gsl_matrix_char_ispos 
940 =item gsl_matrix_char_isneg 
942 =item gsl_matrix_char_isnonneg  
944 =item gsl_matrix_char_add 
946 =item gsl_matrix_char_sub 
948 =item gsl_matrix_char_mul_elements 
950 =item gsl_matrix_char_div_elements 
952 =item gsl_matrix_char_scale 
954 =item gsl_matrix_char_add_constant 
956 =item gsl_matrix_char_add_diagonal 
958 =item gsl_matrix_int_alloc 
960 =item gsl_matrix_int_calloc 
962 =item gsl_matrix_int_alloc_from_block 
964 =item gsl_matrix_int_alloc_from_matrix 
966 =item gsl_vector_int_alloc_row_from_matrix 
968 =item gsl_vector_int_alloc_col_from_matrix 
970 =item gsl_matrix_int_free 
972 =item gsl_matrix_int_submatrix 
974 =item gsl_matrix_int_row 
976 =item gsl_matrix_int_column 
978 =item gsl_matrix_int_diagonal
980 =item gsl_matrix_int_subdiagonal 
982 =item gsl_matrix_int_superdiagonal 
984 =item gsl_matrix_int_subrow 
986 =item gsl_matrix_int_subcolumn 
988 =item gsl_matrix_int_view_array 
990 =item gsl_matrix_int_view_array_with_tda 
992 =item gsl_matrix_int_view_vector 
994 =item gsl_matrix_int_view_vector_with_tda 
996 =item gsl_matrix_int_const_submatrix 
998 =item gsl_matrix_int_const_row 
1000 =item gsl_matrix_int_const_column 
1002 =item gsl_matrix_int_ptr 
1004 =item gsl_matrix_int_const_ptr 
1006 =item gsl_matrix_int_set_zero 
1008 =item gsl_matrix_int_set_identity 
1010 =item gsl_matrix_int_set_all 
1012 =item gsl_matrix_int_fread 
1014 =item gsl_matrix_int_fwrite 
1016 =item gsl_matrix_int_fscanf 
1018 =item gsl_matrix_int_fprintf 
1020 =item gsl_matrix_int_memcpy 
1022 =item gsl_matrix_int_swap 
1024 =item gsl_matrix_int_swap_rows 
1026 =item gsl_matrix_int_swap_columns 
1028 =item gsl_matrix_int_swap_rowcol
1030 =item gsl_matrix_int_transpose 
1032 =item gsl_matrix_int_transpose_memcpy  
1034 =item gsl_matrix_int_max 
1036 =item gsl_matrix_int_min 
1038 =item gsl_matrix_int_minmax 
1040 =item gsl_matrix_int_max_index 
1042 =item gsl_matrix_int_min_index 
1044 =item gsl_matrix_int_minmax_index  
1046 =item gsl_matrix_int_isnull 
1048 =item gsl_matrix_int_ispos 
1050 =item gsl_matrix_int_isneg 
1052 =item gsl_matrix_int_isnonneg 
1054 =item gsl_matrix_int_add 
1056 =item gsl_matrix_int_sub 
1058 =item gsl_matrix_int_mul_elements 
1060 =item gsl_matrix_int_div_elements 
1062 =item gsl_matrix_int_scale 
1064 =item gsl_matrix_int_add_constant 
1066 =item gsl_matrix_int_add_diagonal
1068 =back
1070 You have to add the functions you want to use inside the qw /put_funtion_here /. 
1071 You can also write use Math::GSL::Matrix qw/:all/ to use all avaible functions of the module. 
1072 Other tags are also avaible, here is a complete list of all tags for this module :
1074 =over 1
1076 =item C<all>
1078 =item C<int>
1080 =item C<double> 
1082 =item C<char> 
1084 =item C<complex>
1086 =back
1088 For more informations on the functions, we refer you to the GSL offcial documentation
1089 L<http://www.gnu.org/software/gsl/manual/html_node/>
1091 Tip : search on google: site:http://www.gnu.org/software/gsl/manual/html_node/name_of_the_function_you_want
1093 =head1 EXAMPLES
1095  Most of the examples from this section are perl versions of the examples at L<http://www.gnu.org/software/gsl/manual/html_node/Example-programs-for-matrices.html>
1097  The program below shows how to allocate, initialize and read from a matrix using the functions gsl_matrix_alloc, gsl_matrix_set and gsl_matrix_get. 
1099  use Math::GSL::Matrix qw/:all/;
1100  my $m = gsl_matrix_alloc (10,3);
1101  for my $i (0..9){
1102     for my $j (0..2){
1103         gsl_matrix_set($m, $i, $j, 0.23 + 100*$i + $j); 
1104     }
1107  for my $i (0..99){ # OUT OF RANGE ERROR
1108      for my $j (0..2){
1109         print "m($i, $j) = " . gsl_matrix_get ($m, $i, $j) . "\n";
1110     }
1112  gsl_matrix_free ($m);
1115  use Math::GSL::Matrix qw/:all/;
1117  my $m = gsl_matrix_alloc (100, 100);
1118  my $a = gsl_matrix_alloc (100, 100);
1120  for my $i (0..99){
1121      for my $j (0..99){
1122          gsl_matrix_set ($m, $i, $j, 0.23 + $i + $j);
1123      }
1126  The next program shows how to write a matrix to a file. 
1128  my $out = gsl_fopen("test.dat", "wb");
1129  gsl_matrix_fwrite ($out, $m);
1130  gsl_fclose ($out);
1132  my $in = gsl_fopen("test.dat", "rb");
1133  gsl_matrix_fread ($in, $a);
1134  gsl_fclose($in);
1136  my $k=0;
1137  for my $i (0..99){
1138      for my $j (0..99){
1139          $mij = gsl_matrix_get ($m, $i, $j);
1140          $aij = gsl_matrix_get ($a, $i, $j);
1141          $k++ if ($mij != $aij);
1142      }
1145  gsl_matrix_free($m);
1146  gsl_matrix_free($a);
1148  print "differences = $k (should be zero)\n";
1150 =head1 AUTHORS
1152 Jonathan Leto <jonathan@leto.net> and Thierry Moisan <thierry.moisan@gmail.com>
1154 =head1 COPYRIGHT AND LICENSE
1156 Copyright (C) 2008 Jonathan Leto and Thierry Moisan
1158 This program is free software; you can redistribute it and/or modify it
1159 under the same terms as Perl itself.
1161 =cut