[Gsll-devel] patch to export random number distribution symbols

James Wright james at chumsley.org
Thu Jan 7 20:23:31 UTC 2010


A related question for Liam:  It seems like keywords would make more
sense for the selector symbols (e.g., :uniform rather that
'gsl:uniform).  Is there any particular reason that the selection
symbols are in the GSL package instead?

Thanks,
      James

On Wed, Jan 6, 2010 at 7:12 PM, Russell Kliese <russell at kliese.id.au> wrote:
> It appears that the symbols used to select the various random number sample
> functions are not exported. I was getting "The symbol "UNIFORM" is not
> external in the GSLL package." when I ran the following code.
>
> (clc:clc-require :gsll)
> (defparameter *rng* (gsl:make-random-number-generator gsl:+default-type+))
> (gsl:sample *rng* 'gsl:uniform)
>
> I've created a patch to merge into the git repository, but I'm not a Lisp
> expert, so my solution may be wrong.
>
> Thanks to all who have contributed to this very useful library.
>
> Russell
>
>
> diff --git a/random/bernoulli.lisp b/random/bernoulli.lisp
> index 5e6ba48..e3259a7 100644
> --- a/random/bernoulli.lisp
> +++ b/random/bernoulli.lisp
> @@ -20,6 +20,7 @@
>
>  (in-package :gsl)
>
> +(export 'bernoulli)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'bernoulli))
>      &key probability)
> diff --git a/random/beta.lisp b/random/beta.lisp
> index f830f50..e63ab29 100644
> --- a/random/beta.lisp
> +++ b/random/beta.lisp
> @@ -20,6 +20,7 @@
>
>  (in-package :gsl)
>
> +(export 'beta)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'beta)) &key a b)
>   "gsl_ran_beta"
> diff --git a/random/cauchy.lisp b/random/cauchy.lisp
> index ef8c44d..88913a7 100644
> --- a/random/cauchy.lisp
> +++ b/random/cauchy.lisp
> @@ -23,6 +23,7 @@
>  ;;; /usr/include/gsl/gsl_randist.h
>  ;;; /usr/include/gsl/gsl_cdf.h
>
> +(export 'cauchy)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'cauchy)) &key a)
>   "gsl_ran_cauchy"
> diff --git a/random/chi-squared.lisp b/random/chi-squared.lisp
> index 4c0b2cc..6f2ed09 100644
> --- a/random/chi-squared.lisp
> +++ b/random/chi-squared.lisp
> @@ -23,6 +23,7 @@
>  ;;; /usr/include/gsl/gsl_randist.h
>  ;;; /usr/include/gsl/gsl_cdf.h
>
> +(export 'chi-squared)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'chi-squared)) &key nu)
>   "gsl_ran_chisq"
> diff --git a/random/dirichlet.lisp b/random/dirichlet.lisp
> index 17a7668..1618e48 100644
> --- a/random/dirichlet.lisp
> +++ b/random/dirichlet.lisp
> @@ -22,6 +22,7 @@
>
>  ;;; /usr/include/gsl/gsl_randist.h
>
> +(export 'dirichlet)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'dirichlet))
>      &key alpha (theta (vdf (dim0 alpha))))
> diff --git a/random/discrete.lisp b/random/discrete.lisp
> index c0bf6c0..c0dd53a 100644
> --- a/random/discrete.lisp
> +++ b/random/discrete.lisp
> @@ -35,6 +35,7 @@
>   generally as ``weights'')---the preprocessor will normalize appropriately.
>   This return value is used as an argument to #'discrete.")
>
> +(export 'discrete)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'discrete))
>      &key table)
> diff --git a/random/exponential-power.lisp b/random/exponential-power.lisp
> index bcc9eee..a5f4844 100644
> --- a/random/exponential-power.lisp
> +++ b/random/exponential-power.lisp
> @@ -22,6 +22,7 @@
>
>  ;;; /usr/include/gsl/gsl_randist.h
>
> +(export 'exponential-power)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'exponential-power))
>      &key a b)
> diff --git a/random/exponential.lisp b/random/exponential.lisp
> index 574a2af..940497f 100644
> --- a/random/exponential.lisp
> +++ b/random/exponential.lisp
> @@ -23,6 +23,7 @@
>  ;;; /usr/include/gsl/gsl_randist.h
>  ;;; /usr/include/gsl/gsl_cdf.h
>
> +(export 'exponential)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'exponential))
>      &key mu)
> diff --git a/random/fdist.lisp b/random/fdist.lisp
> index 9710abf..cfd22c2 100644
> --- a/random/fdist.lisp
> +++ b/random/fdist.lisp
> @@ -23,6 +23,7 @@
>  ;;; /usr/include/gsl/gsl_randist.h
>  ;;; /usr/include/gsl/gsl_cdf.h
>
> +(export 'fdist)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'fdist)) &key nu1 nu2)
>   "gsl_ran_fdist"
> diff --git a/random/flat.lisp b/random/flat.lisp
> index 5017d88..4841913 100644
> --- a/random/flat.lisp
> +++ b/random/flat.lisp
> @@ -22,6 +22,7 @@
>
>  ;;; /usr/include/gsl/gsl_randist.h
>
> +(export 'flat)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'flat)) &key a b)
>   "gsl_ran_flat"
> diff --git a/random/gamma.lisp b/random/gamma.lisp
> index 0327a04..d02a4c4 100644
> --- a/random/gamma.lisp
> +++ b/random/gamma.lisp
> @@ -23,6 +23,7 @@
>  ;;; /usr/include/gsl/gsl_randist.h
>  ;;; /usr/include/gsl/gsl_cdf.h
>
> +(export 'gamma)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'gamma)) &key a b)
>   "gsl_ran_gamma"
> @@ -37,6 +38,7 @@
>    is known as the Erlang distribution.  The variates are computed using
>    the algorithms from Knuth (vol 2).")
>
> +(export 'gamma-mt)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'gamma-mt)) &key a b)
>   "gsl_ran_gamma_mt"
> diff --git a/random/gaussian-bivariate.lisp b/random/gaussian-bivariate.lisp
> index b00bf77..2c72ecd 100644
> --- a/random/gaussian-bivariate.lisp
> +++ b/random/gaussian-bivariate.lisp
> @@ -23,6 +23,7 @@
>
>  ;;; /usr/include/gsl/gsl_randist.h
>
> +(export 'gaussian-bivariate)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'gaussian-bivariate))
>      &key sigma-x sigma-y rho)
> diff --git a/random/gaussian-tail.lisp b/random/gaussian-tail.lisp
> index e4881e5..f2b0817 100644
> --- a/random/gaussian-tail.lisp
> +++ b/random/gaussian-tail.lisp
> @@ -22,6 +22,7 @@
>
>  ;;; /usr/include/gsl/gsl_randist.h
>
> +(export 'gaussian-tail)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'gaussian-tail))
>      &key a sigma)
> @@ -50,6 +51,7 @@
>   for a Gaussian tail distribution with standard deviation sigma and
>   lower limit a, using the formula given for gaussian-tail.")
>
> +(export 'ugaussian-tail)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'ugaussian-tail))
>      &key a)
> diff --git a/random/gaussian.lisp b/random/gaussian.lisp
> index af4009d..d714a3d 100644
> --- a/random/gaussian.lisp
> +++ b/random/gaussian.lisp
> @@ -23,6 +23,7 @@
>  ;;; /usr/include/gsl/gsl_randist.h
>  ;;; /usr/include/gsl/gsl_cdf.h
>
> +(export 'gaussian)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'gaussian))
>      &key sigma)
> @@ -48,6 +49,7 @@
>   "Compute the probability density p(x) at x
>    for a Gaussian distribution with standard deviation sigma.")
>
> +(export 'gaussian-ziggurat)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'gaussian-ziggurat))
>      &key sigma)
> @@ -60,6 +62,7 @@
>    Marsaglia-Tsang ziggurat method. The Ziggurat algorithm
>    is the fastest available algorithm in most cases.")
>
> +(export 'gaussian-ratio-method)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'gaussian-ratio-method))
>      &key sigma)
> @@ -71,6 +74,7 @@
>   "Compute a Gaussian random variate using the Kinderman-Monahan-Leva
>    ratio method.")
>
> +(export 'ugaussian)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'ugaussian)) &key)
>   "gsl_ran_ugaussian" (((mpointer generator) :pointer))
> @@ -89,6 +93,7 @@
>    equivalent to the #'gaussian-pdf with a standard deviation of one,
>    sigma = 1.")
>
> +(export 'ugaussian-ratio-method)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql
> 'ugaussian-ratio-method))
>      &key)
> diff --git a/random/generators.lisp b/random/generators.lisp
> index d0177fb..5e2f968 100644
> --- a/random/generators.lisp
> +++ b/random/generators.lisp
> @@ -77,6 +77,7 @@
>   (:documentation
>    "Sample from the probability distribution."))
>
> +(export 'uniform)
>  (defmfun sample ((source random-number-generator) (type (eql 'uniform))
> &key)
>   "gsl_rng_uniform" (((mpointer source) :pointer))
>   :definition :method
> @@ -91,6 +92,7 @@
>    (the maximum number of bits that can be portably represented in a single
>    :ulong.")
>
> +(export 'uniform>0)
>  (defmfun sample ((source random-number-generator) (type (eql 'uniform>0))
> &key)
>   "gsl_rng_uniform_pos" (((mpointer source) :pointer))
>   :definition :method
> @@ -102,6 +104,7 @@
>    type 'uniform until a non-zero value is obtained.  You can use this
>    function if you need to avoid a singularity at 0.0.")
>
> +(export 'uniform-fixnum)
>  (defmfun sample
>     ((source random-number-generator) (type (eql 'uniform-fixnum))
>      &key upperbound)
> diff --git a/random/geometric.lisp b/random/geometric.lisp
> index 26ba486..e38106b 100644
> --- a/random/geometric.lisp
> +++ b/random/geometric.lisp
> @@ -22,6 +22,7 @@
>
>  ;;; /usr/include/gsl/gsl_randist.h
>
> +(export 'geometric)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'geometric))
>      &key probability)
> diff --git a/random/gumbel1.lisp b/random/gumbel1.lisp
> index 89b0ca0..fe33b90 100644
> --- a/random/gumbel1.lisp
> +++ b/random/gumbel1.lisp
> @@ -23,6 +23,7 @@
>  ;;; /usr/include/gsl/gsl_randist.h
>  ;;; /usr/include/gsl/gsl_cdf.h
>
> +(export 'geometric)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'gumbel1)) &key a b)
>   "gsl_ran_gumbel1"
> diff --git a/random/gumbel2.lisp b/random/gumbel2.lisp
> index 13eda47..ea69218 100644
> --- a/random/gumbel2.lisp
> +++ b/random/gumbel2.lisp
> @@ -23,6 +23,7 @@
>  ;;; /usr/include/gsl/gsl_randist.h
>  ;;; /usr/include/gsl/gsl_cdf.h
>
> +(export 'gumbel2)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'gumbel2)) &key a b)
>   "gsl_ran_gumbel2"
> diff --git a/random/hypergeometric.lisp b/random/hypergeometric.lisp
> index 0771c72..a307cea 100644
> --- a/random/hypergeometric.lisp
> +++ b/random/hypergeometric.lisp
> @@ -23,6 +23,7 @@
>  ;;; /usr/include/gsl/gsl_randist.h
>  ;;; /usr/include/gsl/gsl_cdf.h
>
> +(export 'hypergeometric)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'hypergeometric))
>      &key n1 n2 tt)
> diff --git a/random/landau.lisp b/random/landau.lisp
> index 635c4de..087775a 100644
> --- a/random/landau.lisp
> +++ b/random/landau.lisp
> @@ -22,6 +22,7 @@
>
>  ;;; /usr/include/gsl/gsl_randist.h
>
> +(export 'landau)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'landau)) &key)
>   "gsl_ran_landau"
> diff --git a/random/laplace.lisp b/random/laplace.lisp
> index e0089c9..a8d7d37 100644
> --- a/random/laplace.lisp
> +++ b/random/laplace.lisp
> @@ -23,6 +23,7 @@
>  ;;; /usr/include/gsl/gsl_randist.h
>  ;;; /usr/include/gsl/gsl_cdf.h
>
> +(export 'laplace)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'laplace)) &key a)
>   "gsl_ran_laplace"
> diff --git a/random/levy.lisp b/random/levy.lisp
> index df84970..9a9589b 100644
> --- a/random/levy.lisp
> +++ b/random/levy.lisp
> @@ -22,6 +22,7 @@
>
>  ;;; /usr/include/gsl/gsl_randist.h
>
> +(export 'levy)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'levy)) &key c alpha)
>   "gsl_ran_levy"
> @@ -40,6 +41,7 @@
>    For \alpha < 1 the tails of the distribution become extremely wide.
>    The algorithm only works for 0 < alpha <= 2.")
>
> +(export 'levy-skew)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'levy-skew))
>      &key c alpha beta)
> diff --git a/random/logarithmic.lisp b/random/logarithmic.lisp
> index dcdc3ff..d8999ef 100644
> --- a/random/logarithmic.lisp
> +++ b/random/logarithmic.lisp
> @@ -22,6 +22,7 @@
>
>  ;;; /usr/include/gsl/gsl_randist.h
>
> +(export 'logarithmic)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'logarithmic))
>      &key probability)
> diff --git a/random/logistic.lisp b/random/logistic.lisp
> index fed8882..b2ec5b5 100644
> --- a/random/logistic.lisp
> +++ b/random/logistic.lisp
> @@ -23,6 +23,7 @@
>  ;;; /usr/include/gsl/gsl_randist.h
>  ;;; /usr/include/gsl/gsl_cdf.h
>
> +(export 'logistic)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'logistic)) &key a)
>   "gsl_ran_logistic"
> diff --git a/random/lognormal.lisp b/random/lognormal.lisp
> index eeacb13..6594532 100644
> --- a/random/lognormal.lisp
> +++ b/random/lognormal.lisp
> @@ -20,6 +20,7 @@
>
>  (in-package :gsl)
>
> +(export 'lognormal)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'lognormal))
>      &key zeta sigma)
> diff --git a/random/multinomial.lisp b/random/multinomial.lisp
> index 5677767..24336b8 100644
> --- a/random/multinomial.lisp
> +++ b/random/multinomial.lisp
> @@ -22,6 +22,7 @@
>
>  ;;; /usr/include/gsl/gsl_randist.h
>
> +(export 'multinomial)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'multinomial))
>      &key sum probabilities
> diff --git a/random/negative-binomial.lisp b/random/negative-binomial.lisp
> index 4e7350a..bddcb66 100644
> --- a/random/negative-binomial.lisp
> +++ b/random/negative-binomial.lisp
> @@ -26,6 +26,7 @@
>  ;;;; Negative binomial
>  ;;;;****************************************************************************
>
> +(export 'negative-binomial)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'negative-binomial))
>      &key probability n)
> @@ -70,6 +71,7 @@
>  ;;;; Pascal
>  ;;;;****************************************************************************
>
> +(export 'pascal)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'pascal))
>      &key probability n)
> diff --git a/random/pareto.lisp b/random/pareto.lisp
> index e1753e2..d5dea2b 100644
> --- a/random/pareto.lisp
> +++ b/random/pareto.lisp
> @@ -23,6 +23,7 @@
>  ;;; /usr/include/gsl/gsl_randist.h
>  ;;; /usr/include/gsl/gsl_cdf.h
>
> +(export 'pareto)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'pareto)) &key a b)
>   "gsl_ran_pareto"
> diff --git a/random/poisson.lisp b/random/poisson.lisp
> index 3bb2f2d..36c512d 100644
> --- a/random/poisson.lisp
> +++ b/random/poisson.lisp
> @@ -23,6 +23,7 @@
>  ;;; /usr/include/gsl/gsl_randist.h
>  ;;; /usr/include/gsl/gsl_cdf.h
>
> +(export 'poisson)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'poisson)) &key mu)
>   "gsl_ran_poisson"
> diff --git a/random/rayleigh-tail.lisp b/random/rayleigh-tail.lisp
> index a848456..3416606 100644
> --- a/random/rayleigh-tail.lisp
> +++ b/random/rayleigh-tail.lisp
> @@ -22,6 +22,7 @@
>
>  ;;; /usr/include/gsl/gsl_randist.h
>
> +(export 'rayleigh-tail)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'rayleigh-tail))
>      &key a sigma)
> diff --git a/random/rayleigh.lisp b/random/rayleigh.lisp
> index 4855b22..e68fefa 100644
> --- a/random/rayleigh.lisp
> +++ b/random/rayleigh.lisp
> @@ -22,6 +22,7 @@
>
>  ;;; /usr/include/gsl/gsl_randist.h
>
> +(export 'rayleigh)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'rayleigh))
>      &key sigma)
> diff --git a/random/shuffling-sampling.lisp b/random/shuffling-sampling.lisp
> index 541e2ca..fc26b09 100644
> --- a/random/shuffling-sampling.lisp
> +++ b/random/shuffling-sampling.lisp
> @@ -22,6 +22,7 @@
>
>  ;;; These are currently defined only for vectors.
>
> +(export 'shuffle)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'shuffle))
>      &key base)
> @@ -40,6 +41,7 @@
>    permutations with equal probability, assuming a perfect source of random
>    numbers.")
>
> +(export 'choose-random)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'choose-random))
>      &key src (dest (dim0 src))
> @@ -68,6 +70,7 @@
>    same relative order as those in src.  You will need to call
>    with 'shuffle if you want to randomize the order.")
>
> +(export 'random-sample)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'random-sample))
>      &key src (dest (dim0 src))
> diff --git a/random/spherical-vector.lisp b/random/spherical-vector.lisp
> index c55ea86..0fa5533 100644
> --- a/random/spherical-vector.lisp
> +++ b/random/spherical-vector.lisp
> @@ -24,6 +24,7 @@
>
>  ;;; No test for #'direction-Nd yet.
>
> +(export 'direction-2d)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'direction-2d)) &key)
>   "gsl_ran_dir_2d"
> @@ -36,6 +37,7 @@
>    two dimensions.  The vector is normalized such that
>    |v|^2 = x^2 + y^2 = 1.")
>
> +(export 'direction-2d-trig-method)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql
> 'direction-2d-trig-method)) &key)
>   "gsl_ran_dir_2d_trig_method"
> @@ -48,6 +50,7 @@
>    two dimensions.  The vector is normalized such that
>    |v|^2 = x^2 + y^2 = 1.  Uses trigonometric functions.")
>
> +(export 'direction-3d)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'direction-3d)) &key)
>   "gsl_ran_dir_3d"
> @@ -64,6 +67,7 @@
>   projected along any axis is actually uniform (this is only true for 3
>   dimensions).")
>
> +(export 'direction-Nd)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'direction-Nd)) &key
> vector)
>   "gsl_ran_dir_nd"
> diff --git a/random/tdist.lisp b/random/tdist.lisp
> index aa530d5..804b731 100644
> --- a/random/tdist.lisp
> +++ b/random/tdist.lisp
> @@ -22,6 +22,7 @@
>
>  ;;; /usr/include/gsl/gsl_randist.h
>
> +(export 'tdist)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'tdist)) &key nu)
>   "gsl_ran_tdist"
> diff --git a/random/weibull.lisp b/random/weibull.lisp
> index ea00a79..82dce05 100644
> --- a/random/weibull.lisp
> +++ b/random/weibull.lisp
> @@ -23,6 +23,7 @@
>  ;;; /usr/include/gsl/gsl_randist.h
>  ;;; /usr/include/gsl/gsl_cdf.h
>
> +(export 'weibull)
>  (defmfun sample
>     ((generator random-number-generator) (type (eql 'weibull)) &key a b)
>   "gsl_ran_weibull"
>
> _______________________________________________
> Gsll-devel mailing list
> Gsll-devel at common-lisp.net
> http://common-lisp.net/cgi-bin/mailman/listinfo/gsll-devel
>
>




More information about the gsll-devel mailing list