Adding fopen and flcose functions. Adding an example in the
[Math-GSL.git] / Matrix.i
blob8537b453043efe50e19856900b8c4f199eeaabc1
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 / put_functions_here/;
110 =head1 DESCRIPTION
111 Here is a list of all the functions included in this module :
113 gsl_matrix_alloc gsl_matrix_calloc gsl_matrix_alloc_from_block
114 gsl_matrix_alloc_from_matrix gsl_vector_alloc_row_from_matrix
115 gsl_vector_alloc_col_from_matrix gsl_matrix_free gsl_matrix_submatrix
116 gsl_matrix_row gsl_matrix_column gsl_matrix_diagonal
117 gsl_matrix_subdiagonal gsl_matrix_superdiagonal gsl_matrix_subrow
118 gsl_matrix_subcolumn gsl_matrix_view_array
119 gsl_matrix_view_array_with_tda gsl_matrix_view_vector
120 gsl_matrix_view_vector_with_tda gsl_matrix_const_submatrix
121 gsl_matrix_const_row gsl_matrix_const_column gsl_matrix_const_diagonal
122 gsl_matrix_const_subdiagonal gsl_matrix_const_superdiagonal
123 gsl_matrix_const_subrow gsl_matrix_const_subcolumn
124 gsl_matrix_const_view_array gsl_matrix_const_view_array_with_tda
125 gsl_matrix_const_view_vector gsl_matrix_const_view_vector_with_tda
126 gsl_matrix_get gsl_matrix_set gsl_matrix_ptr gsl_matrix_const_ptr
127 gsl_matrix_set_zero gsl_matrix_set_identity gsl_matrix_set_all
128 gsl_matrix_fread gsl_matrix_fwrite gsl_matrix_fscanf gsl_matrix_fprintf
129 gsl_matrix_memcpy gsl_matrix_swap gsl_matrix_swap_rows
130 gsl_matrix_swap_columns gsl_matrix_swap_rowcol gsl_matrix_transpose
131 gsl_matrix_transpose_memcpy gsl_matrix_max gsl_matrix_min
132 gsl_matrix_minmax gsl_matrix_max_index gsl_matrix_min_index
133 gsl_matrix_minmax_index gsl_matrix_isnull gsl_matrix_ispos
134 gsl_matrix_isneg gsl_matrix_isnonneg gsl_matrix_add gsl_matrix_sub
135 gsl_matrix_mul_elements gsl_matrix_div_elements gsl_matrix_scale
136 gsl_matrix_add_constant gsl_matrix_add_diagonal
137 gsl_matrix_char_alloc gsl_matrix_char_calloc gsl_matrix_char_alloc_from_block
138 gsl_matrix_char_alloc_from_matrix gsl_vector_char_alloc_row_from_matrix gsl_vector_char_alloc_col_from_matrix
139 gsl_matrix_char_free gsl_matrix_char_submatrix
140 gsl_matrix_char_row gsl_matrix_char_column
141 gsl_matrix_char_diagonal gsl_matrix_char_subdiagonal gsl_matrix_char_superdiagonal
142 gsl_matrix_char_subrow gsl_matrix_char_subcolumn gsl_matrix_char_view_array
143 gsl_matrix_char_view_array_with_tda gsl_matrix_char_view_vector gsl_matrix_char_view_vector_with_tda
144 gsl_matrix_char_const_submatrix gsl_matrix_char_const_row gsl_matrix_char_const_column
145 gsl_matrix_char_const_diagonal gsl_matrix_char_const_subdiagonal gsl_matrix_char_const_superdiagonal
146 gsl_matrix_char_const_subrow gsl_matrix_char_const_subcolumn gsl_matrix_char_const_view_array
147 gsl_matrix_char_const_view_array_with_tda gsl_matrix_char_const_view_vector gsl_matrix_char_const_view_vector_with_tda
148 gsl_matrix_char_get gsl_matrix_char_set gsl_matrix_char_ptr gsl_matrix_char_const_ptr
149 gsl_matrix_char_set_zero gsl_matrix_char_set_identity
150 gsl_matrix_char_set_all gsl_matrix_char_fread
151 gsl_matrix_char_fwrite gsl_matrix_char_fscanf gsl_matrix_char_fprintf
152 gsl_matrix_char_memcpy gsl_matrix_char_swap
153 gsl_matrix_char_swap_rows gsl_matrix_char_swap_columns
154 gsl_matrix_char_swap_rowcol gsl_matrix_char_transpose gsl_matrix_char_transpose_memcpy
155 gsl_matrix_char_max gsl_matrix_char_min
156 gsl_matrix_char_minmax gsl_matrix_char_max_index
157 gsl_matrix_char_min_index gsl_matrix_char_minmax_index
158 gsl_matrix_char_isnull gsl_matrix_char_ispos gsl_matrix_char_isneg
159 gsl_matrix_char_isnonneg gsl_matrix_char_add
160 gsl_matrix_char_sub gsl_matrix_char_mul_elements gsl_matrix_char_div_elements
161 gsl_matrix_char_scale gsl_matrix_char_add_constant gsl_matrix_char_add_diagonal
162 gsl_matrix_int_alloc gsl_matrix_int_calloc gsl_matrix_int_alloc_from_block
163 gsl_matrix_int_alloc_from_matrix gsl_vector_int_alloc_row_from_matrix gsl_vector_int_alloc_col_from_matrix
164 gsl_matrix_int_free gsl_matrix_int_submatrix gsl_matrix_int_row
165 gsl_matrix_int_column gsl_matrix_int_diagonal gsl_matrix_int_subdiagonal
166 gsl_matrix_int_superdiagonal gsl_matrix_int_subrow gsl_matrix_int_subcolumn gsl_matrix_int_view_array
167 gsl_matrix_int_view_array_with_tda gsl_matrix_int_view_vector gsl_matrix_int_view_vector_with_tda
168 gsl_matrix_int_const_submatrix gsl_matrix_int_const_row gsl_matrix_int_const_column
169 gsl_matrix_int_const_diagonal gsl_matrix_int_const_subdiagonal gsl_matrix_int_const_superdiagonal
170 gsl_matrix_int_const_subrow gsl_matrix_int_const_subcolumn gsl_matrix_int_const_view_array
171 gsl_matrix_int_const_view_array_with_tda gsl_matrix_int_const_view_vector gsl_matrix_int_const_view_vector_with_tda
172 gsl_matrix_int_get gsl_matrix_int_set
173 gsl_matrix_int_ptr gsl_matrix_int_const_ptr
174 gsl_matrix_int_set_zero gsl_matrix_int_set_identity gsl_matrix_int_set_all
175 gsl_matrix_int_fread gsl_matrix_int_fwrite
176 gsl_matrix_int_fscanf gsl_matrix_int_fprintf
177 gsl_matrix_int_memcpy gsl_matrix_int_swap
178 gsl_matrix_int_swap_rows gsl_matrix_int_swap_columns gsl_matrix_int_swap_rowcol
179 gsl_matrix_int_transpose gsl_matrix_int_transpose_memcpy
180 gsl_matrix_int_max gsl_matrix_int_min gsl_matrix_int_minmax
181 gsl_matrix_int_max_index gsl_matrix_int_min_index
182 gsl_matrix_int_minmax_index gsl_matrix_int_isnull
183 gsl_matrix_int_ispos gsl_matrix_int_isneg gsl_matrix_int_isnonneg
184 gsl_matrix_int_add gsl_matrix_int_sub
185 gsl_matrix_int_mul_elements gsl_matrix_int_div_elements gsl_matrix_int_scale
186 gsl_matrix_int_add_constant gsl_matrix_int_add_diagonal
188 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 :
192 double
193 char
195 For more informations on the functions, we refer you to the GSL offcial documentation: http://www.gnu.org/software/gsl/manual/html_node/
196 Tip : search on google: site:http://www.gnu.org/software/gsl/manual/html_node/ name_of_the_function_you_want
198 =head1 EXAMPLES
200 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
203 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.
205 use Math::GSL::Matrix qw/:all/;
206 $m = gsl_matrix_alloc (10,3);
207 for($i = 0; $i< 10; $i++){
208 for($j = 0; $j<3; $j++){
209 gsl_matrix_set($m, $i, $j, 0.23 + 100*$i + $j);
212 for($i = 0; $i< 100; $i++){ # OUT OF RANGE ERROR
213 for($j=0; $j<3; $j++){
214 print "m($i, $j) = " . gsl_matrix_get ($m, $i, $j) . "\n";;
217 gsl_matrix_free ($m);
220 use Math::GSL::Matrix qw/:all/;
221 $m = gsl_matrix_alloc (100, 100);
222 $a = gsl_matrix_alloc (100, 100);
224 for($i = 0; $i < 100; $i++){
225 for($j = 0; $j < 100; $j++){
226 gsl_matrix_set ($m, $i, $j, 0.23 + $i + $j);
230 The next program shows how to write a matrix to a file.
232 $out = fopen("test.dat", "wb");
233 gsl_matrix_fwrite ($out, $m);
234 fclose ($out);
236 $in = fopen("test.dat", "rb");
237 gsl_matrix_fread ($in, $a);
238 fclose($in);
240 $k=0;
241 for($i = 0; $i < 100; $i++){
242 for($j = 0; $j < 100; $j++){
243 $mij = gsl_matrix_get ($m, $i, $j);
244 $aij = gsl_matrix_get ($a, $i, $j);
245 if ($mij != $aij){ $k++ };
249 gsl_matrix_free($m);
250 gsl_matrix_free($a);
252 print "differences = $k (should be zero)\n";
254 =head1 AUTHOR
256 Jonathan Leto <jaleto@gmail.com> and Thierry Moisan <thierry.moisan@gmail.com>
258 =head1 COPYRIGHT AND LICENSE
260 Copyright (C) 2008 Jonathan Leto and Thierry Moisan
262 This program is free software; you can redistribute it and/or modify it
263 under the same terms as Perl itself.
265 =cut