NAME

PDL::GSL::RNG - PDL interface to RNG and randist routines in GSL

DESCRIPTION

This is an interface to the rng and randist packages present in the GNU Scientific Library.

SYNOPSIS

use PDL;
use PDL::GSL::RNG;

$rng = PDL::GSL::RNG->new('taus');

$rng->set_seed(time());

$x=zeroes(5,5,5)

$rng->get_uniform($x); # inplace

$y=$rng->get_uniform(3,4,5); # creates new pdl

NOMENCLATURE

Throughout this documentation we strive to use the same variables that are present in the original GSL documentation (see See Also). Oftentimes those variables are called a and b. Since good Perl coding practices discourage the use of Perl variables $a and $b, here we refer to Parameters a and b as $pa and $pb, respectively, and Limits (of domain or integration) as $la and $lb.

new

The new method initializes a new instance of the RNG.

The available RNGs are:

coveyou
cmrg
fishman18
fishman20
fishman2x
gfsr4
knuthran
knuthran2
knuthran2002
lecuyer21
minstd
mrg
mt19937
mt19937_1999
mt19937_1998
r250
ran0
ran1
ran2
ran3
rand
rand48
random128_bsd
random128_glibc2
random128_libc5
random256_bsd
random256_glibc2
random256_libc5
random32_bsd
random32_glibc2
random32_libc5
random64_bsd
random64_glibc2
random64_libc5
random8_bsd
random8_glibc2
random8_libc5
random_bsd
random_glibc2
random_libc5
randu
ranf
ranlux
ranlux389
ranlxd1
ranlxd2
ranlxs0
ranlxs1
ranlxs2
ranmar
slatec
taus
taus2
taus113
transputer
tt800
uni
uni32
vax
waterman14
zuf
default

The last one (default) uses the environment variable GSL_RNG_TYPE.

Note that only a few of these rngs are recommended for general use. Please check the GSL documentation for more information.

Usage:

$blessed_ref = PDL::GSL::RNG->new($RNG_name);

Example:

$rng = PDL::GSL::RNG->new('taus');

set_seed

Sets the RNG seed.

Usage:

$rng->set_seed($integer);
# or
$rng = PDL::GSL::RNG->new('taus')->set_seed($integer);

Example:

$rng->set_seed(666);

min

Return the minimum value generable by this RNG.

Usage:

$integer = $rng->min();

Example:

$min = $rng->min(); $max = $rng->max();

max

Return the maximum value generable by the RNG.

Usage:

$integer = $rng->max();

Example:

$min = $rng->min(); $max = $rng->max();

name

Returns the name of the RNG.

Usage:

$string = $rng->name();

Example:

$name = $rng->name();

ran_shuffle

Shuffles values in ndarray, treating it as flat.

Usage:

$rng->ran_shuffle($ndarray);

ran_shuffle_vec

Returns values in Perl list, shuffled.

Usage:

@shuffled = $rng->ran_shuffle_vec(@vec);

ran_choose

Chooses values from $inndarray to $outndarray, treating both as flat.

Usage:

$rng->ran_choose($inndarray,$outndarray);

ran_choose_vec

Chooses $n values from @vec.

Usage:

@chosen = $rng->ran_choose_vec($n,@vec);

ran_dir

Returns $n random vectors in $ndim dimensions.

Usage:

$ndarray = $rng->ran_dir($ndim,$n);

Example:

$o = $rng->ran_dir($ndim,$n);

ran_discrete_preproc

This method returns a handle that must be used when calling "ran_discrete". You specify the probability of the integer number that are returned by "ran_discrete".

Usage:

$discrete_dist_handle = $rng->ran_discrete_preproc($double_ndarray_prob);

Example:

$prob = pdl [0.1,0.3,0.6];
$ddh = $rng->ran_discrete_preproc($prob);
$o = $rng->ran_discrete($discrete_dist_handle,100);

BUGS

