File: gsl_rng.t

package info (click to toggle)
libpdl-gsl-perl 2.101-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 600 kB
  • sloc: perl: 1,587; ansic: 202; makefile: 9
file content (138 lines) | stat: -rw-r--r-- 3,113 bytes parent folder | download
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
# Test Script for the PDL interface to the GSL library
#  This tests only that the interface is working, i.e. that the
#   functions can be called. The actual return values are not
#   checked. 
#  The GSL library already has a extensive test suite, and we
#  do not want to duplicate that effort here.

use strict;
use warnings;
use Test::More;
use PDL::LiteF;
use PDL::GSL::RNG;

my $image = zeroes(10,10);
my $ndim = 2;
my $name = '';
my $sigma = 1;

# new() function Test: 
my $rng = PDL::GSL::RNG->new('taus');

pass('new() function');

# set_seed(); function Test: 
$rng->set_seed(666);

pass('set_seed(); function');

my $rng2 = PDL::GSL::RNG->new('taus')->set_seed(666);
is(ref $rng2, 'PDL::GSL::RNG', 'PDL::GSL::RNG->new(..)->set_seed(..)');

# min() function Test: 
my $min = $rng->min(); my $max = $rng->max();

pass('min() function');

# rmax() function Test: 
$min = $rng->min(); $max = $rng->max();

pass('rmax() function');

# name() function Test: 
$name = $rng->name();

pass('name() function');

# get_uniform() function Test: 
my $x = zeroes 5,6; $max=100;
my $o = $rng->get_uniform(10,10); $rng->get_uniform($x);

pass('get_uniform() function');

# get_uniform_pos() function Test: 
$x = zeroes 5,6;

$o = $rng->get_uniform_pos(10,10); $rng->get_uniform_pos($x);

pass('get_uniform_pos() function');

# get() function Test: 
$x = zeroes 5,6;

$o = $rng->get(10,10); $rng->get($x);

pass('get() function');

# get_int() function Test: 
$x = zeroes 5,6; $max=100;

$o = $rng->get(10,10); $rng->get($x);

pass('get_int() function');

# ran_gaussian() function Test: 
$o = $rng->ran_gaussian($sigma,10,10);

$rng->ran_gaussian($sigma,$x);


pass('ran_gaussian() function');

# $rng->ran_gaussian_var() function Test: 
my $sigma_pdl = rvals zeroes 11,11; $o = $rng->ran_gaussian_var($sigma_pdl);

pass('ran_gaussian_var() method');

# ran_additive_gaussian() function Test: 
$rng->ran_additive_gaussian(1,$image);

pass('ran_additive_gaussian() method');

# ran_additive_poisson() function Test: 
$rng->ran_additive_poisson(1,$image);

pass('ran_additive_poisson() method');

# ran_feed_poisson() function Test: 
$rng->ran_feed_poisson($image);

pass('ran_feed_poisson() method');

# ran_bivariate_gaussian() function Test: 
$o = $rng->ran_bivariate_gaussian(1,2,0.5,1000);

pass('ran_bivariate_gaussian() method');

# ran_dir() function Test: 
$o = $rng->ran_dir($ndim,12);

pass('ran_dir() method');

# ran_discrete_preproc() function Test: 
my $prob = pdl [0.1,0.3,0.6];

my $discrete_dist_handle = $rng->ran_discrete_preproc($prob);

$o = $rng->ran_discrete($discrete_dist_handle,100);

pass('ran_discrete_preproc() method');

# ran_discrete() function Test: 
$prob = pdl [0.1,0.3,0.6];

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

$o = $rng->ran_discrete($discrete_dist_handle,100);

pass('ran_discrete() method');

my $vec2d = sequence(10,10);
$rng->ran_shuffle($_) for $vec2d->dog;
ok any($vec2d != sequence(10,10)), 'ran_shuffle() method';

$vec2d = sequence(10,10);
$rng->ran_shuffle_1d($vec2d);
ok any($vec2d != sequence(10,10)), 'ran_shuffle_1d() method';

done_testing;