File: SparseMatrix.pm.2.2.1

package info (click to toggle)
libmath-gsl-perl 0.45-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 192,156 kB
  • sloc: ansic: 895,524; perl: 24,682; makefile: 12
file content (319 lines) | stat: -rw-r--r-- 11,788 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
# This file was automatically generated by SWIG (https://www.swig.org).
# Version 4.2.0
#
# Do not make changes to this file unless you know what you are doing - modify
# the SWIG interface file instead.

package Math::GSL::SparseMatrix;
use base qw(Exporter);
use base qw(DynaLoader);
package Math::GSL::SparseMatrixc;
bootstrap Math::GSL::SparseMatrix;
package Math::GSL::SparseMatrix;
@EXPORT = qw();

# ---------- BASE METHODS -------------

package Math::GSL::SparseMatrix;

sub TIEHASH {
    my ($classname,$obj) = @_;
    return bless $obj, $classname;
}

sub CLEAR { }

sub FIRSTKEY { }

sub NEXTKEY { }

sub FETCH {
    my ($self,$field) = @_;
    my $member_func = "swig_${field}_get";
    $self->$member_func();
}

sub STORE {
    my ($self,$field,$newval) = @_;
    my $member_func = "swig_${field}_set";
    $self->$member_func($newval);
}

sub this {
    my $ptr = shift;
    return tied(%$ptr);
}


# ------- FUNCTION WRAPPERS --------

package Math::GSL::SparseMatrix;

*gsl_error = *Math::GSL::SparseMatrixc::gsl_error;
*gsl_stream_printf = *Math::GSL::SparseMatrixc::gsl_stream_printf;
*gsl_strerror = *Math::GSL::SparseMatrixc::gsl_strerror;
*gsl_set_error_handler = *Math::GSL::SparseMatrixc::gsl_set_error_handler;
*gsl_set_error_handler_off = *Math::GSL::SparseMatrixc::gsl_set_error_handler_off;
*gsl_set_stream_handler = *Math::GSL::SparseMatrixc::gsl_set_stream_handler;
*gsl_set_stream = *Math::GSL::SparseMatrixc::gsl_set_stream;
*gsl_spmatrix_alloc = *Math::GSL::SparseMatrixc::gsl_spmatrix_alloc;
*gsl_spmatrix_alloc_nzmax = *Math::GSL::SparseMatrixc::gsl_spmatrix_alloc_nzmax;
*gsl_spmatrix_free = *Math::GSL::SparseMatrixc::gsl_spmatrix_free;
*gsl_spmatrix_realloc = *Math::GSL::SparseMatrixc::gsl_spmatrix_realloc;
*gsl_spmatrix_set_zero = *Math::GSL::SparseMatrixc::gsl_spmatrix_set_zero;
*gsl_spmatrix_nnz = *Math::GSL::SparseMatrixc::gsl_spmatrix_nnz;
*gsl_spmatrix_compare_idx = *Math::GSL::SparseMatrixc::gsl_spmatrix_compare_idx;
*gsl_spmatrix_tree_rebuild = *Math::GSL::SparseMatrixc::gsl_spmatrix_tree_rebuild;
*gsl_spmatrix_memcpy = *Math::GSL::SparseMatrixc::gsl_spmatrix_memcpy;
*gsl_spmatrix_get = *Math::GSL::SparseMatrixc::gsl_spmatrix_get;
*gsl_spmatrix_set = *Math::GSL::SparseMatrixc::gsl_spmatrix_set;
*gsl_spmatrix_ptr = *Math::GSL::SparseMatrixc::gsl_spmatrix_ptr;
*gsl_spmatrix_compcol = *Math::GSL::SparseMatrixc::gsl_spmatrix_compcol;
*gsl_spmatrix_ccs = *Math::GSL::SparseMatrixc::gsl_spmatrix_ccs;
*gsl_spmatrix_crs = *Math::GSL::SparseMatrixc::gsl_spmatrix_crs;
*gsl_spmatrix_cumsum = *Math::GSL::SparseMatrixc::gsl_spmatrix_cumsum;
*gsl_spmatrix_fprintf = *Math::GSL::SparseMatrixc::gsl_spmatrix_fprintf;
*gsl_spmatrix_fscanf = *Math::GSL::SparseMatrixc::gsl_spmatrix_fscanf;
*gsl_spmatrix_fwrite = *Math::GSL::SparseMatrixc::gsl_spmatrix_fwrite;
*gsl_spmatrix_fread = *Math::GSL::SparseMatrixc::gsl_spmatrix_fread;
*gsl_spmatrix_scale = *Math::GSL::SparseMatrixc::gsl_spmatrix_scale;
*gsl_spmatrix_minmax = *Math::GSL::SparseMatrixc::gsl_spmatrix_minmax;
*gsl_spmatrix_add = *Math::GSL::SparseMatrixc::gsl_spmatrix_add;
*gsl_spmatrix_d2sp = *Math::GSL::SparseMatrixc::gsl_spmatrix_d2sp;
*gsl_spmatrix_sp2d = *Math::GSL::SparseMatrixc::gsl_spmatrix_sp2d;
*gsl_spmatrix_equal = *Math::GSL::SparseMatrixc::gsl_spmatrix_equal;
*gsl_spmatrix_transpose = *Math::GSL::SparseMatrixc::gsl_spmatrix_transpose;
*gsl_spmatrix_transpose2 = *Math::GSL::SparseMatrixc::gsl_spmatrix_transpose2;
*gsl_spmatrix_transpose_memcpy = *Math::GSL::SparseMatrixc::gsl_spmatrix_transpose_memcpy;

