Refactor verify_results and Build.PL, add Const tests for math constants like $M_PI.
[Math-GSL.git] / Matrix.i
blobbdc51fd707f3544c35878cc9075c3015fc4a9150
1 %module Matrix
3 %apply int *OUTPUT { size_t *imin, size_t *imax, size_t *jmin, size_t *jmax };
5 %apply double *OUTPUT { double * min_out, double * max_out };
6 %{
7 #include "/usr/local/include/gsl/gsl_matrix.h"
8 #include "/usr/local/include/gsl/gsl_complex.h"
9 #include "/usr/local/include/gsl/gsl_vector_double.h"
10 #include "/usr/local/include/gsl/gsl_matrix_double.h"
11 #include "/usr/local/include/gsl/gsl_matrix_int.h"
12 #include "/usr/local/include/gsl/gsl_matrix_complex_double.h"
13 #include "/usr/local/include/gsl/gsl_matrix_char.h"
16 %include "/usr/local/include/gsl/gsl_matrix.h"
17 %include "/usr/local/include/gsl/gsl_complex.h"
18 %include "/usr/local/include/gsl/gsl_vector_double.h"
19 %include "/usr/local/include/gsl/gsl_matrix_double.h"
20 %include "/usr/local/include/gsl/gsl_matrix_int.h"
21 %include "/usr/local/include/gsl/gsl_matrix_complex_double.h"
22 %include "/usr/local/include/gsl/gsl_matrix_char.h"
25 %perlcode %{
27 no warnings 'redefine';
29 @EXPORT_OK = qw/fopen fclose
30 gsl_matrix_alloc gsl_matrix_calloc gsl_matrix_alloc_from_block
31 gsl_matrix_alloc_from_matrix gsl_vector_alloc_row_from_matrix
32 gsl_vector_alloc_col_from_matrix gsl_matrix_free gsl_matrix_submatrix
33 gsl_matrix_row gsl_matrix_column gsl_matrix_diagonal
34 gsl_matrix_subdiagonal gsl_matrix_superdiagonal gsl_matrix_subrow
35 gsl_matrix_subcolumn gsl_matrix_view_array
36 gsl_matrix_view_array_with_tda gsl_matrix_view_vector
37 gsl_matrix_view_vector_with_tda gsl_matrix_const_submatrix
38 gsl_matrix_const_row gsl_matrix_const_column gsl_matrix_const_diagonal
39 gsl_matrix_const_subdiagonal gsl_matrix_const_superdiagonal
40 gsl_matrix_const_subrow gsl_matrix_const_subcolumn
41 gsl_matrix_const_view_array gsl_matrix_const_view_array_with_tda
42 gsl_matrix_const_view_vector gsl_matrix_const_view_vector_with_tda
43 gsl_matrix_get gsl_matrix_set gsl_matrix_ptr gsl_matrix_const_ptr
44 gsl_matrix_set_zero gsl_matrix_set_identity gsl_matrix_set_all
45 gsl_matrix_fread gsl_matrix_fwrite gsl_matrix_fscanf gsl_matrix_fprintf
46 gsl_matrix_memcpy gsl_matrix_swap gsl_matrix_swap_rows
47 gsl_matrix_swap_columns gsl_matrix_swap_rowcol gsl_matrix_transpose
48 gsl_matrix_transpose_memcpy gsl_matrix_max gsl_matrix_min
49 gsl_matrix_minmax gsl_matrix_max_index gsl_matrix_min_index
50 gsl_matrix_minmax_index gsl_matrix_isnull gsl_matrix_ispos
51 gsl_matrix_isneg gsl_matrix_isnonneg gsl_matrix_add gsl_matrix_sub
52 gsl_matrix_mul_elements gsl_matrix_div_elements gsl_matrix_scale
53 gsl_matrix_add_constant gsl_matrix_add_diagonal
54 gsl_matrix_char_alloc gsl_matrix_char_calloc gsl_matrix_char_alloc_from_block
55 gsl_matrix_char_alloc_from_matrix gsl_vector_char_alloc_row_from_matrix gsl_vector_char_alloc_col_from_matrix
56 gsl_matrix_char_free gsl_matrix_char_submatrix
57 gsl_matrix_char_row gsl_matrix_char_column
58 gsl_matrix_char_diagonal gsl_matrix_char_subdiagonal gsl_matrix_char_superdiagonal
59 gsl_matrix_char_subrow gsl_matrix_char_subcolumn gsl_matrix_char_view_array
60 gsl_matrix_char_view_array_with_tda gsl_matrix_char_view_vector gsl_matrix_char_view_vector_with_tda
61 gsl_matrix_char_const_submatrix gsl_matrix_char_const_row gsl_matrix_char_const_column
62 gsl_matrix_char_const_diagonal gsl_matrix_char_const_subdiagonal gsl_matrix_char_const_superdiagonal
63 gsl_matrix_char_const_subrow gsl_matrix_char_const_subcolumn gsl_matrix_char_const_view_array
64 gsl_matrix_char_const_view_array_with_tda gsl_matrix_char_const_view_vector gsl_matrix_char_const_view_vector_with_tda
65 gsl_matrix_char_get gsl_matrix_char_set gsl_matrix_char_ptr gsl_matrix_char_const_ptr
66 gsl_matrix_char_set_zero gsl_matrix_char_set_identity
67 gsl_matrix_char_set_all gsl_matrix_char_fread
68 gsl_matrix_char_fwrite gsl_matrix_char_fscanf gsl_matrix_char_fprintf
69 gsl_matrix_char_memcpy gsl_matrix_char_swap
70 gsl_matrix_char_swap_rows gsl_matrix_char_swap_columns
71 gsl_matrix_char_swap_rowcol gsl_matrix_char_transpose gsl_matrix_char_transpose_memcpy
72 gsl_matrix_char_max gsl_matrix_char_min
73 gsl_matrix_char_minmax gsl_matrix_char_max_index
74 gsl_matrix_char_min_index gsl_matrix_char_minmax_index
75 gsl_matrix_char_isnull gsl_matrix_char_ispos gsl_matrix_char_isneg
76 gsl_matrix_char_isnonneg gsl_matrix_char_add
77 gsl_matrix_char_sub gsl_matrix_char_mul_elements gsl_matrix_char_div_elements
78 gsl_matrix_char_scale gsl_matrix_char_add_constant gsl_matrix_char_add_diagonal
79 gsl_matrix_int_alloc gsl_matrix_int_calloc gsl_matrix_int_alloc_from_block
80 gsl_matrix_int_alloc_from_matrix gsl_vector_int_alloc_row_from_matrix gsl_vector_int_alloc_col_from_matrix
81 gsl_matrix_int_free gsl_matrix_int_submatrix gsl_matrix_int_row
82 gsl_matrix_int_column gsl_matrix_int_diagonal gsl_matrix_int_subdiagonal
83 gsl_matrix_int_superdiagonal gsl_matrix_int_subrow gsl_matrix_int_subcolumn gsl_matrix_int_view_array
84 gsl_matrix_int_view_array_with_tda gsl_matrix_int_view_vector gsl_matrix_int_view_vector_with_tda
85 gsl_matrix_int_const_submatrix gsl_matrix_int_const_row gsl_matrix_int_const_column
86 gsl_matrix_int_const_diagonal gsl_matrix_int_const_subdiagonal gsl_matrix_int_const_superdiagonal
87 gsl_matrix_int_const_subrow gsl_matrix_int_const_subcolumn gsl_matrix_int_const_view_array
88 gsl_matrix_int_const_view_array_with_tda gsl_matrix_int_const_view_vector gsl_matrix_int_const_view_vector_with_tda
89 gsl_matrix_int_get gsl_matrix_int_set
90 gsl_matrix_int_ptr gsl_matrix_int_const_ptr
91 gsl_matrix_int_set_zero gsl_matrix_int_set_identity gsl_matrix_int_set_all
92 gsl_matrix_int_fread gsl_matrix_int_fwrite
93 gsl_matrix_int_fscanf gsl_matrix_int_fprintf
94 gsl_matrix_int_memcpy gsl_matrix_int_swap
95 gsl_matrix_int_swap_rows gsl_matrix_int_swap_columns gsl_matrix_int_swap_rowcol
96 gsl_matrix_int_transpose gsl_matrix_int_transpose_memcpy
97 gsl_matrix_int_max gsl_matrix_int_min gsl_matrix_int_minmax
98 gsl_matrix_int_max_index gsl_matrix_int_min_index
99 gsl_matrix_int_minmax_index gsl_matrix_int_isnull
100 gsl_matrix_int_ispos gsl_matrix_int_isneg gsl_matrix_int_isnonneg
101 gsl_matrix_int_add gsl_matrix_int_sub
102 gsl_matrix_int_mul_elements gsl_matrix_int_div_elements gsl_matrix_int_scale
103 gsl_matrix_int_add_constant gsl_matrix_int_add_diagonal
104 gsl_matrix_get_row gsl_matrix_get_col gsl_matrix_set_row gsl_matrix_set_col
105 gsl_matrix_complex_alloc gsl_matrix_complex_calloc gsl_matrix_complex_alloc_from_block
106 gsl_matrix_complex_alloc_from_matrix gsl_vector_complex_alloc_row_from_matrix gsl_vector_complex_alloc_col_from_matrix
107 gsl_matrix_complex_free gsl_matrix_complex_submatrix gsl_matrix_complex_row
108 gsl_matrix_complex_column gsl_matrix_complex_diagonal gsl_matrix_complex_subdiagonal
109 gsl_matrix_complex_superdiagonal gsl_matrix_complex_subrow gsl_matrix_complex_subcolumn
110 gsl_matrix_complex_view_array gsl_matrix_complex_view_array_with_tda gsl_matrix_complex_view_vector
111 gsl_matrix_complex_view_vector_with_tda gsl_matrix_complex_const_submatrix gsl_matrix_complex_const_row
112 gsl_matrix_complex_const_column gsl_matrix_complex_const_diagonal gsl_matrix_complex_const_subdiagonal
113 gsl_matrix_complex_const_superdiagonal gsl_matrix_complex_const_subrow gsl_matrix_complex_const_subcolumn
114 gsl_matrix_complex_const_view_array gsl_matrix_complex_const_view_array_with_tda gsl_matrix_complex_const_view_vector
115 gsl_matrix_complex_const_view_vector_with_tda gsl_matrix_complex_get gsl_matrix_complex_set
116 gsl_matrix_complex_ptr gsl_matrix_complex_const_ptr gsl_matrix_complex_set_zero
117 gsl_matrix_complex_set_identity gsl_matrix_complex_set_all gsl_matrix_complex_fread
118 gsl_matrix_complex_fwrite gsl_matrix_complex_fscanf gsl_matrix_complex_fprintf
119 gsl_matrix_complex_memcpy gsl_matrix_complex_swap gsl_matrix_complex_swap_rows
120 gsl_matrix_complex_swap_columns gsl_matrix_complex_swap_rowcol gsl_matrix_complex_transpose
121 gsl_matrix_complex_transpose_memcpy gsl_matrix_complex_isnull gsl_matrix_complex_ispos
122 gsl_matrix_complex_isneg gsl_matrix_complex_add gsl_matrix_complex_sub
123 gsl_matrix_complex_mul_elements gsl_matrix_complex_div_elements gsl_matrix_complex_scale
124 gsl_matrix_complex_add_constant gsl_matrix_complex_add_diagonal gsl_matrix_complex_get_row
125 gsl_matrix_complex_get_col gsl_matrix_complex_set_row gsl_matrix_complex_set_col /;
129 %EXPORT_TAGS = ( all => [ @EXPORT_OK ],
130 char => [ qw/
131 gsl_matrix_char_alloc
132 gsl_matrix_char_calloc
133 gsl_matrix_char_alloc_from_block
134 gsl_matrix_char_alloc_from_matrix
135 gsl_vector_char_alloc_row_from_matrix
136 gsl_vector_char_alloc_col_from_matrix
137 gsl_matrix_char_free
138 gsl_matrix_char_submatrix
139 gsl_matrix_char_row
140 gsl_matrix_char_column
141 gsl_matrix_char_diagonal
142 gsl_matrix_char_subdiagonal
143 gsl_matrix_char_superdiagonal
144 gsl_matrix_char_subrow
145 gsl_matrix_char_subcolumn
146 gsl_matrix_char_view_array
147 gsl_matrix_char_view_array_with_tda
148 gsl_matrix_char_view_vector
149 gsl_matrix_char_view_vector_with_tda
150 gsl_matrix_char_const_submatrix
151 gsl_matrix_char_const_row
152 gsl_matrix_char_const_column
153 gsl_matrix_char_const_diagonal
154 gsl_matrix_char_const_subdiagonal
155 gsl_matrix_char_const_superdiagonal
156 gsl_matrix_char_const_subrow
157 gsl_matrix_char_const_subcolumn
158 gsl_matrix_char_const_view_array
159 gsl_matrix_char_const_view_array_with_tda
160 gsl_matrix_char_const_view_vector
161 gsl_matrix_char_const_view_vector_with_tda
162 gsl_matrix_char_get
163 gsl_matrix_char_set
164 gsl_matrix_char_ptr
165 gsl_matrix_char_const_ptr
166 gsl_matrix_char_set_zero
167 gsl_matrix_char_set_identity
168 gsl_matrix_char_set_all
169 gsl_matrix_char_fread
170 gsl_matrix_char_fwrite
171 gsl_matrix_char_fscanf
172 gsl_matrix_char_fprintf
173 gsl_matrix_char_memcpy
174 gsl_matrix_char_swap
175 gsl_matrix_char_swap_rows
176 gsl_matrix_char_swap_columns
177 gsl_matrix_char_swap_rowcol
178 gsl_matrix_char_transpose
179 gsl_matrix_char_transpose_memcpy
180 gsl_matrix_char_max
181 gsl_matrix_char_min
182 gsl_matrix_char_minmax
183 gsl_matrix_char_max_index
184 gsl_matrix_char_min_index
185 gsl_matrix_char_minmax_index
186 gsl_matrix_char_isnull
187 gsl_matrix_char_ispos
188 gsl_matrix_char_isneg
189 gsl_matrix_char_isnonneg
190 gsl_matrix_char_add
191 gsl_matrix_char_sub
192 gsl_matrix_char_mul_elements
193 gsl_matrix_char_div_elements
194 gsl_matrix_char_scale
195 gsl_matrix_char_add_constant
196 gsl_matrix_char_add_diagonal
199 double => [ qw/
200 gsl_matrix_alloc
201 gsl_matrix_calloc
202 gsl_matrix_alloc_from_block
203 gsl_matrix_alloc_from_matrix
204 gsl_vector_alloc_row_from_matrix
205 gsl_vector_alloc_col_from_matrix
206 gsl_matrix_free
207 gsl_matrix_submatrix
208 gsl_matrix_row
209 gsl_matrix_column
210 gsl_matrix_diagonal
211 gsl_matrix_subdiagonal
212 gsl_matrix_superdiagonal
213 gsl_matrix_subrow
214 gsl_matrix_subcolumn
215 gsl_matrix_view_array
216 gsl_matrix_view_array_with_tda
217 gsl_matrix_view_vector
218 gsl_matrix_view_vector_with_tda
219 gsl_matrix_const_submatrix
220 gsl_matrix_const_row
221 gsl_matrix_const_column
222 gsl_matrix_const_diagonal
223 gsl_matrix_const_subdiagonal
224 gsl_matrix_const_superdiagonal
225 gsl_matrix_const_subrow
226 gsl_matrix_const_subcolumn
227 gsl_matrix_const_view_array
228 gsl_matrix_const_view_array_with_tda
229 gsl_matrix_const_view_vector
230 gsl_matrix_const_view_vector_with_tda
231 gsl_matrix_get
232 gsl_matrix_set
233 gsl_matrix_ptr
234 gsl_matrix_const_ptr
235 gsl_matrix_set_zero
236 gsl_matrix_set_identity
237 gsl_matrix_set_all
238 gsl_matrix_fread
239 gsl_matrix_fwrite
240 gsl_matrix_fscanf
241 gsl_matrix_fprintf
242 gsl_matrix_memcpy
243 gsl_matrix_swap
244 gsl_matrix_swap_rows
245 gsl_matrix_swap_columns
246 gsl_matrix_swap_rowcol
247 gsl_matrix_transpose
248 gsl_matrix_transpose_memcpy
249 gsl_matrix_max
250 gsl_matrix_minmax
251 gsl_matrix_max_index
252 gsl_matrix_min_index
253 gsl_matrix_minmax_index
254 gsl_matrix_isnull
255 gsl_matrix_ispos
256 gsl_matrix_isneg
257 gsl_matrix_isnonneg
258 gsl_matrix_add
259 gsl_matrix_mul_elements
260 gsl_matrix_div_elements
261 gsl_matrix_scale
262 gsl_matrix_add_constant
263 gsl_matrix_add_diagonal
265 int => [ qw/
266 gsl_matrix_int_alloc
267 gsl_matrix_int_alloc_from_matrix
268 gsl_matrix_int_free
269 gsl_matrix_int_column
270 gsl_matrix_int_superdiagonal
271 gsl_matrix_int_view_array_with_tda
272 gsl_matrix_int_const_submatrix
273 gsl_matrix_int_const_diagonal
274 gsl_matrix_int_const_subrow
275 gsl_matrix_int_const_view_array_with_tda
276 gsl_matrix_int_get
277 gsl_matrix_int_ptr
278 gsl_matrix_int_set_zero
279 gsl_matrix_int_fread
280 gsl_matrix_int_fscanf
281 gsl_matrix_int_memcpy
282 gsl_matrix_int_swap_rows
283 gsl_matrix_int_transpose
284 gsl_matrix_int_max
285 gsl_matrix_int_max_index
286 gsl_matrix_int_minmax_index
287 gsl_matrix_int_ispos
288 gsl_matrix_int_add
289 gsl_matrix_int_mul_elements
290 gsl_matrix_int_add_constant
292 complex => [ qw/
293 gsl_matrix_complex_alloc
294 gsl_matrix_complex_calloc
295 gsl_matrix_complex_alloc_from_block
296 gsl_matrix_complex_alloc_from_matrix
297 gsl_vector_complex_alloc_row_from_matrix
298 gsl_vector_complex_alloc_col_from_matrix
299 gsl_matrix_complex_free
300 gsl_matrix_complex_submatrix
301 gsl_matrix_complex_row
302 gsl_matrix_complex_column
303 gsl_matrix_complex_diagonal
304 gsl_matrix_complex_subdiagonal
305 gsl_matrix_complex_superdiagonal
306 gsl_matrix_complex_subrow
307 gsl_matrix_complex_subcolumn
308 gsl_matrix_complex_view_array
309 gsl_matrix_complex_view_array_with_tda
310 gsl_matrix_complex_view_vector
311 gsl_matrix_complex_view_vector_with_tda
312 gsl_matrix_complex_const_submatrix
313 gsl_matrix_complex_const_row
314 gsl_matrix_complex_const_column
315 gsl_matrix_complex_const_diagonal
316 gsl_matrix_complex_const_subdiagonal
317 gsl_matrix_complex_const_superdiagonal
318 gsl_matrix_complex_const_subrow
319 gsl_matrix_complex_const_subcolumn
320 gsl_matrix_complex_const_view_array
321 gsl_matrix_complex_const_view_array_with_tda
322 gsl_matrix_complex_const_view_vector
323 gsl_matrix_complex_const_view_vector_with_tda
324 gsl_matrix_complex_get
325 gsl_matrix_complex_set
326 gsl_matrix_complex_ptr
327 gsl_matrix_complex_const_ptr
328 gsl_matrix_complex_set_zero gsl_matrix_complex_set_identity
329 gsl_matrix_complex_set_all
330 gsl_matrix_complex_fread
331 gsl_matrix_complex_fwrite
332 gsl_matrix_complex_fscanf
333 gsl_matrix_complex_fprintf
334 gsl_matrix_complex_memcpygsl_matrix_complex_swap
335 gsl_matrix_complex_swap_rows
336 gsl_matrix_complex_swap_columns
337 gsl_matrix_complex_swap_rowcol
338 gsl_matrix_complex_transpose
339 gsl_matrix_complex_transpose_memcpy
340 gsl_matrix_complex_isnull
341 gsl_matrix_complex_ispos
342 gsl_matrix_complex_isneg
343 gsl_matrix_complex_add
344 gsl_matrix_complex_sub
345 gsl_matrix_complex_mul_elements
346 gsl_matrix_complex_div_elements
347 gsl_matrix_complex_scale
348 gsl_matrix_complex_add_constant
349 gsl_matrix_complex_add_diagonal
350 gsl_matrix_complex_get_row
351 gsl_matrix_complex_get_col
352 gsl_matrix_complex_set_row
353 gsl_matrix_complex_set_col
354 /]);
356 =head1 NAME
358 Math::GSL::Matrix - Mathematical functions concerning Matrices
360 =head1 SYPNOPSIS
362 use Math::GSL::Matrix qw/:all/;
363 my $matrix1 = Math::GSL::Matrix->new(5,5); # OO interface
364 my $matrix2 = gsl_matrix_alloc(5,5); # standard interface
367 =head1 Objected Oriented Interface to GSL Math::GSL::Matrix
369 my $matrix = Math::GSL::Matrix->new(10,10);
370 printf "My matrix is %d x %d\n", $matrix->rows, $matrix->cols;
371 =cut
373 sub new
375 my ($class, $rows, $cols) = @_;
376 my $this = {};
377 my $matrix;
378 if ( defined $rows && defined $cols &&
379 $rows > 0 && $cols > 0 &&
380 (int $rows == $rows) && (int $cols == $cols)){
382 $matrix = gsl_matrix_alloc($rows,$cols);
383 } else {
384 die __PACKAGE__.'::new($x,$y) - $x and $y must be positive integers';
386 gsl_matrix_set_zero($matrix);
387 $this->{_matrix} = $matrix;
388 ($this->{_rows}, $this->{_cols}) = ($rows,$cols);
389 bless $this, $class;
391 =head2 raw()
393 Get the underlying GSL matrix object created by SWIG, useful for using gsl_matrix_* functions which do not have an OO counterpart.
395 my $matrix = Math::GSL::Matrix->new(3,3);
396 my $gsl_matrix = $matrix->raw;
397 my $stuff = gsl_matrix_get($gsl_matrix, 1, 2);
399 =cut
400 sub raw { (shift)->{_matrix} }
401 =head2 rows()
403 Returns the number of rows in the matrix.
405 my $rows = $matrix->rows;
406 =cut
408 sub rows { (shift)->{_rows} }
410 =head2 cols()
412 Returns the number of columns in the matrix.
414 my $cols = $matrix->cols;
415 =cut
417 sub cols { (shift)->{_cols} }
419 =head2 as_list()
421 Get the contents of a Math::GSL::Matrix object as a Perl list.
423 my $matrix = Math::GSL::Matrix->new(3,3);
425 my @matrix = $matrix->as_list;
426 =cut
429 sub as_list
431 my $self = shift;
432 my ($r,$c) = ($self->rows,$self->cols);
433 return (map
435 gsl_matrix_get($self->raw, _index_to_row_col($_,$r,$c))
436 } (0 .. $self->rows*$self->cols-1 ));
439 sub _index_to_row_col($$$)
441 my ($k,$rows,$cols) = @_;
442 return ( int($k/$rows), $k % $cols );
446 =head1 DESCRIPTION
448 Here is a list of all the functions included in this module :
450 =over 1
452 =item C<gsl_matrix_alloc($i, $j)> - Return a gsl_matrix of $i rows and $j columns
454 =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
456 =item C<gsl_matrix_alloc_from_block> -
458 =item C<gsl_matrix_free> -
460 =item C<gsl_matrix_alloc_from_matrix > -
462 =item C<gsl_vector_alloc_row_from_matrix> -
464 =item C<gsl_vector_alloc_col_from_matrix > -
466 =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.
468 =item C<gsl_matrix_row($m , $i)> - Return a vector view of the $i-th row of the matrix $m
470 =item C<gsl_matrix_column($m, $j)> - Return a vector view of the $j-th column of the matrix $m
472 =item C<gsl_matrix_diagonal($m)> - Return a vector view of the diagonal of the vector. The matrix doesn't have to be square.
474 =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.
476 =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.
478 =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.
480 =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.
482 =item C<gsl_matrix_view_array> -
484 =item C<gsl_matrix_view_array_with_tda > -
486 =item C<gsl_matrix_view_vector> -
488 =item C<gsl_matrix_view_vector_with_tda> -
490 =item C<gsl_matrix_const_submatrix> -
492 =item C<gsl_matrix_get($m, $i, $j)> - Return the (i,j)-th element of the matrix $m
494 =item C<gsl_matrix_set($m, $i, $j, $x)> - Set the value of the (i,j)-th element of the matrix $m to $x
496 =item C<gsl_matrix_ptr> -
498 =item C<gsl_matrix_const_ptr> -
500 =item C<gsl_matrix_set_zero($m)> - Set all the elements of the matrix $m to zero
502 =item C<gsl_matrix_set_identity($m)> - Set the elements of the matrix $m to the corresponding elements of the identity matrix
504 =item C<gsl_matrix_set_all($m, $x)> - Set all the elements of the matrix $m to the value $x
506 =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 fopen function and stores the data inside the matrix $m
508 =item C<gsl_matrix_fwrite($fh, $m)> - Write the elements of the matrix $m in binary format to a stream $fh opened with the fopen function
510 =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 fopen function and stores the data inside the matrix $m
512 =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 fopen function
514 =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.
516 =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.
518 =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.
520 =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.
522 =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.
524 =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.
526 =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.
528 =item C<gsl_matrix_max($m)> - Return the maximum value in the matrix $m
530 =item C<gsl_matrix_min($m)> - Return the minimum value in the matrix $m
532 =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.
534 =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.
536 =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.
538 =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
540 =item C<gsl_matrix_isnull($m)> - Return 1 if all the elements of the matrix $m are zero, 0 otherwise
542 =item C<gsl_matrix_ispos($m)> - Return 1 if all the elements of the matrix $m are strictly positve, 0 otherwise
544 =item C<gsl_matrix_isneg($m)> - Return 1 if all the elements of the matrix $m are strictly negative, 0 otherwise
546 =item C<gsl_matrix_isnonneg($m)> - Return 1 if all the elements of the matrix $m are non-negatuive, 0 otherwise
548 =item C<gsl_matrix_add($a, $b)> - Add the elements of matrix $b to the elements of matrix $a
550 =item C<gsl_matrix_sub($a, $b)> - Subtract the elements of matrix $b from the elements of matrix $a
552 =item C<gsl_matrix_mul_elements($a, $b)> - Multiplie the elements of matrix $a by the elements of matrix $b
554 =item C<gsl_matrix_div_elements($a, $b)> - Divide the elements of matrix $a by the elements of matrix $b
556 =item C<gsl_matrix_scale($a, $x)> - Multiplie the elements of matrix $a by the constant factor $x
558 =item C<gsl_matrix_add_constant($a, $x)> - Add the constant value $x to the elements of the matrix $a
560 =item C<gsl_matrix_add_diagonal($a, $x)> - Add the constant value $x to the elements of the diagonal of the matrix $a
562 =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.
564 =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.
566 =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.
568 =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.
570 =back
572 The following functions are specific to matrices containing complex numbers :
574 =over 1
576 =item C<gsl_matrix_complex_alloc >
578 =item C<gsl_matrix_complex_calloc >
580 =item C<gsl_matrix_complex_alloc_from_block >
582 =item C<gsl_matrix_complex_alloc_from_matrix >
584 =item C<gsl_vector_complex_alloc_row_from_matrix >
586 =item C<gsl_vector_complex_alloc_col_from_matrix >
588 =item C<gsl_matrix_complex_free >
590 =item C<gsl_matrix_complex_submatrix >
592 =item C<gsl_matrix_complex_row >
594 =item C<gsl_matrix_complex_column >
596 =item C<gsl_matrix_complex_diagonal >
598 =item C<gsl_matrix_complex_subdiagonal >
600 =item C<gsl_matrix_complex_superdiagonal >
602 =item C<gsl_matrix_complex_subrow >
604 =item C<gsl_matrix_complex_subcolumn >
606 =item C<gsl_matrix_complex_view_array >
608 =item C<gsl_matrix_complex_view_array_with_tda >
610 =item C<gsl_matrix_complex_view_vector >
612 =item C<gsl_matrix_complex_view_vector_with_tda >
614 =item C<gsl_matrix_complex_const_submatrix >
616 =item C<gsl_matrix_complex_const_row >
618 =item C<gsl_matrix_complex_const_column >
620 =item C<gsl_matrix_complex_const_diagonal >
622 =item C<gsl_matrix_complex_const_subdiagonal >
624 =item C<gsl_matrix_complex_const_superdiagonal >
626 =item C<gsl_matrix_complex_const_subrow >
628 =item C<gsl_matrix_complex_const_subcolumn >
630 =item C<gsl_matrix_complex_const_view_array >
632 =item C<gsl_matrix_complex_const_view_array_with_tda >
634 =item C<gsl_matrix_complex_const_view_vector >
636 =item C<gsl_matrix_complex_const_view_vector_with_tda >
638 =item C<gsl_matrix_complex_get>
640 =item C<gsl_matrix_complex_set>
642 =item C<gsl_matrix_complex_ptr>
644 =item C<gsl_matrix_complex_const_ptr>
646 =item C<gsl_matrix_complex_set_zero >
648 =item C<gsl_matrix_complex_set_identity >
650 =item C<gsl_matrix_complex_set_all >
652 =item C<gsl_matrix_complex_fread >
654 =item C<gsl_matrix_complex_fwrite >
656 =item C<gsl_matrix_complex_fscanf >
658 =item C<gsl_matrix_complex_fprintf >
660 =item C<gsl_matrix_complex_memcpy>
662 =item C<gsl_matrix_complex_swap>
664 =item C<gsl_matrix_complex_swap_rows>
666 =item C<gsl_matrix_complex_swap_columns>
668 =item C<gsl_matrix_complex_swap_rowcol>
670 =item C<gsl_matrix_complex_transpose >
672 =item C<gsl_matrix_complex_transpose_memcpy >
674 =item C<gsl_matrix_complex_isnull >
676 =item C<gsl_matrix_complex_ispos >
678 =item C<gsl_matrix_complex_isneg >
680 =item C<gsl_matrix_complex_add >
682 =item C<gsl_matrix_complex_sub >
684 =item C<gsl_matrix_complex_mul_elements >
686 =item C<gsl_matrix_complex_div_elements >
688 =item C<gsl_matrix_complex_scale >
690 =item C<gsl_matrix_complex_add_constant >
692 =item C<gsl_matrix_complex_add_diagonal >
694 =item C<gsl_matrix_complex_get_row>
696 =item C<gsl_matrix_complex_get_col>
698 =item C<gsl_matrix_complex_set_row>
700 =item C<gsl_matrix_complex_set_col>
702 =back
705 The following functions are the same as the previous enonced ones except that they work with other data types than double.
707 =over 1
709 =item gsl_matrix_const_row gsl_matrix_const_column gsl_matrix_const_diagonal
711 =item gsl_matrix_const_subdiagonal gsl_matrix_const_superdiagonal
713 =item gsl_matrix_const_subrow gsl_matrix_const_subcolumn
715 =item gsl_matrix_const_view_array gsl_matrix_const_view_array_with_tda
717 =item gsl_matrix_const_view_vector gsl_matrix_const_view_vector_with_tda gsl_matrix_char_alloc gsl_matrix_char_calloc gsl_matrix_char_alloc_from_block
719 =item gsl_matrix_char_alloc_from_matrix gsl_vector_char_alloc_row_from_matrix gsl_vector_char_alloc_col_from_matrix
721 =item gsl_matrix_char_free gsl_matrix_char_submatrix gsl_matrix_char_row gsl_matrix_char_column
723 =item gsl_matrix_char_diagonal gsl_matrix_char_subdiagonal gsl_matrix_char_superdiagonal
725 =item gsl_matrix_char_subrow gsl_matrix_char_subcolumn gsl_matrix_char_view_array
727 =item gsl_matrix_char_view_array_with_tda gsl_matrix_char_view_vector gsl_matrix_char_view_vector_with_tda
729 =item gsl_matrix_char_const_submatrix gsl_matrix_char_const_row gsl_matrix_char_const_column
731 =item gsl_matrix_char_const_diagonal gsl_matrix_char_const_subdiagonal gsl_matrix_char_const_superdiagonal
733 =item gsl_matrix_char_const_subrow gsl_matrix_char_const_subcolumn gsl_matrix_char_const_view_array
735 =item gsl_matrix_char_const_view_array_with_tda gsl_matrix_char_const_view_vector gsl_matrix_char_const_view_vector_with_tda
737 =item gsl_matrix_char_get gsl_matrix_char_set gsl_matrix_char_ptr gsl_matrix_char_const_ptr
739 =item gsl_matrix_char_set_zero gsl_matrix_char_set_identity
741 =item gsl_matrix_char_set_all gsl_matrix_char_fread
743 =item gsl_matrix_char_fwrite gsl_matrix_char_fscanf gsl_matrix_char_fprintf
745 =item gsl_matrix_char_memcpy gsl_matrix_char_swap
747 =item gsl_matrix_char_swap_rows gsl_matrix_char_swap_columns
749 =item gsl_matrix_char_swap_rowcol gsl_matrix_char_transpose gsl_matrix_char_transpose_memcpy
751 =item gsl_matrix_char_max gsl_matrix_char_min
753 =item gsl_matrix_char_minmax gsl_matrix_char_max_index
755 =item gsl_matrix_char_min_index gsl_matrix_char_minmax_index
757 =item gsl_matrix_char_isnull gsl_matrix_char_ispos gsl_matrix_char_isneg
759 =item gsl_matrix_char_isnonneg gsl_matrix_char_add
761 =item gsl_matrix_char_sub gsl_matrix_char_mul_elements gsl_matrix_char_div_elements
763 =item gsl_matrix_char_scale gsl_matrix_char_add_constant gsl_matrix_char_add_diagonal
765 =item gsl_matrix_int_alloc gsl_matrix_int_calloc gsl_matrix_int_alloc_from_block
767 =item gsl_matrix_int_alloc_from_matrix gsl_vector_int_alloc_row_from_matrix gsl_vector_int_alloc_col_from_matrix
769 =item gsl_matrix_int_free gsl_matrix_int_submatrix gsl_matrix_int_row
771 =item gsl_matrix_int_column gsl_matrix_int_diagonal gsl_matrix_int_subdiagonal gsl_matrix_int_superdiagonal gsl_matrix_int_subrow gsl_matrix_int_subcolumn gsl_matrix_int_view_array gsl_matrix_int_view_array_with_tda gsl_matrix_int_view_vector gsl_matrix_int_view_vector_with_tda
773 =item gsl_matrix_int_const_submatrix gsl_matrix_int_const_row gsl_matrix_int_const_column
776 =item gsl_matrix_int_const_diagonal gsl_matrix_int_const_subdiagonal gsl_matrix_int_const_superdiagonal
778 =item gsl_matrix_int_const_subrow gsl_matrix_int_const_subcolumn gsl_matrix_int_const_view_array
780 =item gsl_matrix_int_const_view_array_with_tda gsl_matrix_int_const_view_vector gsl_matrix_int_const_view_vector_with_tda
782 =item gsl_matrix_int_get gsl_matrix_int_set
784 =item gsl_matrix_int_ptr gsl_matrix_int_const_ptr
786 =item gsl_matrix_int_set_zero gsl_matrix_int_set_identity gsl_matrix_int_set_all
788 =item gsl_matrix_int_fread gsl_matrix_int_fwrite
790 =item gsl_matrix_int_fscanf gsl_matrix_int_fprintf
792 =item gsl_matrix_int_memcpy gsl_matrix_int_swap
794 =item gsl_matrix_int_swap_rows gsl_matrix_int_swap_columns gsl_matrix_int_swap_rowcol
796 =item gsl_matrix_int_transpose gsl_matrix_int_transpose_memcpy
798 =item gsl_matrix_int_max gsl_matrix_int_min gsl_matrix_int_minmax
800 =item gsl_matrix_int_max_index gsl_matrix_int_min_index
802 =item gsl_matrix_int_minmax_index gsl_matrix_int_isnull
804 =item gsl_matrix_int_ispos gsl_matrix_int_isneg gsl_matrix_int_isnonneg
806 =item gsl_matrix_int_add gsl_matrix_int_sub
808 =item gsl_matrix_int_mul_elements gsl_matrix_int_div_elements gsl_matrix_int_scale
810 =item gsl_matrix_int_add_constant gsl_matrix_int_add_diagonal
812 =back
814 You have to add the functions you want to use inside the qw /put_funtion_here /.
815 You can also write use Math::GSL::PowInt qw/:all/ to use all avaible functions of the module.
816 Other tags are also avaible, here is a complete list of all tags for this module :
818 =over 1
820 =item C<all>
822 =item C<int>
824 =item C<double>
826 =item C<char>
828 =item C<complex>
830 =back
832 For more informations on the functions, we refer you to the GSL offcial documentation: http://www.gnu.org/software/gsl/manual/html_node/
833 Tip : search on google: site:http://www.gnu.org/software/gsl/manual/html_node/name_of_the_function_you_want
835 =head1 EXAMPLES
837 Most of the examples from this section are perl versions of the examples there : http://www.gnu.org/software/gsl/manual/html_node/Example-programs-for-matrices.html
839 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.
841 use Math::GSL::Matrix qw/:all/;
842 $m = gsl_matrix_alloc (10,3);
843 for($i = 0; $i< 10; $i++){
844 for($j = 0; $j<3; $j++){
845 gsl_matrix_set($m, $i, $j, 0.23 + 100*$i + $j);
849 for($i = 0; $i< 100; $i++){ # OUT OF RANGE ERROR
850 for($j=0; $j<3; $j++){
851 print "m($i, $j) = " . gsl_matrix_get ($m, $i, $j) . "\n";
854 gsl_matrix_free ($m);
857 use Math::GSL::Matrix qw/:all/;
859 $m = gsl_matrix_alloc (100, 100);
860 $a = gsl_matrix_alloc (100, 100);
862 for($i = 0; $i < 100; $i++){
863 for($j = 0; $j < 100; $j++){
864 gsl_matrix_set ($m, $i, $j, 0.23 + $i + $j);
868 The next program shows how to write a matrix to a file.
870 $out = fopen("test.dat", "wb");
871 gsl_matrix_fwrite ($out, $m);
872 fclose ($out);
874 $in = fopen("test.dat", "rb");
875 gsl_matrix_fread ($in, $a);
876 fclose($in);
878 $k=0;
879 for($i = 0; $i < 100; $i++){
880 for($j = 0; $j < 100; $j++){
881 $mij = gsl_matrix_get ($m, $i, $j);
882 $aij = gsl_matrix_get ($a, $i, $j);
883 if ($mij != $aij){ $k++ };
887 gsl_matrix_free($m);
888 gsl_matrix_free($a);
890 print "differences = $k (should be zero)\n";
892 =head1 AUTHOR
894 Jonathan Leto <jonathan@leto.net> and Thierry Moisan <thierry.moisan@gmail.com>
896 =head1 COPYRIGHT AND LICENSE
898 Copyright (C) 2008 Jonathan Leto and Thierry Moisan
900 This program is free software; you can redistribute it and/or modify it
901 under the same terms as Perl itself.
903 =cut