annotate liboctave/numeric/oct-rand.h @ 23433:c9fab0bc983e

maint: Use convention 'int& x' for naming references. * ButtonGroup.cc, Canvas.cc, Canvas.h, annotation-dialog.cc, annotation-dialog.h, dialog.h, documentation-dock-widget.cc, files-dock-widget.cc, files-dock-widget.h, find-files-dialog.cc, find-files-dialog.h, find-files-model.cc, find-files-model.h, history-dock-widget.cc, history-dock-widget.h, file-editor-tab.cc, file-editor-tab.h, file-editor.cc, file-editor.h, main-window.cc, main-window.h, octave-qt-link.h, parser.cc, parser.h, webinfo.cc, webinfo.h, settings-dialog.cc, bsxfun.cc, call-stack.cc, call-stack.h, fft.cc, fft2.cc, fftn.cc, gl-render.cc, graphics.cc, graphics.in.h, input.cc, load-save.cc, ls-hdf5.cc, ls-hdf5.h, octave-link.h, pr-output.cc, regexp.cc, sparse-xdiv.cc, sparse-xdiv.h, symtab.cc, xdiv.cc, xdiv.h, zfstream.h, __eigs__.cc, __ode15__.cc, ov-base.h, ov-builtin.cc, ov-cx-sparse.h, ov-fcn-handle.cc, ov-fcn-handle.h, ov.cc, ov.h, jit-ir.h, jit-typeinfo.cc, jit-typeinfo.h, pt-jit.cc, pt-jit.h, CMatrix.cc, CMatrix.h, CSparse.cc, CSparse.h, MatrixType.cc, MatrixType.h, dDiagMatrix.cc, dMatrix.cc, dMatrix.h, dSparse.cc, dSparse.h, fCMatrix.cc, fCMatrix.h, fDiagMatrix.cc, fMatrix.cc, fMatrix.h, eigs-base.cc, oct-fftw.cc, oct-rand.h, sparse-dmsolve.cc, kpse.cc, lo-regexp.h: Use convention 'int& x' for naming references.
author Rik <rik@octave.org>
date Mon, 24 Apr 2017 17:20:37 -0700
parents 092078913d54
children d691ed308237
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4308
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
1 /*
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
2
23219
3ac9f9ecfae5 maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents: 23083
diff changeset
3 Copyright (C) 2003-2017 John W. Eaton
4308
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
4
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
6
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
8 under the terms of the GNU General Public License as published by
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
9 the Free Software Foundation; either version 3 of the License, or
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
10 (at your option) any later version.
4308
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
11
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
12 Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
13 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
15 GNU General Public License for more details.
4308
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
16
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6108
diff changeset
18 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6108
diff changeset
19 <http://www.gnu.org/licenses/>.
4308
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
20
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
21 */
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
22
20791
f7084eae3318 maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents: 19697
diff changeset
23 #if ! defined (octave_oct_rand_h)
17822
ebb3ef964372 maint: Use common #define syntax "octave_filename_h" in h_files.
Rik <rik@octave.org>
parents: 17769
diff changeset
24 #define octave_oct_rand_h 1
4308
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
25
21244
1473547f50f5 include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents: 21017
diff changeset
26 #include "octave-config.h"
1473547f50f5 include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents: 21017
diff changeset
27
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
28 #include <map>
4308
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
29 #include <string>
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
30
5730
109fdf7b3dcb [project @ 2006-04-03 19:18:26 by jwe]
jwe
parents: 5307
diff changeset
31 #include "dColVector.h"
4543
79df15d4470c [project @ 2003-10-18 03:53:52 by jwe]
jwe
parents: 4308
diff changeset
32 #include "dNDArray.h"
14655
43db83eff9db Implement single precision rand, randn, rande, randg and randp generators (bug #34351, #36293)
David Bateman <dbateman@free.fr>
parents: 14138
diff changeset
33 #include "fNDArray.h"
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
34 #include "lo-ieee.h"
4308
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
35
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
36 class
6108
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5730
diff changeset
37 OCTAVE_API
4308
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
38 octave_rand
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
39 {
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
40 protected:
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
41
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
42 octave_rand (void);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
43
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
44 public:
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
45
22868
87e3163f6c87 use c++11 "= default" syntax for declaration of trivial destructors
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
46 ~octave_rand (void) = default;
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
47
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
48 static bool instance_ok (void);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
49
4308
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
50 // Return the current seed.
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
51 static double seed (void)
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
52 {
22402
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22323
diff changeset
53 return instance_ok () ? instance->do_seed ()
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22323
diff changeset
54 : octave::numeric_limits<double>::NaN ();
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
55 }
4308
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
56
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
57 // Set the seed.
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
58 static void seed (double s)
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
59 {
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
60 if (instance_ok ())
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
61 instance->do_seed (s);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
62 }
4308
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
63
10709
92a85ed5b86e Don't special case color_property type when emitting factory default (bug #30118)
David Bateman <dbateman@free.fr>
parents: 10312
diff changeset
64 // Reset the seed.
92a85ed5b86e Don't special case color_property type when emitting factory default (bug #30118)
David Bateman <dbateman@free.fr>
parents: 10312
diff changeset
65 static void reset (void)
92a85ed5b86e Don't special case color_property type when emitting factory default (bug #30118)
David Bateman <dbateman@free.fr>
parents: 10312
diff changeset
66 {
92a85ed5b86e Don't special case color_property type when emitting factory default (bug #30118)
David Bateman <dbateman@free.fr>
parents: 10312
diff changeset
67 if (instance_ok ())
92a85ed5b86e Don't special case color_property type when emitting factory default (bug #30118)
David Bateman <dbateman@free.fr>
parents: 10312
diff changeset
68 instance->do_reset ();
92a85ed5b86e Don't special case color_property type when emitting factory default (bug #30118)
David Bateman <dbateman@free.fr>
parents: 10312
diff changeset
69 }
92a85ed5b86e Don't special case color_property type when emitting factory default (bug #30118)
David Bateman <dbateman@free.fr>
parents: 10312
diff changeset
70
5730
109fdf7b3dcb [project @ 2006-04-03 19:18:26 by jwe]
jwe
parents: 5307
diff changeset
71 // Return the current state.
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20791
diff changeset
72 static ColumnVector state (const std::string& d = "")
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
73 {
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
74 return instance_ok () ? instance->do_state (d) : ColumnVector ();
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
75 }
5730
109fdf7b3dcb [project @ 2006-04-03 19:18:26 by jwe]
jwe
parents: 5307
diff changeset
76
109fdf7b3dcb [project @ 2006-04-03 19:18:26 by jwe]
jwe
parents: 5307
diff changeset
77 // Set the current state/
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
78 static void state (const ColumnVector& s,
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20791
diff changeset
79 const std::string& d = "")
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
80 {
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
81 if (instance_ok ())
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
82 instance->do_state (s, d);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
83 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
84
10709
92a85ed5b86e Don't special case color_property type when emitting factory default (bug #30118)
David Bateman <dbateman@free.fr>
parents: 10312
diff changeset
85 // Reset the current state/
92a85ed5b86e Don't special case color_property type when emitting factory default (bug #30118)
David Bateman <dbateman@free.fr>
parents: 10312
diff changeset
86 static void reset (const std::string& d)
92a85ed5b86e Don't special case color_property type when emitting factory default (bug #30118)
David Bateman <dbateman@free.fr>
parents: 10312
diff changeset
87 {
92a85ed5b86e Don't special case color_property type when emitting factory default (bug #30118)
David Bateman <dbateman@free.fr>
parents: 10312
diff changeset
88 if (instance_ok ())
92a85ed5b86e Don't special case color_property type when emitting factory default (bug #30118)
David Bateman <dbateman@free.fr>
parents: 10312
diff changeset
89 instance->do_reset (d);
92a85ed5b86e Don't special case color_property type when emitting factory default (bug #30118)
David Bateman <dbateman@free.fr>
parents: 10312
diff changeset
90 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
91
4308
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
92 // Return the current distribution.
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
93 static std::string distribution (void)
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
94 {
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20791
diff changeset
95 return instance_ok () ? instance->do_distribution () : "";
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
96 }
4308
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
97
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
98 // Set the current distribution. May be either "uniform" (the
7533
ff52243af934 save state separately for each MT random number generator
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
99 // default), "normal", "exponential", "poisson", or "gamma".
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
100 static void distribution (const std::string& d)
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
101 {
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
102 if (instance_ok ())
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
103 instance->do_distribution (d);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
104 }
4308
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
105
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
106 static void uniform_distribution (void)
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
107 {
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
108 if (instance_ok ())
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
109 instance->do_uniform_distribution ();
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
110 }
4308
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
111
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
112 static void normal_distribution (void)
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
113 {
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
114 if (instance_ok ())
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
115 instance->do_normal_distribution ();
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
116 }
4308
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
117
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
118 static void exponential_distribution (void)
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
119 {
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
120 if (instance_ok ())
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
121 instance->do_exponential_distribution ();
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
122 }
5730
109fdf7b3dcb [project @ 2006-04-03 19:18:26 by jwe]
jwe
parents: 5307
diff changeset
123
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
124 static void poisson_distribution (void)
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
125 {
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
126 if (instance_ok ())
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
127 instance->do_poisson_distribution ();
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
128 }
5730
109fdf7b3dcb [project @ 2006-04-03 19:18:26 by jwe]
jwe
parents: 5307
diff changeset
129
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
130 static void gamma_distribution (void)
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
131 {
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
132 if (instance_ok ())
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
133 instance->do_gamma_distribution ();
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
134 }
5730
109fdf7b3dcb [project @ 2006-04-03 19:18:26 by jwe]
jwe
parents: 5307
diff changeset
135
4308
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
136 // Return the next number from the sequence.
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
137 static double scalar (double a = 1.0)
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
138 {
22402
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22323
diff changeset
139 return instance_ok () ? instance->do_scalar (a)
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22323
diff changeset
140 : octave::numeric_limits<double>::NaN ();
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
141 }
4308
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
142
14655
43db83eff9db Implement single precision rand, randn, rande, randg and randp generators (bug #34351, #36293)
David Bateman <dbateman@free.fr>
parents: 14138
diff changeset
143 // Return the next number from the sequence.
43db83eff9db Implement single precision rand, randn, rande, randg and randp generators (bug #34351, #36293)
David Bateman <dbateman@free.fr>
parents: 14138
diff changeset
144 static float float_scalar (float a = 1.0)
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
145 {
22402
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22323
diff changeset
146 return instance_ok () ? instance->do_float_scalar (a)
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22323
diff changeset
147 : octave::numeric_limits<float>::NaN ();
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
148 }
4308
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
149
14655
43db83eff9db Implement single precision rand, randn, rande, randg and randp generators (bug #34351, #36293)
David Bateman <dbateman@free.fr>
parents: 14138
diff changeset
150 // Return an array of numbers from the sequence.
43db83eff9db Implement single precision rand, randn, rande, randg and randp generators (bug #34351, #36293)
David Bateman <dbateman@free.fr>
parents: 14138
diff changeset
151 static Array<double> vector (octave_idx_type n, double a = 1.0)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
152 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
153 return instance_ok () ? instance->do_vector (n, a) : Array<double> ();
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
154 }
14655
43db83eff9db Implement single precision rand, randn, rande, randg and randp generators (bug #34351, #36293)
David Bateman <dbateman@free.fr>
parents: 14138
diff changeset
155
43db83eff9db Implement single precision rand, randn, rande, randg and randp generators (bug #34351, #36293)
David Bateman <dbateman@free.fr>
parents: 14138
diff changeset
156 // Return an array of numbers from the sequence.
43db83eff9db Implement single precision rand, randn, rande, randg and randp generators (bug #34351, #36293)
David Bateman <dbateman@free.fr>
parents: 14138
diff changeset
157 static Array<float> float_vector (octave_idx_type n, float a = 1.0)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
158 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
159 return instance_ok () ? instance->do_float_vector (n, a) : Array<float> ();
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
160 }
14655
43db83eff9db Implement single precision rand, randn, rande, randg and randp generators (bug #34351, #36293)
David Bateman <dbateman@free.fr>
parents: 14138
diff changeset
161
4543
79df15d4470c [project @ 2003-10-18 03:53:52 by jwe]
jwe
parents: 4308
diff changeset
162 // Return an N-dimensional array of numbers from the sequence,
79df15d4470c [project @ 2003-10-18 03:53:52 by jwe]
jwe
parents: 4308
diff changeset
163 // filled in column major order.
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
164 static NDArray nd_array (const dim_vector& dims, double a = 1.0)
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
165 {
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
166 return instance_ok () ? instance->do_nd_array (dims, a) : NDArray ();
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
167 }
4543
79df15d4470c [project @ 2003-10-18 03:53:52 by jwe]
jwe
parents: 4308
diff changeset
168
14655
43db83eff9db Implement single precision rand, randn, rande, randg and randp generators (bug #34351, #36293)
David Bateman <dbateman@free.fr>
parents: 14138
diff changeset
169 // Return an N-dimensional array of numbers from the sequence,
43db83eff9db Implement single precision rand, randn, rande, randg and randp generators (bug #34351, #36293)
David Bateman <dbateman@free.fr>
parents: 14138
diff changeset
170 // filled in column major order.
43db83eff9db Implement single precision rand, randn, rande, randg and randp generators (bug #34351, #36293)
David Bateman <dbateman@free.fr>
parents: 14138
diff changeset
171 static FloatNDArray float_nd_array (const dim_vector& dims, float a = 1.0)
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
172 {
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
173 return instance_ok () ? instance->do_float_nd_array (dims, a)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
174 : FloatNDArray ();
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
175 }
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
176
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
177 private:
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
178
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
179 static octave_rand *instance;
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
180
13983
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
181 static void cleanup_instance (void) { delete instance; instance = 0; }
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
182
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
183 enum
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
184 {
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
185 unknown_dist,
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
186 uniform_dist,
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
187 normal_dist,
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
188 expon_dist,
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
189 poisson_dist,
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
190 gamma_dist
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
191 };
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
192
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
193 // Current distribution of random numbers.
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
194 int current_distribution;
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
195
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
196 // If TRUE, use old RANLIB generators. Otherwise, use Mersenne
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
197 // Twister generator.
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
198 bool use_old_generators;
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
199
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
200 // Saved MT states.
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
201 std::map<int, ColumnVector> rand_states;
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
202
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
203 // Return the current seed.
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
204 double do_seed (void);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
205
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
206 // Set the seed.
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
207 void do_seed (double s);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
208
10709
92a85ed5b86e Don't special case color_property type when emitting factory default (bug #30118)
David Bateman <dbateman@free.fr>
parents: 10312
diff changeset
209 // Reset the seed.
92a85ed5b86e Don't special case color_property type when emitting factory default (bug #30118)
David Bateman <dbateman@free.fr>
parents: 10312
diff changeset
210 void do_reset ();
92a85ed5b86e Don't special case color_property type when emitting factory default (bug #30118)
David Bateman <dbateman@free.fr>
parents: 10312
diff changeset
211
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
212 // Return the current state.
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
213 ColumnVector do_state (const std::string& d);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
214
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
215 // Set the current state/
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
216 void do_state (const ColumnVector& s, const std::string& d);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
217
10709
92a85ed5b86e Don't special case color_property type when emitting factory default (bug #30118)
David Bateman <dbateman@free.fr>
parents: 10312
diff changeset
218 // Reset the current state/
92a85ed5b86e Don't special case color_property type when emitting factory default (bug #30118)
David Bateman <dbateman@free.fr>
parents: 10312
diff changeset
219 void do_reset (const std::string& d);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
220
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
221 // Return the current distribution.
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
222 std::string do_distribution (void);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
223
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
224 // Set the current distribution. May be either "uniform" (the
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
225 // default), "normal", "exponential", "poisson", or "gamma".
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
226 void do_distribution (const std::string& d);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
227
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
228 void do_uniform_distribution (void);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
229
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
230 void do_normal_distribution (void);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
231
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
232 void do_exponential_distribution (void);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
233
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
234 void do_poisson_distribution (void);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
235
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
236 void do_gamma_distribution (void);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
237
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
238 // Return the next number from the sequence.
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
239 double do_scalar (double a = 1.);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
240
14655
43db83eff9db Implement single precision rand, randn, rande, randg and randp generators (bug #34351, #36293)
David Bateman <dbateman@free.fr>
parents: 14138
diff changeset
241 // Return the next number from the sequence.
43db83eff9db Implement single precision rand, randn, rande, randg and randp generators (bug #34351, #36293)
David Bateman <dbateman@free.fr>
parents: 14138
diff changeset
242 float do_float_scalar (float a = 1.);
43db83eff9db Implement single precision rand, randn, rande, randg and randp generators (bug #34351, #36293)
David Bateman <dbateman@free.fr>
parents: 14138
diff changeset
243
43db83eff9db Implement single precision rand, randn, rande, randg and randp generators (bug #34351, #36293)
David Bateman <dbateman@free.fr>
parents: 14138
diff changeset
244 // Return an array of numbers from the sequence.
43db83eff9db Implement single precision rand, randn, rande, randg and randp generators (bug #34351, #36293)
David Bateman <dbateman@free.fr>
parents: 14138
diff changeset
245 Array<double> do_vector (octave_idx_type n, double a = 1.);
43db83eff9db Implement single precision rand, randn, rande, randg and randp generators (bug #34351, #36293)
David Bateman <dbateman@free.fr>
parents: 14138
diff changeset
246
43db83eff9db Implement single precision rand, randn, rande, randg and randp generators (bug #34351, #36293)
David Bateman <dbateman@free.fr>
parents: 14138
diff changeset
247 // Return an array of numbers from the sequence.
43db83eff9db Implement single precision rand, randn, rande, randg and randp generators (bug #34351, #36293)
David Bateman <dbateman@free.fr>
parents: 14138
diff changeset
248 Array<float> do_float_vector (octave_idx_type n, float a = 1.);
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
249
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
250 // Return an N-dimensional array of numbers from the sequence,
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
251 // filled in column major order.
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
252 NDArray do_nd_array (const dim_vector& dims, double a = 1.);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
253
14655
43db83eff9db Implement single precision rand, randn, rande, randg and randp generators (bug #34351, #36293)
David Bateman <dbateman@free.fr>
parents: 14138
diff changeset
254 // Return an N-dimensional array of numbers from the sequence,
43db83eff9db Implement single precision rand, randn, rande, randg and randp generators (bug #34351, #36293)
David Bateman <dbateman@free.fr>
parents: 14138
diff changeset
255 // filled in column major order.
43db83eff9db Implement single precision rand, randn, rande, randg and randp generators (bug #34351, #36293)
David Bateman <dbateman@free.fr>
parents: 14138
diff changeset
256 FloatNDArray do_float_nd_array (const dim_vector& dims, float a = 1.);
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
257
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
258 // Some helper functions.
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
259
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
260 void initialize_ranlib_generators (void);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
261
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
262 void initialize_mersenne_twister (void);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
263
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
264 ColumnVector get_internal_state (void);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
265
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
266 void save_state (void);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
267
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
268 int get_dist_id (const std::string& d);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
269
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
270 void set_internal_state (const ColumnVector& s);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
271
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
272 void switch_to_generator (int dist);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
273
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
274 void fill (octave_idx_type len, double *v, double a);
14655
43db83eff9db Implement single precision rand, randn, rande, randg and randp generators (bug #34351, #36293)
David Bateman <dbateman@free.fr>
parents: 14138
diff changeset
275
43db83eff9db Implement single precision rand, randn, rande, randg and randp generators (bug #34351, #36293)
David Bateman <dbateman@free.fr>
parents: 14138
diff changeset
276 void fill (octave_idx_type len, float *v, float a);
4308
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
277 };
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
278
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
279 #endif