############# Class : Math::GSL::SparseMatrix::gsl_spmatrix_tree ##############

package Math::GSL::SparseMatrix::gsl_spmatrix_tree;
use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
@ISA = qw( Math::GSL::SparseMatrix );
%OWNER = ();
%ITERATORS = ();
*swig_tree_get = *Math::GSL::SparseMatrixc::gsl_spmatrix_tree_tree_get;
*swig_tree_set = *Math::GSL::SparseMatrixc::gsl_spmatrix_tree_tree_set;
*swig_node_array_get = *Math::GSL::SparseMatrixc::gsl_spmatrix_tree_node_array_get;
*swig_node_array_set = *Math::GSL::SparseMatrixc::gsl_spmatrix_tree_node_array_set;
*swig_n_get = *Math::GSL::SparseMatrixc::gsl_spmatrix_tree_n_get;
*swig_n_set = *Math::GSL::SparseMatrixc::gsl_spmatrix_tree_n_set;
sub new {
    my $pkg = shift;
    my $self = Math::GSL::SparseMatrixc::new_gsl_spmatrix_tree(@_);
    bless $self, $pkg if defined($self);
}

sub DESTROY {
    return unless $_[0]->isa('HASH');
    my $self = tied(%{$_[0]});
    return unless defined $self;
    delete $ITERATORS{$self};
    if (exists $OWNER{$self}) {
        Math::GSL::SparseMatrixc::delete_gsl_spmatrix_tree($self);
        delete $OWNER{$self};
    }
}

sub DISOWN {
    my $self = shift;
    my $ptr = tied(%$self);
    delete $OWNER{$ptr};
}

sub ACQUIRE {
    my $self = shift;
    my $ptr = tied(%$self);
    $OWNER{$ptr} = 1;
}


############# Class : Math::GSL::SparseMatrix::gsl_spmatrix ##############

package Math::GSL::SparseMatrix::gsl_spmatrix;
use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
@ISA = qw( Math::GSL::SparseMatrix );
%OWNER = ();
%ITERATORS = ();
*swig_size1_get = *Math::GSL::SparseMatrixc::gsl_spmatrix_size1_get;
*swig_size1_set = *Math::GSL::SparseMatrixc::gsl_spmatrix_size1_set;
*swig_size2_get = *Math::GSL::SparseMatrixc::gsl_spmatrix_size2_get;
*swig_size2_set = *Math::GSL::SparseMatrixc::gsl_spmatrix_size2_set;
*swig_i_get = *Math::GSL::SparseMatrixc::gsl_spmatrix_i_get;
*swig_i_set = *Math::GSL::SparseMatrixc::gsl_spmatrix_i_set;
*swig_data_get = *Math::GSL::SparseMatrixc::gsl_spmatrix_data_get;
*swig_data_set = *Math::GSL::SparseMatrixc::gsl_spmatrix_data_set;
*swig_p_get = *Math::GSL::SparseMatrixc::gsl_spmatrix_p_get;
*swig_p_set = *Math::GSL::SparseMatrixc::gsl_spmatrix_p_set;
*swig_nzmax_get = *Math::GSL::SparseMatrixc::gsl_spmatrix_nzmax_get;
*swig_nzmax_set = *Math::GSL::SparseMatrixc::gsl_spmatrix_nzmax_set;
*swig_nz_get = *Math::GSL::SparseMatrixc::gsl_spmatrix_nz_get;
*swig_nz_set = *Math::GSL::SparseMatrixc::gsl_spmatrix_nz_set;
*swig_tree_data_get = *Math::GSL::SparseMatrixc::gsl_spmatrix_tree_data_get;
*swig_tree_data_set = *Math::GSL::SparseMatrixc::gsl_spmatrix_tree_data_set;
*swig_work_get = *Math::GSL::SparseMatrixc::gsl_spmatrix_work_get;
*swig_work_set = *Math::GSL::SparseMatrixc::gsl_spmatrix_work_set;
*swig_sptype_get = *Math::GSL::SparseMatrixc::gsl_spmatrix_sptype_get;
*swig_sptype_set = *Math::GSL::SparseMatrixc::gsl_spmatrix_sptype_set;
sub new {
    my $pkg = shift;
    my $self = Math::GSL::SparseMatrixc::new_gsl_spmatrix(@_);
    bless $self, $pkg if defined($self);
}