Feedback is welcome. Log bugs in the PDL bug database (the database is always linked from http://pdl.perl.org/).

SEE ALSO

PDL

The GSL documentation for random number distributions is online at https://www.gnu.org/software/gsl/doc/html/randist.html

AUTHOR

This file copyright (C) 1999 Christian Pellegrin <chri@infis.univ.trieste.it> Docs mangled by C. Soeller. All rights reserved. There is no warranty. You are allowed to redistribute this software / documentation under certain conditions. For details, see the file COPYING in the PDL distribution. If this file is separated from the PDL distribution, the copyright notice should be included in the file.

The GSL RNG and randist modules were written by James Theiler.

Takes n-dimensional ndarray, and shuffles it along its zero-th dimension.

Usage:

$vec2d = sequence(10,10);
$rng->ran_shuffle_1d($vec2d);
EOF
);

pp_def('get_uniform', Pars => '[o]a()', GenericTypes => ['F','D'], OtherPars => 'gsl_rng *rng', Code => ' $a() = gsl_rng_uniform($COMP(rng));', PMCode => make_get_sub('get_uniform',''), Doc => <<'EOF', =for ref

This function creates an ndarray with given dimensions or accepts an existing ndarray and fills it. get_uniform() returns values 0<=x<1,

Usage:

$ndarray = $rng->get_uniform($list_of_integers)
$rng->get_uniform($ndarray);

Example:

$x = zeroes 5,6; $max=100;
$o = $rng->get_uniform(10,10); $rng->get_uniform($x);
EOF
);

pp_def('get_uniform_pos', Pars => '[o]a()', GenericTypes => ['F','D'], OtherPars => 'gsl_rng *rng', Code => ' $a() = gsl_rng_uniform_pos($COMP(rng));', PMCode => make_get_sub('get_uniform_pos',''), Doc => <<'EOF', =for ref

This function creates an ndarray with given dimensions or accepts an existing ndarray and fills it. get_uniform_pos() returns values 0<x<1,

Usage:

$ndarray = $rng->get_uniform_pos($list_of_integers)
$rng->get_uniform_pos($ndarray);

Example:

$x = zeroes 5,6;
$o = $rng->get_uniform_pos(10,10); $rng->get_uniform_pos($x);
EOF
);

pp_def('get', Pars => '[o]a()', GenericTypes => ['F','D'], OtherPars => 'gsl_rng *rng', Code => ' $a() = gsl_rng_get($COMP(rng));', PMCode => make_get_sub('get',''), Doc => <<'EOF', =for ref

This function creates an ndarray with given dimensions or accepts an existing ndarray and fills it. get() returns integer values between a minimum and a maximum specific to every RNG.

Usage:

$ndarray = $rng->get($list_of_integers)
$rng->get($ndarray);

Example:

$x = zeroes 5,6;
$o = $rng->get(10,10); $rng->get($x);
EOF
);

pp_def('get_int', Pars => '[o]a()', GenericTypes => ['F','D'], OtherPars => 'IV n; gsl_rng *rng', Code => ' $a() = gsl_rng_uniform_int($COMP(rng),$COMP(n));', PMCode => make_get_sub('get_int','$n,'), Doc => <<'EOF', =for ref

This function creates an ndarray with given dimensions or accepts an existing ndarray and fills it. get_int() returns integer values between 0 and $max.

Usage:

$ndarray = $rng->get($max, $list_of_integers)
$rng->get($max, $ndarray);

Example:

$x = zeroes 5,6; $max=100;
$o = $rng->get(10,10); $rng->get($x);
EOF
);

# randist stuff

