Adding gsl_set_complex and a test for it.
[Math-GSL.git] / Matrix.i
blob21907cd35092e9ad1ca017ccb3d5b180633ae3da
1 %module Matrix
2 %{
3 #include "/usr/local/include/gsl/gsl_matrix.h"
4 #include "/usr/local/include/gsl/gsl_matrix_double.h"
5 #include "/usr/local/include/gsl/gsl_matrix_int.h"
6 #include "/usr/local/include/gsl/gsl_matrix_complex_double.h"
7 #include "/usr/local/include/gsl/gsl_matrix_char.h"
8 %}
10 %include "/usr/local/include/gsl/gsl_matrix.h"
11 %include "/usr/local/include/gsl/gsl_matrix_double.h"
12 %include "/usr/local/include/gsl/gsl_matrix_int.h"
13 %include "/usr/local/include/gsl/gsl_matrix_complex_double.h"
14 %include "/usr/local/include/gsl/gsl_matrix_char.h"
16 FILE *fopen(char *, char *);
17 int fclose(FILE *);
19 %perlcode %{
21 @EXPORT_OK = qw/fopen fclose
22 gsl_matrix_alloc gsl_matrix_calloc gsl_matrix_alloc_from_block
23 gsl_matrix_alloc_from_matrix gsl_vector_alloc_row_from_matrix
24 gsl_vector_alloc_col_from_matrix gsl_matrix_free gsl_matrix_submatrix
25 gsl_matrix_row gsl_matrix_column gsl_matrix_diagonal
26 gsl_matrix_subdiagonal gsl_matrix_superdiagonal gsl_matrix_subrow
27 gsl_matrix_subcolumn gsl_matrix_view_array
28 gsl_matrix_view_array_with_tda gsl_matrix_view_vector
29 gsl_matrix_view_vector_with_tda gsl_matrix_const_submatrix
30 gsl_matrix_const_row gsl_matrix_const_column gsl_matrix_const_diagonal
31 gsl_matrix_const_subdiagonal gsl_matrix_const_superdiagonal
32 gsl_matrix_const_subrow gsl_matrix_const_subcolumn
33 gsl_matrix_const_view_array gsl_matrix_const_view_array_with_tda
34 gsl_matrix_const_view_vector gsl_matrix_const_view_vector_with_tda
35 gsl_matrix_get gsl_matrix_set gsl_matrix_ptr gsl_matrix_const_ptr
36 gsl_matrix_set_zero gsl_matrix_set_identity gsl_matrix_set_all
37 gsl_matrix_fread gsl_matrix_fwrite gsl_matrix_fscanf gsl_matrix_fprintf
38 gsl_matrix_memcpy gsl_matrix_swap gsl_matrix_swap_rows
39 gsl_matrix_swap_columns gsl_matrix_swap_rowcol gsl_matrix_transpose
40 gsl_matrix_transpose_memcpy gsl_matrix_max gsl_matrix_min
41 gsl_matrix_minmax gsl_matrix_max_index gsl_matrix_min_index
42 gsl_matrix_minmax_index gsl_matrix_isnull gsl_matrix_ispos
43 gsl_matrix_isneg gsl_matrix_isnonneg gsl_matrix_add gsl_matrix_sub
44 gsl_matrix_mul_elements gsl_matrix_div_elements gsl_matrix_scale
45 gsl_matrix_add_constant gsl_matrix_add_diagonal
46 gsl_matrix_char_alloc gsl_matrix_char_calloc gsl_matrix_char_alloc_from_block
47 gsl_matrix_char_alloc_from_matrix gsl_vector_char_alloc_row_from_matrix gsl_vector_char_alloc_col_from_matrix
48 gsl_matrix_char_free gsl_matrix_char_submatrix
49 gsl_matrix_char_row gsl_matrix_char_column
50 gsl_matrix_char_diagonal gsl_matrix_char_subdiagonal gsl_matrix_char_superdiagonal
51 gsl_matrix_char_subrow gsl_matrix_char_subcolumn gsl_matrix_char_view_array
52 gsl_matrix_char_view_array_with_tda gsl_matrix_char_view_vector gsl_matrix_char_view_vector_with_tda
53 gsl_matrix_char_const_submatrix gsl_matrix_char_const_row gsl_matrix_char_const_column
54 gsl_matrix_char_const_diagonal gsl_matrix_char_const_subdiagonal gsl_matrix_char_const_superdiagonal
55 gsl_matrix_char_const_subrow gsl_matrix_char_const_subcolumn gsl_matrix_char_const_view_array
56 gsl_matrix_char_const_view_array_with_tda gsl_matrix_char_const_view_vector gsl_matrix_char_const_view_vector_with_tda
57 gsl_matrix_char_get gsl_matrix_char_set gsl_matrix_char_ptr gsl_matrix_char_const_ptr
58 gsl_matrix_char_set_zero gsl_matrix_char_set_identity
59 gsl_matrix_char_set_all gsl_matrix_char_fread
60 gsl_matrix_char_fwrite gsl_matrix_char_fscanf gsl_matrix_char_fprintf
61 gsl_matrix_char_memcpy gsl_matrix_char_swap
62 gsl_matrix_char_swap_rows gsl_matrix_char_swap_columns
63 gsl_matrix_char_swap_rowcol gsl_matrix_char_transpose gsl_matrix_char_transpose_memcpy
64 gsl_matrix_char_max gsl_matrix_char_min
65 gsl_matrix_char_minmax gsl_matrix_char_max_index
66 gsl_matrix_char_min_index gsl_matrix_char_minmax_index
67 gsl_matrix_char_isnull gsl_matrix_char_ispos gsl_matrix_char_isneg
68 gsl_matrix_char_isnonneg gsl_matrix_char_add
69 gsl_matrix_char_sub gsl_matrix_char_mul_elements gsl_matrix_char_div_elements
70 gsl_matrix_char_scale gsl_matrix_char_add_constant gsl_matrix_char_add_diagonal
71 gsl_matrix_int_alloc gsl_matrix_int_calloc gsl_matrix_int_alloc_from_block
72 gsl_matrix_int_alloc_from_matrix gsl_vector_int_alloc_row_from_matrix gsl_vector_int_alloc_col_from_matrix
73 gsl_matrix_int_free gsl_matrix_int_submatrix gsl_matrix_int_row
74 gsl_matrix_int_column gsl_matrix_int_diagonal gsl_matrix_int_subdiagonal
75 gsl_matrix_int_superdiagonal gsl_matrix_int_subrow gsl_matrix_int_subcolumn gsl_matrix_int_view_array
76 gsl_matrix_int_view_array_with_tda gsl_matrix_int_view_vector gsl_matrix_int_view_vector_with_tda
77 gsl_matrix_int_const_submatrix gsl_matrix_int_const_row gsl_matrix_int_const_column
78 gsl_matrix_int_const_diagonal gsl_matrix_int_const_subdiagonal gsl_matrix_int_const_superdiagonal
79 gsl_matrix_int_const_subrow gsl_matrix_int_const_subcolumn gsl_matrix_int_const_view_array
80 gsl_matrix_int_const_view_array_with_tda gsl_matrix_int_const_view_vector gsl_matrix_int_const_view_vector_with_tda
81 gsl_matrix_int_get gsl_matrix_int_set
82 gsl_matrix_int_ptr gsl_matrix_int_const_ptr
83 gsl_matrix_int_set_zero gsl_matrix_int_set_identity gsl_matrix_int_set_all
84 gsl_matrix_int_fread gsl_matrix_int_fwrite
85 gsl_matrix_int_fscanf gsl_matrix_int_fprintf
86 gsl_matrix_int_memcpy gsl_matrix_int_swap
87 gsl_matrix_int_swap_rows gsl_matrix_int_swap_columns gsl_matrix_int_swap_rowcol
88 gsl_matrix_int_transpose gsl_matrix_int_transpose_memcpy
89 gsl_matrix_int_max gsl_matrix_int_min gsl_matrix_int_minmax
90 gsl_matrix_int_max_index gsl_matrix_int_min_index
91 gsl_matrix_int_minmax_index gsl_matrix_int_isnull
92 gsl_matrix_int_ispos gsl_matrix_int_isneg gsl_matrix_int_isnonneg
93 gsl_matrix_int_add gsl_matrix_int_sub
94 gsl_matrix_int_mul_elements gsl_matrix_int_div_elements gsl_matrix_int_scale
95 gsl_matrix_int_add_constant gsl_matrix_int_add_diagonal
97 %EXPORT_TAGS = ( all => [ @EXPORT_OK ], char => [gsl_matrix_char_alloc, gsl_matrix_char_calloc, gsl_matrix_char_alloc_from_block, gsl_matrix_char_alloc_from_matrix, gsl_vector_char_alloc_row_from_matrix, gsl_vector_char_alloc_col_from_matrix, gsl_matrix_char_free, gsl_matrix_char_submatrix, gsl_matrix_char_row, gsl_matrix_char_column, gsl_matrix_char_diagonal, gsl_matrix_char_subdiagonal, gsl_matrix_char_superdiagonal, gsl_matrix_char_subrow, gsl_matrix_char_subcolumn, gsl_matrix_char_view_array, gsl_matrix_char_view_array_with_tda, gsl_matrix_char_view_vector, gsl_matrix_char_view_vector_with_tda, gsl_matrix_char_const_submatrix, gsl_matrix_char_const_row, gsl_matrix_char_const_column, gsl_matrix_char_const_diagonal, gsl_matrix_char_const_subdiagonal, gsl_matrix_char_const_superdiagonal, gsl_matrix_char_const_subrow, gsl_matrix_char_const_subcolumn, gsl_matrix_char_const_view_array, gsl_matrix_char_const_view_array_with_tda, gsl_matrix_char_const_view_vector, gsl_matrix_char_const_view_vector_with_tda, gsl_matrix_char_get, gsl_matrix_char_set, gsl_matrix_char_ptr, gsl_matrix_char_const_ptr, gsl_matrix_char_set_zero, gsl_matrix_char_set_identity, gsl_matrix_char_set_all, gsl_matrix_char_fread, gsl_matrix_char_fwrite, gsl_matrix_char_fscanf, gsl_matrix_char_fprintf, gsl_matrix_char_memcpy, gsl_matrix_char_swap, gsl_matrix_char_swap_rows, gsl_matrix_char_swap_columns, gsl_matrix_char_swap_rowcol, gsl_matrix_char_transpose, gsl_matrix_char_transpose_memcpy, gsl_matrix_char_max, gsl_matrix_char_min, gsl_matrix_char_minmax, gsl_matrix_char_max_index, gsl_matrix_char_min_index, gsl_matrix_char_minmax_index, gsl_matrix_char_isnull, gsl_matrix_char_ispos, gsl_matrix_char_isneg, gsl_matrix_char_isnonneg, gsl_matrix_char_add, gsl_matrix_char_sub, gsl_matrix_char_mul_elements, gsl_matrix_char_div_elements, gsl_matrix_char_scale, gsl_matrix_char_add_constant, gsl_matrix_char_add_diagonal], double => [ gsl_matrix_alloc, gsl_matrix_calloc, gsl_matrix_alloc_from_block, gsl_matrix_alloc_from_matrix, gsl_vector_alloc_row_from_matrix, gsl_vector_alloc_col_from_matrix, gsl_matrix_free, gsl_matrix_submatrix, gsl_matrix_row, gsl_matrix_column, gsl_matrix_diagonal, gsl_matrix_subdiagonal, gsl_matrix_superdiagonal, gsl_matrix_subrow, gsl_matrix_subcolumn, gsl_matrix_view_array, gsl_matrix_view_array_with_tda, gsl_matrix_view_vector, gsl_matrix_view_vector_with_tda, gsl_matrix_const_submatrix, gsl_matrix_const_row, gsl_matrix_const_column, gsl_matrix_const_diagonal, gsl_matrix_const_subdiagonal, gsl_matrix_const_superdiagonal, gsl_matrix_const_subrow, gsl_matrix_const_subcolumn, gsl_matrix_const_view_array, gsl_matrix_const_view_array_with_tda, gsl_matrix_const_view_vector, gsl_matrix_const_view_vector_with_tda, gsl_matrix_get, gsl_matrix_set, gsl_matrix_ptr, gsl_matrix_const_ptr, gsl_matrix_set_zero, gsl_matrix_set_identity, gsl_matrix_set_all, gsl_matrix_fread, gsl_matrix_fwrite, gsl_matrix_fscanf, gsl_matrix_fprintf, gsl_matrix_memcpy, gsl_matrix_swap, gsl_matrix_swap_rows, gsl_matrix_swap_columns, gsl_matrix_swap_rowcol, gsl_matrix_transpose, gsl_matrix_transpose_memcpy, gsl_matrix_max, gsl_matrix_minmax, gsl_matrix_max_index, gsl_matrix_min_index, gsl_matrix_minmax_index, gsl_matrix_isnull, gsl_matrix_ispos, gsl_matrix_isneg, gsl_matrix_isnonneg, gsl_matrix_add, gsl_matrix_mul_elements, gsl_matrix_div_elements, gsl_matrix_scale, gsl_matrix_add_constant, gsl_matrix_add_diagonal], int => [gsl_matrix_int_alloc, gsl_matrix_int_alloc_from_matrix, gsl_matrix_int_free, gsl_matrix_int_column, gsl_matrix_int_superdiagonal, gsl_matrix_int_view_array_with_tda, gsl_matrix_int_const_submatrix, gsl_matrix_int_const_diagonal, gsl_matrix_int_const_subrow, gsl_matrix_int_const_view_array_with_tda, gsl_matrix_int_get, gsl_matrix_int_ptr, gsl_matrix_int_set_zero, gsl_matrix_int_fread, gsl_matrix_int_fscanf, gsl_matrix_int_memcpy, gsl_matrix_int_swap_rows, gsl_matrix_int_transpose, gsl_matrix_int_max, gsl_matrix_int_max_index, gsl_matrix_int_minmax_index, gsl_matrix_int_ispos, gsl_matrix_int_add, gsl_matrix_int_mul_elements, gsl_matrix_int_add_constant]);
99 __END__
101 =head1 NAME
103 Math::GSL::Matrix
104 Mathematical functions concerning Matrices
106 =head1 SYPNOPSIS
108 use Math::GSL::Matrix qw/:all/;
110 =head1 DESCRIPTION
112 Here is a list of all the functions included in this module :
114 gsl_matrix_alloc gsl_matrix_calloc gsl_matrix_alloc_from_block
115 gsl_matrix_alloc_from_matrix gsl_vector_alloc_row_from_matrix
116 gsl_vector_alloc_col_from_matrix gsl_matrix_free gsl_matrix_submatrix
117 gsl_matrix_row gsl_matrix_column gsl_matrix_diagonal
118 gsl_matrix_subdiagonal gsl_matrix_superdiagonal gsl_matrix_subrow
119 gsl_matrix_subcolumn gsl_matrix_view_array
120 gsl_matrix_view_array_with_tda gsl_matrix_view_vector
121 gsl_matrix_view_vector_with_tda gsl_matrix_const_submatrix
122 gsl_matrix_const_row gsl_matrix_const_column gsl_matrix_const_diagonal
123 gsl_matrix_const_subdiagonal gsl_matrix_const_superdiagonal
124 gsl_matrix_const_subrow gsl_matrix_const_subcolumn
125 gsl_matrix_const_view_array gsl_matrix_const_view_array_with_tda
126 gsl_matrix_const_view_vector gsl_matrix_const_view_vector_with_tda
127 gsl_matrix_get gsl_matrix_set gsl_matrix_ptr gsl_matrix_const_ptr
128 gsl_matrix_set_zero gsl_matrix_set_identity gsl_matrix_set_all
129 gsl_matrix_fread gsl_matrix_fwrite gsl_matrix_fscanf gsl_matrix_fprintf
130 gsl_matrix_memcpy gsl_matrix_swap gsl_matrix_swap_rows
131 gsl_matrix_swap_columns gsl_matrix_swap_rowcol gsl_matrix_transpose
132 gsl_matrix_transpose_memcpy gsl_matrix_max gsl_matrix_min
133 gsl_matrix_minmax gsl_matrix_max_index gsl_matrix_min_index
134 gsl_matrix_minmax_index gsl_matrix_isnull gsl_matrix_ispos
135 gsl_matrix_isneg gsl_matrix_isnonneg gsl_matrix_add gsl_matrix_sub
136 gsl_matrix_mul_elements gsl_matrix_div_elements gsl_matrix_scale
137 gsl_matrix_add_constant gsl_matrix_add_diagonal
138 gsl_matrix_char_alloc gsl_matrix_char_calloc gsl_matrix_char_alloc_from_block
139 gsl_matrix_char_alloc_from_matrix gsl_vector_char_alloc_row_from_matrix gsl_vector_char_alloc_col_from_matrix
140 gsl_matrix_char_free gsl_matrix_char_submatrix
141 gsl_matrix_char_row gsl_matrix_char_column
142 gsl_matrix_char_diagonal gsl_matrix_char_subdiagonal gsl_matrix_char_superdiagonal
143 gsl_matrix_char_subrow gsl_matrix_char_subcolumn gsl_matrix_char_view_array
144 gsl_matrix_char_view_array_with_tda gsl_matrix_char_view_vector gsl_matrix_char_view_vector_with_tda
145 gsl_matrix_char_const_submatrix gsl_matrix_char_const_row gsl_matrix_char_const_column
146 gsl_matrix_char_const_diagonal gsl_matrix_char_const_subdiagonal gsl_matrix_char_const_superdiagonal
147 gsl_matrix_char_const_subrow gsl_matrix_char_const_subcolumn gsl_matrix_char_const_view_array
148 gsl_matrix_char_const_view_array_with_tda gsl_matrix_char_const_view_vector gsl_matrix_char_const_view_vector_with_tda
149 gsl_matrix_char_get gsl_matrix_char_set gsl_matrix_char_ptr gsl_matrix_char_const_ptr
150 gsl_matrix_char_set_zero gsl_matrix_char_set_identity
151 gsl_matrix_char_set_all gsl_matrix_char_fread
152 gsl_matrix_char_fwrite gsl_matrix_char_fscanf gsl_matrix_char_fprintf
153 gsl_matrix_char_memcpy gsl_matrix_char_swap
154 gsl_matrix_char_swap_rows gsl_matrix_char_swap_columns
155 gsl_matrix_char_swap_rowcol gsl_matrix_char_transpose gsl_matrix_char_transpose_memcpy
156 gsl_matrix_char_max gsl_matrix_char_min
157 gsl_matrix_char_minmax gsl_matrix_char_max_index
158 gsl_matrix_char_min_index gsl_matrix_char_minmax_index
159 gsl_matrix_char_isnull gsl_matrix_char_ispos gsl_matrix_char_isneg
160 gsl_matrix_char_isnonneg gsl_matrix_char_add
161 gsl_matrix_char_sub gsl_matrix_char_mul_elements gsl_matrix_char_div_elements
162 gsl_matrix_char_scale gsl_matrix_char_add_constant gsl_matrix_char_add_diagonal
163 gsl_matrix_int_alloc gsl_matrix_int_calloc gsl_matrix_int_alloc_from_block
164 gsl_matrix_int_alloc_from_matrix gsl_vector_int_alloc_row_from_matrix gsl_vector_int_alloc_col_from_matrix
165 gsl_matrix_int_free gsl_matrix_int_submatrix gsl_matrix_int_row
166 gsl_matrix_int_column gsl_matrix_int_diagonal gsl_matrix_int_subdiagonal
167 gsl_matrix_int_superdiagonal gsl_matrix_int_subrow gsl_matrix_int_subcolumn gsl_matrix_int_view_array
168 gsl_matrix_int_view_array_with_tda gsl_matrix_int_view_vector gsl_matrix_int_view_vector_with_tda
169 gsl_matrix_int_const_submatrix gsl_matrix_int_const_row gsl_matrix_int_const_column
170 gsl_matrix_int_const_diagonal gsl_matrix_int_const_subdiagonal gsl_matrix_int_const_superdiagonal
171 gsl_matrix_int_const_subrow gsl_matrix_int_const_subcolumn gsl_matrix_int_const_view_array
172 gsl_matrix_int_const_view_array_with_tda gsl_matrix_int_const_view_vector gsl_matrix_int_const_view_vector_with_tda
173 gsl_matrix_int_get gsl_matrix_int_set
174 gsl_matrix_int_ptr gsl_matrix_int_const_ptr
175 gsl_matrix_int_set_zero gsl_matrix_int_set_identity gsl_matrix_int_set_all
176 gsl_matrix_int_fread gsl_matrix_int_fwrite
177 gsl_matrix_int_fscanf gsl_matrix_int_fprintf
178 gsl_matrix_int_memcpy gsl_matrix_int_swap
179 gsl_matrix_int_swap_rows gsl_matrix_int_swap_columns gsl_matrix_int_swap_rowcol
180 gsl_matrix_int_transpose gsl_matrix_int_transpose_memcpy
181 gsl_matrix_int_max gsl_matrix_int_min gsl_matrix_int_minmax
182 gsl_matrix_int_max_index gsl_matrix_int_min_index
183 gsl_matrix_int_minmax_index gsl_matrix_int_isnull
184 gsl_matrix_int_ispos gsl_matrix_int_isneg gsl_matrix_int_isnonneg
185 gsl_matrix_int_add gsl_matrix_int_sub
186 gsl_matrix_int_mul_elements gsl_matrix_int_div_elements gsl_matrix_int_scale
187 gsl_matrix_int_add_constant gsl_matrix_int_add_diagonal
189 You have to add the functions you want to use inside the qw /put_funtion_here /. You can also write use Math::GSL::PowInt qw/:name_of_tag/ to use all avaible functions of the module. Other tags are also avaible, here is a complete list of all tags for this module :
193 double
194 char
196 For more informations on the functions, we refer you to the GSL offcial documentation: http://www.gnu.org/software/gsl/manual/html_node/
197 Tip : search on google: site:http://www.gnu.org/software/gsl/manual/html_node/name_of_the_function_you_want
199 =head1 EXAMPLES
201 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
204 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.
206 use Math::GSL::Matrix qw/:all/;
207 $m = gsl_matrix_alloc (10,3);
208 for($i = 0; $i< 10; $i++){
209 for($j = 0; $j<3; $j++){
210 gsl_matrix_set($m, $i, $j, 0.23 + 100*$i + $j);
213 for($i = 0; $i< 100; $i++){ # OUT OF RANGE ERROR
214 for($j=0; $j<3; $j++){
215 print "m($i, $j) = " . gsl_matrix_get ($m, $i, $j) . "\n";
218 gsl_matrix_free ($m);
221 use Math::GSL::Matrix qw/:all/;
223 $m = gsl_matrix_alloc (100, 100);
224 $a = gsl_matrix_alloc (100, 100);
226 for($i = 0; $i < 100; $i++){
227 for($j = 0; $j < 100; $j++){
228 gsl_matrix_set ($m, $i, $j, 0.23 + $i + $j);
232 The next program shows how to write a matrix to a file.
234 $out = fopen("test.dat", "wb");
235 gsl_matrix_fwrite ($out, $m);
236 fclose ($out);
238 $in = fopen("test.dat", "rb");
239 gsl_matrix_fread ($in, $a);
240 fclose($in);
242 $k=0;
243 for($i = 0; $i < 100; $i++){
244 for($j = 0; $j < 100; $j++){
245 $mij = gsl_matrix_get ($m, $i, $j);
246 $aij = gsl_matrix_get ($a, $i, $j);
247 if ($mij != $aij){ $k++ };
251 gsl_matrix_free($m);
252 gsl_matrix_free($a);
254 print "differences = $k (should be zero)\n";
256 =head1 AUTHOR
258 Jonathan Leto <jaleto@gmail.com> and Thierry Moisan <thierry.moisan@gmail.com>
260 =head1 COPYRIGHT AND LICENSE
262 Copyright (C) 2008 Jonathan Leto and Thierry Moisan
264 This program is free software; you can redistribute it and/or modify it
265 under the same terms as Perl itself.
267 =cut