sub DESTROY {
    return unless $_[0]->isa('HASH');
    my $self = tied(%{$_[0]});
    return unless defined $self;
    delete $ITERATORS{$self};
    if (exists $OWNER{$self}) {
        Math::GSL::SparseMatrixc::delete_gsl_spmatrix($self);
        delete $OWNER{$self};
    }
}

sub DISOWN {
    my $self = shift;
    my $ptr = tied(%$self);
    delete $OWNER{$ptr};
}

sub ACQUIRE {
    my $self = shift;
    my $ptr = tied(%$self);
    $OWNER{$ptr} = 1;
}


# ------- VARIABLE STUBS --------

package Math::GSL::SparseMatrix;

*GSL_VERSION = *Math::GSL::SparseMatrixc::GSL_VERSION;
*GSL_MAJOR_VERSION = *Math::GSL::SparseMatrixc::GSL_MAJOR_VERSION;
*GSL_MINOR_VERSION = *Math::GSL::SparseMatrixc::GSL_MINOR_VERSION;
*GSL_POSZERO = *Math::GSL::SparseMatrixc::GSL_POSZERO;
*GSL_NEGZERO = *Math::GSL::SparseMatrixc::GSL_NEGZERO;
*GSL_SUCCESS = *Math::GSL::SparseMatrixc::GSL_SUCCESS;
*GSL_FAILURE = *Math::GSL::SparseMatrixc::GSL_FAILURE;
*GSL_CONTINUE = *Math::GSL::SparseMatrixc::GSL_CONTINUE;
*GSL_EDOM = *Math::GSL::SparseMatrixc::GSL_EDOM;
*GSL_ERANGE = *Math::GSL::SparseMatrixc::GSL_ERANGE;
*GSL_EFAULT = *Math::GSL::SparseMatrixc::GSL_EFAULT;
*GSL_EINVAL = *Math::GSL::SparseMatrixc::GSL_EINVAL;
*GSL_EFAILED = *Math::GSL::SparseMatrixc::GSL_EFAILED;
*GSL_EFACTOR = *Math::GSL::SparseMatrixc::GSL_EFACTOR;
*GSL_ESANITY = *Math::GSL::SparseMatrixc::GSL_ESANITY;
*GSL_ENOMEM = *Math::GSL::SparseMatrixc::GSL_ENOMEM;
*GSL_EBADFUNC = *Math::GSL::SparseMatrixc::GSL_EBADFUNC;
*GSL_ERUNAWAY = *Math::GSL::SparseMatrixc::GSL_ERUNAWAY;
*GSL_EMAXITER = *Math::GSL::SparseMatrixc::GSL_EMAXITER;
*GSL_EZERODIV = *Math::GSL::SparseMatrixc::GSL_EZERODIV;
*GSL_EBADTOL = *Math::GSL::SparseMatrixc::GSL_EBADTOL;
*GSL_ETOL = *Math::GSL::SparseMatrixc::GSL_ETOL;
*GSL_EUNDRFLW = *Math::GSL::SparseMatrixc::GSL_EUNDRFLW;
*GSL_EOVRFLW = *Math::GSL::SparseMatrixc::GSL_EOVRFLW;
*GSL_ELOSS = *Math::GSL::SparseMatrixc::GSL_ELOSS;
*GSL_EROUND = *Math::GSL::SparseMatrixc::GSL_EROUND;
*GSL_EBADLEN = *Math::GSL::SparseMatrixc::GSL_EBADLEN;
*GSL_ENOTSQR = *Math::GSL::SparseMatrixc::GSL_ENOTSQR;
*GSL_ESING = *Math::GSL::SparseMatrixc::GSL_ESING;
*GSL_EDIVERGE = *Math::GSL::SparseMatrixc::GSL_EDIVERGE;
*GSL_EUNSUP = *Math::GSL::SparseMatrixc::GSL_EUNSUP;
*GSL_EUNIMPL = *Math::GSL::SparseMatrixc::GSL_EUNIMPL;
*GSL_ECACHE = *Math::GSL::SparseMatrixc::GSL_ECACHE;
*GSL_ETABLE = *Math::GSL::SparseMatrixc::GSL_ETABLE;
*GSL_ENOPROG = *Math::GSL::SparseMatrixc::GSL_ENOPROG;
*GSL_ENOPROGJ = *Math::GSL::SparseMatrixc::GSL_ENOPROGJ;
*GSL_ETOLF = *Math::GSL::SparseMatrixc::GSL_ETOLF;
*GSL_ETOLX = *Math::GSL::SparseMatrixc::GSL_ETOLX;
*GSL_ETOLG = *Math::GSL::SparseMatrixc::GSL_ETOLG;
*GSL_EOF = *Math::GSL::SparseMatrixc::GSL_EOF;
*GSL_SPMATRIX_TRIPLET = *Math::GSL::SparseMatrixc::GSL_SPMATRIX_TRIPLET;
*GSL_SPMATRIX_CCS = *Math::GSL::SparseMatrixc::GSL_SPMATRIX_CCS;
*GSL_SPMATRIX_CRS = *Math::GSL::SparseMatrixc::GSL_SPMATRIX_CRS;