sub add_randist { my ($name,$doc,$params) = @_; my $npar = @$params; my $pars1=join '; ', (map "double $_", @$params), 'gsl_rng *rng'; my $fcall1=join ',', map "\$COMP($_)", @$params; my $arglist=join '', map "\$$_,", @$params; my $pars2=join ';', map "$_()", @$params; my $fcall2=join ',', map "\$$_()", @$params; my $arglist2=join ',', map "\$${_}_ndarray", @$params;

  pp_def(
	 'ran_' . $name,
	 Pars => '[o]output()',
	 GenericTypes => ['F','D'],
	 OtherPars => $pars1,
	 Code =>'
$output() = gsl_ran_' . $name . '($COMP(rng),' . $fcall1 . ');',
	 PMCode =>'
sub ran_' . $name . ' {
my ($obj,' . $arglist . '@var) = @_;
if (ref($var[0]) eq \'PDL\') {
    _ran_' . $name . '_int($var[0],' . $arglist . '$obj);
    return $var[0];
}
else {
    my $p;
    $p = zeroes @var;
    _ran_' . $name . '_int($p,' . $arglist . '$obj);
    return $p;
}
}
',
	 Doc => <<EOF,
=for ref

Fills output ndarray with random $doc

Usage:

\$ndarray = \$rng->ran_$name(@{[join ', ', map qq{\$$_}, @$params]},[list of integers = output ndarray dims]);
\$rng->ran_$name(@{[join ', ', map qq{\$$_}, @$params]}, \$output_ndarray);

Example:

  \$o = \$rng->ran_$name(@{[join ', ', map qq{\$$_}, @$params]},10,10);
  \$rng->ran_$name(@{[join ', ', map qq{\$$_}, @$params]},\$o);
EOF
);

  pp_def(
	 'ran_' . $name . '_var',
	 Pars => $pars2 . ';[o]output()',
	 GenericTypes => ['F','D'],
	 OtherPars => 'gsl_rng *rng',
	 Code =>'
$output() = gsl_ran_' . $name . '($COMP(rng),' . $fcall2 . ');',
	 PMCode =>'
sub ran_' . $name . '_var {
my ($obj,@var) = @_;
    if (scalar(@var) != ' . $npar . ') {barf("Bad number of parameters!");}
    _ran_' . $name . '_var_int(@var,my $x=PDL->null,$obj);
    return $x;
}
',
	 Doc => <<EOF,
=for ref

Similar to "ran_$name" except that it takes the distribution parameters as an ndarray and returns an ndarray of equal dimensions.

Usage:

 \$ndarray = \$rng->ran_${name}_var($arglist2);
EOF
);
}

