Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion doc/source/gsl-rng.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Random generator base class

.. code-block:: dylan

let r1 = make(<gsl-rng>, type: $gsl-rng-cmrg>, seed: 123456);
let r1 = make(<gsl-rng>, type: $gsl-rng-cmrg, seed: 123456);
let r2 = make(<gsl-rng>, seed: 123456);
let r3 = make(<gsl-rng>);

Expand All @@ -116,6 +116,8 @@ Random generator base class

- :func:`gsl-rng-uniform-integer`

- :meth:`gsl-rng-seed(<gsl-rng>)`

- :func:`gsl-rng-name`

- :func:`gsl-rng-min`
Expand Down Expand Up @@ -262,6 +264,31 @@ Auxiliary functions
format-out("%s", r.gsl-rng-name);
// rand

.. method:: gsl-rng-seed
:specializer: <gsl-rng>

Returns the seed of the random number generator

:signature:

gsl-rng-seed (rng) => (seed)

:parameter rng:

An instance of :class:`<gsl-rng>`

:values seed:

An instance of :drm:`<integer>`

:example:

.. code-block:: dylan

let r = make(<gsl-rng>, seed: 1234);
format-out("Seed: %d\n", r.gsl-rng-seed);
// Seed: 1234

.. function:: gsl-rng-min

Returns the smallest value returned by the random number
Expand Down
5 changes: 3 additions & 2 deletions src/lib/ffi/ffi-modules.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,9 @@ end module gsl-ffi-vector-impl;

define module gsl-ffi-rng
create
<gsl-rng-type*>,
<gsl-rng-type*>;

create
<gsl-rng-type**>,
gsl-rng-types-setup,
gsl-rng-env-setup,
Expand All @@ -590,7 +592,6 @@ define module gsl-ffi-rng
gsl-rng-uniform,
gsl-rng-uniform-int,
gsl-rng-uniform-pos;

end module gsl-ffi-rng;

define module gsl-ffi-rng-impl
Expand Down
93 changes: 28 additions & 65 deletions src/lib/gsl/gsl-modules.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,17 @@ Copyright: Copyright (C) 2026, Dylan Hackers. All rights reserved.
License: See License.txt in this distribution for details.

define module gsl-error

use gsl-ffi-error,
export: all;

end module gsl-error;
end module;

define module gsl-error-impl

use common-dylan;
use gsl-ffi-error;
use gsl-error;

end module gsl-error-impl;
end module;

define module gsl-common

create
<double-float?>,
<vector-double-float>,
Expand All @@ -30,23 +25,18 @@ define module gsl-common

create
with-c-double-array;

end module gsl-common;
end module;

define module gsl-common-impl

use common-dylan;
use c-ffi;
use gsl-common;

end module gsl-common-impl;
end module;

define module gsl-math

use gsl-ffi-math,
export: all;


// double float comparison

create
Expand All @@ -61,16 +51,14 @@ define module gsl-math
infinity?,
positive-infinity?,
negative-infinity?;

end module gsl-math;
end module;

define module gsl-math-impl
use common-dylan;
use c-ffi;
use gsl-ffi-math;

use gsl-math;
end module gsl-math-impl;
end module;

define module gsl-complex
create
Expand Down Expand Up @@ -159,23 +147,19 @@ define module gsl-complex
gsl-complex-arcsech,
gsl-complex-arccsch,
gsl-complex-arccoth;

end module gsl-complex;
end module;

define module gsl-complex-impl

use common-dylan;
use c-ffi;
use finalization;
use gsl-ffi-complex,
prefix: "ffi/";
use gsl-complex;

end module gsl-complex-impl;
end module;

define module gsl-vector

create
create
<gsl-vector>,
gsl-vector,
gsl-vector-copy,
Expand Down Expand Up @@ -203,28 +187,25 @@ define module gsl-vector
create
null?,
non-negative?;

end module gsl-vector;
end module;

define module gsl-vector-impl
use common-dylan;
use c-ffi;
use finalization;
use gsl-math,
import: { *epsilon*,
f= };
import: { *epsilon*, f= };
use gsl-ffi-vector,
prefix: "ffi/";

use gsl-vector;

export
%gsl-vector,
%gsl-vector-data,
%gsl-vector-data-setter;
end module gsl-vector-impl;
end module;

define module gsl-statistics

create
mean,
variance,
Expand Down Expand Up @@ -261,44 +242,28 @@ define module gsl-statistics
sn,
qn0,
qn;

end module gsl-statistics;
end module;

define module gsl-statistics-impl

use common-dylan;
use c-ffi;

use gsl-common,
import: { <double-float?>,
<vector-double-float>,
with-c-double-array };

import: { <double-float?>, <vector-double-float>, with-c-double-array };
use gsl-vector,
import: { <gsl-vector>,
gsl-vector-stride },
import: { <gsl-vector>, gsl-vector-stride },
rename: { min-index => vector-min-index,
max-index => vector-max-index,
max-index => vector-max-index,
minmax-index => vector-minmax-index };
use gsl-vector-impl,
import: { %gsl-vector,
%gsl-vector-data,
%gsl-vector-data-setter };