@EXPORT_OK = qw/
               gsl_spmatrix_alloc
               gsl_spmatrix_get
               gsl_spmatrix_set
               gsl_spmatrix_free
               gsl_spmatrix_transpose
               gsl_spmatrix_transpose2
               gsl_spmatrix_transpose_memcpy
               gsl_spmatrix_set_zero
               gsl_spmatrix_add
               gsl_spmatrix_nnz
               gsl_spmatrix_scale
               gsl_spmatrix_d2sp
               gsl_spmatrix_sp2d
               gsl_spmatrix_minmax
               gsl_spmatrix_ccs
               gsl_spmatrix_crs
               gsl_spmatrix_memcpy
               gsl_spmatrix_ptr
               gsl_spmatrix_fwrite
               gsl_spmatrix_fread
               gsl_spmatrix_fprintf
               gsl_spmatrix_fscanf
             /;
%EXPORT_TAGS = ( all => [ @EXPORT_OK ] );

__END__

=encoding utf8

=head1 NAME

Math::GSL::SparseMatrix - Sparse Matrices

=head1 SYNOPSIS

    use Math::GSL::SparseMatrix qw/:all/;
    use Math::GSL::Matrix qw/gsl_matrix_alloc/;
    my $sparse = gsl_spmatrix_alloc(100,100);
    my $status = gsl_spmatrix_set($sparse,50,50,42.42);
    my $value  = gsl_spmatrix_get($sparse,50,50);

    # multiply every element by 5
    $status = gsl_spmatrix_scale($sparse, 5);

    # get the number of non-zero elements
    my $nnz = gsl_spmatrix_nnz($sparse);

    # fine min and max values, other than zero elements
    ($status, $min, $max) = gsl_spmatrix_minmax($sparse);

    # set all elements to zero
    $status = gsl_spmatrix_set_zero($sparse);

    my $dense  = gsl_matrix_alloc(100,100);
    # convert a sparse matrix to a dense matrix
    $status = gsl_spmatrix_sp2d($dense, $sparse);

    # convert a dense matrix to a sparse matrix
    $status = gsl_spmatrix_d2sp($sparse, $dense);

=head1 DESCRIPTION

NOTE: This module requires GSL 2.0 or higher.

For more information on the functions, we refer you to the GSL official
documentation: L<http://www.gnu.org/software/gsl/manual/html_node/>

=head1 AUTHORS

Jonathan "Duke" Leto <jonathan@leto.net> and Thierry Moisan <thierry.moisan@gmail.com>

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2008-2024 Jonathan "Duke" Leto and Thierry Moisan

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

=cut


1;