add_randist('gaussian','values from Gaussian distribution with mean zero and standard deviation $sigma.',[qw(sigma)]); add_randist('ugaussian_tail', 'variates from the upper tail of a Gaussian distribution with standard deviation = 1 (AKA unit Gaussian distribution).',[qw(tail)]); add_randist('exponential', 'variates from the exponential distribution with mean $mu.',[qw(mu)]); add_randist('laplace', 'variates from the Laplace distribution with width $pa.',[qw(pa)]); add_randist('exppow', 'variates from the exponential power distribution with scale parameter $pa and exponent $pb.',[qw(pa pb)]); add_randist('cauchy', 'variates from the Cauchy distribution with scale parameter $pa.',[qw(pa)]); add_randist('rayleigh', 'variates from the Rayleigh distribution with scale parameter $sigma.',[qw(sigma)]); add_randist('rayleigh_tail', 'variates from the tail of the Rayleigh distribution with scale parameter $sigma and a lower limit of $la.',[qw(x sigma)]); add_randist('levy', 'variates from the Levy symmetric stable distribution with scale $c and exponent $alpha.',[qw(mu x)]); add_randist('gamma', 'variates from the gamma distribution.',[qw(pa pb)]); add_randist('flat', 'variates from the flat (uniform) distribution from $la to $lb.',[qw(la lb)]); add_randist('lognormal', 'variates from the lognormal distribution with parameters $mu (location) and $sigma (scale).',[qw(mu sigma)]); add_randist('chisq', 'variates from the chi-squared distribution with $nu degrees of freedom.',[qw(nu)]); add_randist('fdist', 'variates from the F-distribution with degrees of freedom $nu1 and $nu2.',[qw(nu1 nu2)]); add_randist('tdist', q{variates from the t-distribution (AKA Student's t-distribution) with $nu degrees of freedom.},[qw(nu)]); add_randist('beta', 'variates from the beta distribution with parameters $pa and $pb.',[qw(pa pb)]); add_randist('logistic', 'random variates from the logistic distribution.',[qw(m)]); add_randist('pareto', 'variates from the Pareto distribution of order $pa and scale $lb.',[qw(pa lb)]); add_randist('weibull', 'variates from the Weibull distribution with scale $pa and exponent $pb. (Some literature uses lambda for $pa and k for $pb.)',[qw(pa pb)]); add_randist('gumbel1', 'variates from the Type-1 Gumbel distribution.',[qw(pa pb)]); add_randist('gumbel2', 'variates from the Type-2 Gumbel distribution.',[qw(pa pb)]); add_randist('poisson','integer values from the Poisson distribution with mean $mu.',[qw(mu)]); add_randist('bernoulli', 'values 0 or 1, the result of a Bernoulli trial with probability $p.',[qw(p)]); add_randist('binomial', 'integer values from the binomial distribution, the number of successes in $n independent trials with probability $p.',[qw(p n)]); add_randist('negative_binomial', 'integer values from the negative binomial distribution, the number of failures occurring before $n successes in independent trials with probability $p of success. Note that $n is not required to be an integer.',[qw(p n)]); add_randist('pascal', 'integer values from the Pascal distribution. The Pascal distribution is simply a negative binomial distribution (see "ran_negative_binomial") with an integer value of $n.',[qw(p n)]); add_randist('geometric', 'integer values from the geometric distribution, the number of independent trials with probability $p until the first success.',[qw(p)]); add_randist('hypergeometric', 'integer values from the hypergeometric distribution. If a population contains $n1 elements of type 1 and $n2 elements of type 2 then the hypergeometric distribution gives the probability of obtaining $x elements of type 1 in $t samples from the population without replacement.',[qw(n1 n2 t)]); add_randist('logarithmic', 'integer values from the logarithmic distribution.',[qw(p)]);

# specific randist

pp_def('ran_additive_gaussian', Pars => '[o]x()', GenericTypes => ['F','D'], OtherPars => 'double sigma; gsl_rng *rng', Code =>'$x() += gsl_ran_gaussian($COMP(rng), $COMP(sigma));', PMCode =>' sub ran_additive_gaussian { my ($obj,$sigma,$var) = @_; barf("In additive gaussian mode you must specify an ndarray!") if ref($var) ne \'PDL\'; _ran_additive_gaussian_int($var,$sigma,$obj); return $var; } ', Doc => <<'EOF', =for ref

Add Gaussian noise of given sigma to an ndarray.

Usage:

$rng->ran_additive_gaussian($sigma,$ndarray);

Example:

$rng->ran_additive_gaussian(1,$image);
EOF
);

pp_def('ran_additive_poisson', Pars => '[o]x()', GenericTypes => ['F','D'], OtherPars => 'double sigma; gsl_rng *rng', Code =>'$x() += gsl_ran_poisson($COMP(rng), $COMP(sigma));', PMCode =>' sub ran_additive_poisson { my ($obj,$sigma,$var) = @_; barf("In additive poisson mode you must specify an ndarray!") if ref($var) ne \'PDL\'; _ran_additive_poisson_int($var,$sigma,$obj); return $var; } ', Doc => <<'EOF', =for ref

Add Poisson noise of given $mu to a $ndarray.

Usage:

$rng->ran_additive_poisson($mu,$ndarray);

Example:

$rng->ran_additive_poisson(1,$image);
EOF
);

pp_def('ran_feed_poisson', Pars => '[o]x()', GenericTypes => ['F','D'], OtherPars => 'gsl_rng *rng', Code =>'$x() = gsl_ran_poisson($COMP(rng), $x());', PMCode =>' sub ran_feed_poisson { my ($obj,$var) = @_; barf("In poisson mode you must specify an ndarray!") if ref($var) ne \'PDL\'; _ran_feed_poisson_int($var,$obj); return $var; } ', Doc => <<'EOF', =for ref

This method simulates shot noise, taking the values of ndarray as values for $mu to be fed in the poissonian RNG.

Usage:

$rng->ran_feed_poisson($ndarray);

Example:

$rng->ran_feed_poisson($image);
EOF
);

pp_def('ran_bivariate_gaussian', Pars => '[o]x(n)', GenericTypes => ['F','D'], OtherPars => 'double sigma_x; double sigma_y; double rho; gsl_rng *rng', Code => <<'EOF', double xx,yy; gsl_ran_bivariate_gaussian($COMP(rng), $COMP(sigma_x), $COMP(sigma_y),$COMP(rho), &xx, &yy); $x(n=>0)=xx; $x(n=>1)=yy; EOF PMCode => <<'EOF', sub ran_bivariate_gaussian { my ($obj,$sigma_x,$sigma_y,$rho,$n) = @_; barf("Not enough parameters for gaussian bivariate!") if $n<=0; my $p = zeroes(2,$n); _ran_bivariate_gaussian_int($p,$sigma_x,$sigma_y,$rho,$obj); return $p; } EOF Doc => <<'EOF', =for ref

Generates $n bivariate gaussian random deviates.

Usage:

$ndarray = $rng->ran_bivariate_gaussian($sigma_x,$sigma_y,$rho,$n);

Example:

$o = $rng->ran_bivariate_gaussian(1,2,0.5,1000);
EOF
);

pp_defnd('ran_dir_2d', Pars => '[o]x(n)', GenericTypes => ['F','D'], OtherPars => 'gsl_rng *rng', Code =>' double xx,yy; gsl_ran_dir_2d($COMP(rng), &xx, &yy); $x(n=>0)=xx; $x(n=>1)=yy; ');

pp_defnd('ran_dir_3d', Pars => '[o]x(n)', GenericTypes => ['F','D'], OtherPars => 'gsl_rng *rng', Code =>' double xx,yy,zz; gsl_ran_dir_3d($COMP(rng), &xx, &yy, &zz); $x(n=>0)=xx; $x(n=>1)=yy; $x(n=>2)=zz; ');

my $MAX_DIMENSIONS = 100;

pp_defnd('ran_dir_nd', Pars => '[o]x(n)', GenericTypes => ['F','D'], OtherPars => 'IV ns => n; gsl_rng *rng', Code =>' double xxx[' . $MAX_DIMENSIONS .']; gsl_ran_dir_nd($COMP(rng), $COMP(ns), xxx); loop (n) %{ $x() = xxx[n]; %}');

pp_addpm(' sub ran_dir { my ($obj,$ndim,$n) = @_; barf("Not enough parameters for random vectors!") if $n<=0; my $p = zeroes($ndim,$n); if ($ndim==2) { ran_dir_2d($p,$obj); } elsif ($ndim==3) { ran_dir_3d($p,$obj); } elsif ($ndim>=4 && $ndim<=' . $MAX_DIMENSIONS . ') { ran_dir_nd($p,$ndim,$obj); } else { barf("Bad number of dimensions!"); } return $p; } ');

pp_def('ran_discrete', Pars => '[o]x()', GenericTypes => ['F','D'], OtherPars => 'gsl_ran_discrete_t *rng_discrete; gsl_rng *rng', Code =>' $x()=gsl_ran_discrete($COMP(rng), $COMP(rng_discrete)); ', PMCode =>' sub ran_discrete { my ($obj, $rdt, @var) = @_; if (ref($var[0]) eq \'PDL\') { _ran_discrete_int($var[0], $rdt, $obj); return $var[0]; } else { my $p; $p = zeroes @var; _ran_discrete_int($p, $rdt, $obj); return $p; } } ', Doc => <<'EOF', =for ref

Is used to get the desired samples once a proper handle has been enstablished (see ran_discrete_preproc()).

Usage:

$ndarray = $rng->ran_discrete($discrete_dist_handle,$num);

Example:

 $prob = pdl [0.1,0.3,0.6];
 $ddh = $rng->ran_discrete_preproc($prob);
 $o = $rng->ran_discrete($discrete_dist_handle,100);
EOF
);

pp_addpm('
sub ran_shuffle_vec {
my ($obj,@in) = @_;
$obj->ran_shuffle(my $p = PDL->sequence(PDL::indx(), 0+@in));
@in[$p->list];
}
');

pp_addpm('
sub ran_choose_vec {
my ($obj,$nout,@in) = @_;
$obj->ran_choose(PDL->sequence(PDL::indx(), 0+@in),my $pout = PDL->zeroes(PDL::indx(), $nout));
@in[$pout->list];
}
');

pp_def('ran_ver', Pars => '[o]x(n)', GenericTypes => ['F','D'], OtherPars => 'double x0; double r;IV ns => n; gsl_rng *rng', Code =>' double xx=$COMP(x0);

loop (n) %{ $x() = xx; xx = $COMP(r)*(1-xx)*xx; %}', PMCode =>' sub ran_ver { my ($obj,$x0,$r,$n) = @_; barf("Not enough parameters for ran_ver!") if $n<=0; my $p = zeroes($n); _ran_ver_int($p,$x0,$r,$n,$obj); return $p; } ', Doc => <<'EOF', =for ref

Returns an ndarray with $n values generated by the Verhulst map from $x0 and parameter $r.

Usage:

$rng->ran_ver($x0, $r, $n);
EOF
);

pp_def('ran_caos', Pars => '[o]x(n)', GenericTypes => ['F','D'], OtherPars => 'double m; IV ns => n; gsl_rng *rng', Code =>' double xx=gsl_ran_gaussian($COMP(rng),0.1)+0.5;

loop (n) %{ $x() = (xx-0.5)*$COMP(m); xx = 4.0*(1-xx)*xx; %}', PMCode =>' sub ran_caos { my ($obj,$m,$n) = @_; barf("Not enough parameters for ran_caos!") if $n<=0; my $p = zeroes($n); _ran_caos_int($p,$m,$n,$obj); return $p; } ', Doc => <<'EOF', =for ref

Returns values from Verhuls map with $r=4.0 and randomly chosen $x0. The values are scaled by $m.

Usage:

$rng->ran_caos($m,$n);
EOF
);

# XS function for the RNG object

pp_addxs('',' MODULE = PDL::GSL::RNG PACKAGE = PDL::GSL::RNG

#define DEF_RNG(X) if (!strcmp(TYPE,#X)) rng=gsl_rng_alloc( gsl_rng_ ## X ); strcat(rngs,#X ", ");

gsl_rng * new (CLASS,TYPE) char *CLASS char *TYPE CODE: gsl_rng * rng = NULL; char rngs[5000]; strcpy(rngs,""); DEF_RNG(borosh13) DEF_RNG(coveyou) DEF_RNG(cmrg) DEF_RNG(fishman18) DEF_RNG(fishman20) DEF_RNG(fishman2x) DEF_RNG(gfsr4) DEF_RNG(knuthran) DEF_RNG(knuthran2) DEF_RNG(knuthran2002) DEF_RNG(lecuyer21) DEF_RNG(minstd) DEF_RNG(mrg) DEF_RNG(mt19937) DEF_RNG(mt19937_1999) DEF_RNG(mt19937_1998) DEF_RNG(r250) DEF_RNG(ran0) DEF_RNG(ran1) DEF_RNG(ran2) DEF_RNG(ran3) DEF_RNG(rand) DEF_RNG(rand48) DEF_RNG(random128_bsd) DEF_RNG(random128_glibc2) DEF_RNG(random128_libc5) DEF_RNG(random256_bsd) DEF_RNG(random256_glibc2) DEF_RNG(random256_libc5) DEF_RNG(random32_bsd) DEF_RNG(random32_glibc2) DEF_RNG(random32_libc5) DEF_RNG(random64_bsd) DEF_RNG(random64_glibc2) DEF_RNG(random64_libc5) DEF_RNG(random8_bsd) DEF_RNG(random8_glibc2) DEF_RNG(random8_libc5) DEF_RNG(random_bsd) DEF_RNG(random_glibc2) DEF_RNG(random_libc5) DEF_RNG(randu) DEF_RNG(ranf) DEF_RNG(ranlux) DEF_RNG(ranlux389) DEF_RNG(ranlxd1) DEF_RNG(ranlxd2) DEF_RNG(ranlxs0) DEF_RNG(ranlxs1) DEF_RNG(ranlxs2) DEF_RNG(ranmar) DEF_RNG(slatec) DEF_RNG(taus) DEF_RNG(taus2) DEF_RNG(taus113) DEF_RNG(transputer) DEF_RNG(tt800) DEF_RNG(uni) DEF_RNG(uni32) DEF_RNG(vax) DEF_RNG(waterman14) DEF_RNG(zuf) DEF_RNG(default) if (rng==NULL) { barf("Unknown RNG, please use one of the following: %s", rngs); } else RETVAL = rng; OUTPUT: RETVAL

void set_seed(rng, seed) gsl_rng * rng int seed PPCODE: gsl_rng_set(rng,seed); XPUSHs(ST(0)); /* return self */

unsigned int min(rng) gsl_rng * rng CODE: RETVAL = gsl_rng_min(rng); OUTPUT: RETVAL

unsigned int max(rng) gsl_rng * rng CODE: RETVAL = gsl_rng_max(rng); OUTPUT: RETVAL

char* name(rng) gsl_rng * rng CODE: RETVAL = (char *) gsl_rng_name(rng); OUTPUT: RETVAL

void DESTROY(sv) SV * sv CODE: gsl_rng *rng = INT2PTR(gsl_rng *, SvIV((SV*)SvRV(sv))); gsl_rng_free(rng);

gsl_ran_discrete_t * ran_discrete_preproc(rng, p) gsl_rng * rng pdl * p CODE: IV n; if (p->ndims!=1 || p->datatype!=PDL_D) { barf("Bad input to ran_discrete_preproc!"); } PDL->barf_if_error(PDL->make_physical(p)); n = p->dims[0]; RETVAL = gsl_ran_discrete_preproc(n,(double *) p->data); OUTPUT: RETVAL

void ran_shuffle(rng, in) gsl_rng * rng pdl * in CODE: IV size, n; PDL->barf_if_error(PDL->make_physical(in)); n = in->nvals; size = PDL->howbig(in->datatype); gsl_ran_shuffle(rng,in->data,n,size); PDL->changed(in, PDL_PARENTDATACHANGED, 0);

void ran_choose(rng, in, out) gsl_rng * rng pdl * in pdl * out CODE: IV size, n,m;

if (in->datatype != out->datatype) barf("Data Types must match for ran_chooser");
PDL->barf_if_error(PDL->make_physical(in));
PDL->barf_if_error(PDL->make_physical(out));
n = in->nvals;
m = out->nvals;
size = PDL->howbig(in->datatype);
gsl_ran_choose(rng,out->data, m, in->data,n,size);
PDL->changed(out, PDL_PARENTDATACHANGED, 0);
');

pp_core_importList(' qw/ zeroes long barf /'); # import just a named list to our namespace, so we don't get warning # messages like 'warning 'min' redefined at line ...'

pp_export_nothing; # set to not export anything. (This is a OO package, it doesn't need to export any methods.) pp_add_exported(@export_names); # ... except functions suitable for that

pp_add_boot('gsl_set_error_handler_off(); ');

pp_done();