1# This file was automatically generated by SWIG (http://www.swig.org). 2# Version 4.0.1 3# 4# Do not make changes to this file unless you know what you are doing--modify 5# the SWIG interface file instead. 6 7package Math::GSL::Multiset; 8use base qw(Exporter); 9use base qw(DynaLoader); 10package Math::GSL::Multisetc; 11bootstrap Math::GSL::Multiset; 12package Math::GSL::Multiset; 13@EXPORT = qw(); 14 15# ---------- BASE METHODS ------------- 16 17package Math::GSL::Multiset; 18 19sub TIEHASH { 20 my ($classname,$obj) = @_; 21 return bless $obj, $classname; 22} 23 24sub CLEAR { } 25 26sub FIRSTKEY { } 27 28sub NEXTKEY { } 29 30sub FETCH { 31 my ($self,$field) = @_; 32 my $member_func = "swig_${field}_get"; 33 $self->$member_func(); 34} 35 36sub STORE { 37 my ($self,$field,$newval) = @_; 38 my $member_func = "swig_${field}_set"; 39 $self->$member_func($newval); 40} 41 42sub this { 43 my $ptr = shift; 44 return tied(%$ptr); 45} 46 47 48# ------- FUNCTION WRAPPERS -------- 49 50package Math::GSL::Multiset; 51 52*gsl_error = *Math::GSL::Multisetc::gsl_error; 53*gsl_stream_printf = *Math::GSL::Multisetc::gsl_stream_printf; 54*gsl_strerror = *Math::GSL::Multisetc::gsl_strerror; 55*gsl_set_error_handler = *Math::GSL::Multisetc::gsl_set_error_handler; 56*gsl_set_error_handler_off = *Math::GSL::Multisetc::gsl_set_error_handler_off; 57*gsl_set_stream_handler = *Math::GSL::Multisetc::gsl_set_stream_handler; 58*gsl_set_stream = *Math::GSL::Multisetc::gsl_set_stream; 59*gsl_multiset_alloc = *Math::GSL::Multisetc::gsl_multiset_alloc; 60*gsl_multiset_calloc = *Math::GSL::Multisetc::gsl_multiset_calloc; 61*gsl_multiset_init_first = *Math::GSL::Multisetc::gsl_multiset_init_first; 62*gsl_multiset_init_last = *Math::GSL::Multisetc::gsl_multiset_init_last; 63*gsl_multiset_free = *Math::GSL::Multisetc::gsl_multiset_free; 64*gsl_multiset_memcpy = *Math::GSL::Multisetc::gsl_multiset_memcpy; 65*gsl_multiset_fread = *Math::GSL::Multisetc::gsl_multiset_fread; 66*gsl_multiset_fwrite = *Math::GSL::Multisetc::gsl_multiset_fwrite; 67*gsl_multiset_fscanf = *Math::GSL::Multisetc::gsl_multiset_fscanf; 68*gsl_multiset_fprintf = *Math::GSL::Multisetc::gsl_multiset_fprintf; 69*gsl_multiset_n = *Math::GSL::Multisetc::gsl_multiset_n; 70*gsl_multiset_k = *Math::GSL::Multisetc::gsl_multiset_k; 71*gsl_multiset_data = *Math::GSL::Multisetc::gsl_multiset_data; 72*gsl_multiset_valid = *Math::GSL::Multisetc::gsl_multiset_valid; 73*gsl_multiset_next = *Math::GSL::Multisetc::gsl_multiset_next; 74*gsl_multiset_prev = *Math::GSL::Multisetc::gsl_multiset_prev; 75*gsl_multiset_get = *Math::GSL::Multisetc::gsl_multiset_get; 76 77############# Class : Math::GSL::Multiset::gsl_multiset_struct ############## 78 79package Math::GSL::Multiset::gsl_multiset_struct; 80use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS); 81@ISA = qw( Math::GSL::Multiset ); 82%OWNER = (); 83%ITERATORS = (); 84*swig_n_get = *Math::GSL::Multisetc::gsl_multiset_struct_n_get; 85*swig_n_set = *Math::GSL::Multisetc::gsl_multiset_struct_n_set; 86*swig_k_get = *Math::GSL::Multisetc::gsl_multiset_struct_k_get; 87*swig_k_set = *Math::GSL::Multisetc::gsl_multiset_struct_k_set; 88*swig_data_get = *Math::GSL::Multisetc::gsl_multiset_struct_data_get; 89*swig_data_set = *Math::GSL::Multisetc::gsl_multiset_struct_data_set; 90sub new { 91 my $pkg = shift; 92 my $self = Math::GSL::Multisetc::new_gsl_multiset_struct(@_); 93 bless $self, $pkg if defined($self); 94} 95 96sub DESTROY { 97 return unless $_[0]->isa('HASH'); 98 my $self = tied(%{$_[0]}); 99 return unless defined $self; 100 delete $ITERATORS{$self}; 101 if (exists $OWNER{$self}) { 102 Math::GSL::Multisetc::delete_gsl_multiset_struct($self); 103 delete $OWNER{$self}; 104 } 105} 106 107sub DISOWN { 108 my $self = shift; 109 my $ptr = tied(%$self); 110 delete $OWNER{$ptr}; 111} 112 113sub ACQUIRE { 114 my $self = shift; 115 my $ptr = tied(%$self); 116 $OWNER{$ptr} = 1; 117} 118 119 120# ------- VARIABLE STUBS -------- 121 122package Math::GSL::Multiset; 123 124*GSL_VERSION = *Math::GSL::Multisetc::GSL_VERSION; 125*GSL_MAJOR_VERSION = *Math::GSL::Multisetc::GSL_MAJOR_VERSION; 126*GSL_MINOR_VERSION = *Math::GSL::Multisetc::GSL_MINOR_VERSION; 127*GSL_POSZERO = *Math::GSL::Multisetc::GSL_POSZERO; 128*GSL_NEGZERO = *Math::GSL::Multisetc::GSL_NEGZERO; 129*GSL_SUCCESS = *Math::GSL::Multisetc::GSL_SUCCESS; 130*GSL_FAILURE = *Math::GSL::Multisetc::GSL_FAILURE; 131*GSL_CONTINUE = *Math::GSL::Multisetc::GSL_CONTINUE; 132*GSL_EDOM = *Math::GSL::Multisetc::GSL_EDOM; 133*GSL_ERANGE = *Math::GSL::Multisetc::GSL_ERANGE; 134*GSL_EFAULT = *Math::GSL::Multisetc::GSL_EFAULT; 135*GSL_EINVAL = *Math::GSL::Multisetc::GSL_EINVAL; 136*GSL_EFAILED = *Math::GSL::Multisetc::GSL_EFAILED; 137*GSL_EFACTOR = *Math::GSL::Multisetc::GSL_EFACTOR; 138*GSL_ESANITY = *Math::GSL::Multisetc::GSL_ESANITY; 139*GSL_ENOMEM = *Math::GSL::Multisetc::GSL_ENOMEM; 140*GSL_EBADFUNC = *Math::GSL::Multisetc::GSL_EBADFUNC; 141*GSL_ERUNAWAY = *Math::GSL::Multisetc::GSL_ERUNAWAY; 142*GSL_EMAXITER = *Math::GSL::Multisetc::GSL_EMAXITER; 143*GSL_EZERODIV = *Math::GSL::Multisetc::GSL_EZERODIV; 144*GSL_EBADTOL = *Math::GSL::Multisetc::GSL_EBADTOL; 145*GSL_ETOL = *Math::GSL::Multisetc::GSL_ETOL; 146*GSL_EUNDRFLW = *Math::GSL::Multisetc::GSL_EUNDRFLW; 147*GSL_EOVRFLW = *Math::GSL::Multisetc::GSL_EOVRFLW; 148*GSL_ELOSS = *Math::GSL::Multisetc::GSL_ELOSS; 149*GSL_EROUND = *Math::GSL::Multisetc::GSL_EROUND; 150*GSL_EBADLEN = *Math::GSL::Multisetc::GSL_EBADLEN; 151*GSL_ENOTSQR = *Math::GSL::Multisetc::GSL_ENOTSQR; 152*GSL_ESING = *Math::GSL::Multisetc::GSL_ESING; 153*GSL_EDIVERGE = *Math::GSL::Multisetc::GSL_EDIVERGE; 154*GSL_EUNSUP = *Math::GSL::Multisetc::GSL_EUNSUP; 155*GSL_EUNIMPL = *Math::GSL::Multisetc::GSL_EUNIMPL; 156*GSL_ECACHE = *Math::GSL::Multisetc::GSL_ECACHE; 157*GSL_ETABLE = *Math::GSL::Multisetc::GSL_ETABLE; 158*GSL_ENOPROG = *Math::GSL::Multisetc::GSL_ENOPROG; 159*GSL_ENOPROGJ = *Math::GSL::Multisetc::GSL_ENOPROGJ; 160*GSL_ETOLF = *Math::GSL::Multisetc::GSL_ETOLF; 161*GSL_ETOLX = *Math::GSL::Multisetc::GSL_ETOLX; 162*GSL_ETOLG = *Math::GSL::Multisetc::GSL_ETOLG; 163*GSL_EOF = *Math::GSL::Multisetc::GSL_EOF; 164 165 166use Math::GSL qw/gsl_version/; 167 168@EXPORT_OK = qw/ 169 gsl_multiset_calloc gsl_multiset_alloc 170 gsl_multiset_init_first gsl_multiset_init_last 171 gsl_multiset_free gsl_multiset_memcpy 172 gsl_multiset_get gsl_multiset_n gsl_multiset_k 173 gsl_multiset_data 174 gsl_multiset_valid 175 gsl_multiset_next gsl_multiset_prev 176 gsl_multiset_fwrite 177 gsl_multiset_fread 178 gsl_multiset_fprintf 179 gsl_multiset_fscanf 180/; 181 182 183%EXPORT_TAGS = ( all => [ @EXPORT_OK ] ); 184 185sub new { 186 my ($class, $n, $k) = @_; 187 188 if (gsl_version() < v1.16 && $k > $n) { 189 die __PACKAGE__.": This version of GSL doesn't support k > n" 190 } 191 192 my $self = { k => $k, n => $n, multiset => gsl_multiset_calloc($n, $k)}; 193 194 return bless $self, $class; 195} 196 197sub init_first { 198 my ($self) = @_; 199 gsl_multiset_init_first($self->{multiset}); 200} 201 202sub init_last { 203 my ($self) = @_; 204 gsl_multiset_init_last($self->{multiset}); 205} 206 207 208sub get { 209 my ($self, $i) = @_; 210 die __PACKAGE__.": element $i is out of range (0 <= i < $self->{k})" 211 unless $i >= 0 && $i < $self->{k}; 212 return gsl_multiset_get($self->{multiset}, $i); 213} 214 215sub k { $_[0]->{k} } 216sub n { $_[0]->{n} } 217 218sub clone { 219 my $self = shift; 220 my $other = ref($self)->new($self->n, $self->k); 221 gsl_multiset_memcpy($other->{multiset}, $self->{multiset}); 222 return $other; 223} 224 225sub next { 226 my $self=shift; 227 return gsl_multiset_next($self->{multiset}); 228} 229 230sub prev { 231 my $self=shift; 232 return gsl_multiset_prev($self->{multiset}); 233} 234 235sub to_list { 236 my $self = shift; 237 return map { $self->get($_) } (0..$self->k-1); 238} 239 240sub DESTROY { 241 my $self = shift; 242 gsl_multiset_free($self->{multiset}); 243} 244 245__END__ 246 247=encoding utf8 248 249=head1 NAME 250 251Math::GSL::Multiset - Multisets manipulation 252 253=head1 SYNOPSIS 254 255 use Math::GSL::Multiset qw/:all/; 256 257 my $ms = Math::GSL::Multiset->($n, $k); 258 259 my $value = $ms->get(2); 260 261 # compute next multiset 262 $ms->next; 263 # compute the previous multiset 264 265 266 # clone a multiset 267 my $other = $ms->clone(); 268 269=head1 DESCRIPTION 270 271A multiset c is represented by an array of k integers 272in the range 0 to n-1, where each value c_i may occur more 273than once. The multiset c corresponds to indices of k elements 274chosen from an n element vector with replacement. In mathematical 275terms, n is the cardinality of the multiset while k is the maximum 276multiplicity of any value. 277 278=head2 Object Oriented API 279 280Handy Perl-style OO API for Multisets. 281 282=over 4 283 284=item C<new> 285 286Creates a new multiset with parameters n, k and initializes it to the 287lexicographically first multiset element, i.e., 0 repeated k times. 288 289 my $ms = Math::GSL::Multiset->($n, $k); 290 291=item C<init_first> 292 293Initializes the multiset to the lexicographically first multiset element, i.e. 2940 repeated k times. 295 296 $ms->init_first; 297 298=item C<init_last> 299 300Initializes the multiset c to the lexicographically last multiset element, i.e. 301n-1 repeated k times. 302 303 $ms->init_last; 304 305=item C<get> 306 307Returns the value of the i-th element of the multiset. If i lies outside 308the allowed range of 0 to k-1 then the error handler is invoked and 0 is returned. 309 310 my $val = $ms->get($k-1); 311 312=item C<next> 313 314Advances the multiset to the next multiset element in lexicographic order and returns 315GSL_SUCCESS. If no further multisets elements are available it returns GSL_FAILURE and 316leaves the multiset unmodified. Starting with the first multiset and repeatedly applying 317this function will iterate through all possible multisets of a given order. 318 319 $ms->next(); 320 321=item C<prev> 322 323 $ms->prev(); 324 325Steps backwards from the multiset to the previous multiset element in lexicographic 326order, returning GSL_SUCCESS. If no previous multiset is available it returns 327GSL_FAILURE and leaves the multiset unmodified. 328 329=item C<to_list> 330 331Creates a Perl list of integers with the values from the multiset, starting at 332index 0 and ending at index $k-1. 333 334 @data = $ms->to_list; 335 336=item C<clone> 337 338Creates a new multiset with the same size, and same values. 339 340 my $new = $ms->clone; 341 342=back 343 344=head2 GSL API 345 346For reference on these methds, please consult the GSL documentation. 347 348=over 4 349 350=item C<gsl_multiset_calloc> 351 352=item C<gsl_multiset_alloc> 353 354=item C<gsl_multiset_init_first> 355 356=item C<gsl_multiset_init_last> 357 358=item C<gsl_multiset_free> 359 360=item C<gsl_multiset_memcpy> 361 362=item C<gsl_multiset_get> 363 364=item C<gsl_multiset_n> 365 366=item C<gsl_multiset_k> 367 368=item C<gsl_multiset_data> 369 370=item C<gsl_multiset_valid> 371 372=item C<gsl_multiset_next> 373 374=item C<gsl_multiset_prev> 375 376=item C<gsl_multiset_fwrite> 377 378=item C<gsl_multiset_fread> 379 380=item C<gsl_multiset_fprintf> 381 382=item C<gsl_multiset_fscanf> 383 384 385=back 386 387=head1 AUTHORS 388 389Jonathan "Duke" Leto <jonathan@leto.net> and Thierry Moisan <thierry.moisan@gmail.com> 390 391=head1 COPYRIGHT AND LICENSE 392 393Copyright (C) 2008-2021 Jonathan "Duke" Leto and Thierry Moisan 394 395This program is free software; you can redistribute it and/or modify it 396under the same terms as Perl itself. 397 398=cut 3991; 400