import: { %gsl-vector, %gsl-vector-data, %gsl-vector-data-setter };
use gsl-ffi-statistics;
use gsl-statistics;

end module;

define module gsl-running-statistics

create
<rstat>;

create
rstat-add!;

create
<rstat>,
rstat-add!,
rstat-reset!;

create
Expand All @@ -322,23 +287,18 @@ define module gsl-running-statistics
quantile-rstat-add!,
quantile-rstat-reset!,
quantile-rstat-get;

end module gsl-running-statistics;
end module;

define module gsl-running-statistics-impl

use common-dylan;
use c-ffi;
use gsl-common;

use gsl-ffi-running-statistics,
prefix: "ffi/";
use gsl-running-statistics;

end module gsl-running-statistics-impl;
end module;

define module gsl-rng

create
gsl-rng-env-setup;

Expand Down Expand Up @@ -418,14 +378,17 @@ define module gsl-rng
$gsl-rng-vax,
$gsl-rng-waterman14,
$gsl-rng-zuf;

end module;

define module gsl-rng-impl
use common-dylan;
use format-out;
use finalization;
use uncommon-utils;
use gsl-ffi-rng,
prefix: "ffi/";
use uncommon-utils;
use gsl-rng;
end module gsl-rng-impl;

export
gsl-rng-ffi;
end module;
42 changes: 18 additions & 24 deletions src/lib/gsl/rng.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -75,74 +75,68 @@ define constant <gsl-rng-type>
define constant $gsl-rng-types :: ffi/<gsl-rng-type**>
= ffi/gsl-rng-types-setup();

define function gsl-rng-env-setup
() => ()
ffi/gsl-rng-env-setup();
end;
define constant gsl-rng-env-setup
= ffi/gsl-rng-env-setup;

define class <gsl-rng> (<object>)
constant slot gsl-rng-seed :: <integer>,
init-keyword: seed:,
init-value: ffi/gsl-rng-default-seed();
slot %gsl-rng :: ffi/<gsl-rng*>;
slot gsl-rng-ffi :: ffi/<gsl-rng*>;
end;

define method initialize
(rng :: <gsl-rng>,
#key type :: false-or(<gsl-rng-type>) = #f)
(r :: <gsl-rng>, #key type :: false-or(<gsl-rng-type>) = #f)
=> ()
drain-finalization-queue();
next-method();

let rng-type :: ffi/<gsl-rng-type*>
= if (~type)
ffi/gsl-rng-default-type()
else
= if (type)
$gsl-rng-types[type]
else
ffi/gsl-rng-default-type()
end;

rng.%gsl-rng := ffi/gsl-rng-alloc(rng-type);

finalize-when-unreachable(rng);
r.gsl-rng-ffi := ffi/gsl-rng-alloc(rng-type);
ffi/gsl-rng-set(r.gsl-rng-ffi, r.gsl-rng-seed);
finalize-when-unreachable(r);
end;

define method finalize
(r :: <gsl-rng>) => ()
ffi/gsl-rng-free(r.%gsl-rng)
ffi/gsl-rng-free(r.gsl-rng-ffi)
end;

define function gsl-rng-name
(r :: <gsl-rng>) => (_ :: <string>)
ffi/gsl-rng-name(r.%gsl-rng)
ffi/gsl-rng-name(r.gsl-rng-ffi)
end;

define function gsl-rng-min
(r :: <gsl-rng>) => (_ :: <integer>)
ffi/gsl-rng-min(r.%gsl-rng)
ffi/gsl-rng-min(r.gsl-rng-ffi)
end;

define function gsl-rng-max
(r :: <gsl-rng>) => (_ :: <integer>)
ffi/gsl-rng-max(r.%gsl-rng)
ffi/gsl-rng-max(r.gsl-rng-ffi)
end;

define function gsl-rng-get
(r :: <gsl-rng>) => (_ :: <integer>)
ffi/gsl-rng-get(r.%gsl-rng)
ffi/gsl-rng-get(r.gsl-rng-ffi)
end;

define function gsl-rng-uniform
(r :: <gsl-rng>) => (_ :: <float>)
ffi/gsl-rng-uniform(r.%gsl-rng)
ffi/gsl-rng-uniform(r.gsl-rng-ffi)
end;

define function gsl-rng-uniform-positive
(r :: <gsl-rng>) => (_ :: <float>)
ffi/gsl-rng-uniform-pos(r.%gsl-rng)
ffi/gsl-rng-uniform-pos(r.gsl-rng-ffi)
end;

define function gsl-rng-uniform-int
(r :: <gsl-rng>, n :: <integer>) => (_ :: <integer>)
ffi/gsl-rng-uniform-int(r.%gsl-rng, n)
ffi/gsl-rng-uniform-int(r.gsl-rng-ffi, n)
end;

Loading
Loading