GNU Octave  6.2.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
octave::rand Class Reference

#include "oct-rand.h"

Collaboration diagram for octave::rand:

Public Member Functions

 ~rand (void)=default
 

Static Public Member Functions

static void distribution (const std::string &d)
 
static std::string distribution (void)
 
static void exponential_distribution (void)
 
static FloatNDArray float_nd_array (const dim_vector &dims, float a=1.0)
 
static float float_scalar (float a=1.0)
 
static Array< float > float_vector (octave_idx_type n, float a=1.0)
 
static void gamma_distribution (void)
 
static bool instance_ok (void)
 
static NDArray nd_array (const dim_vector &dims, double a=1.0)
 
static void normal_distribution (void)
 
static void poisson_distribution (void)
 
static void reset (const std::string &d)
 
static void reset (void)
 
static double scalar (double a=1.0)
 
static void seed (double s)
 
static double seed (void)
 
static uint32NDArray state (const std::string &d="")
 
static void state (const uint32NDArray &s, const std::string &d="")
 
static void uniform_distribution (void)
 
static Array< double > vector (octave_idx_type n, double a=1.0)
 

Protected Member Functions

 rand (void)
 

Private Types

enum  {
  unknown_dist , uniform_dist , normal_dist , expon_dist ,
  poisson_dist , gamma_dist
}
 

Private Member Functions

void do_distribution (const std::string &d)
 
std::string do_distribution (void)
 
void do_exponential_distribution (void)
 
FloatNDArray do_float_nd_array (const dim_vector &dims, float a=1.)
 
void do_gamma_distribution (void)
 
NDArray do_nd_array (const dim_vector &dims, double a=1.)
 
void do_normal_distribution (void)
 
void do_poisson_distribution (void)
 
void do_reset ()
 
void do_reset (const std::string &d)
 
template<typename T >
do_scalar (T a=1)
 
void do_seed (double s)
 
double do_seed (void)
 
uint32NDArray do_state (const std::string &d)
 
void do_state (const uint32NDArray &s, const std::string &d)
 
void do_uniform_distribution (void)
 
template<typename T >
Array< T > do_vector (octave_idx_type n, T a=1)
 
template<>
double exponential (void)
 
template<>
float exponential (void)
 
template<typename T >
exponential (void)
 
void fill (octave_idx_type len, double *v, double a)
 
void fill (octave_idx_type len, float *v, float a)
 
template<>
double gamma (double a)
 
template<>
float gamma (float a)
 
template<typename T >
gamma (T a)
 
int get_dist_id (const std::string &d)
 
uint32NDArray get_internal_state (void)
 
void initialize_mersenne_twister (void)
 
void initialize_ranlib_generators (void)
 
template<>
double normal (void)
 
template<>
float normal (void)
 
template<typename T >
normal (void)
 
template<>
double poisson (double a)
 
template<>
float poisson (float a)
 
template<typename T >
poisson (T a)
 
void save_state (void)
 
void set_internal_state (const uint32NDArray &s)
 
void switch_to_generator (int dist)
 
template<>
double uniform (void)
 
template<>
float uniform (void)
 
template<typename T >
uniform (void)
 

Static Private Member Functions

static void cleanup_instance (void)
 

Private Attributes

int current_distribution
 
std::map< int, uint32NDArrayrand_states
 
bool use_old_generators
 

Static Private Attributes

static randinstance = nullptr
 

Detailed Description

Definition at line 44 of file oct-rand.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private
Enumerator
unknown_dist 
uniform_dist 
normal_dist 
expon_dist 
poisson_dist 
gamma_dist 

Definition at line 189 of file oct-rand.h.

Constructor & Destructor Documentation

◆ rand()

octave::rand::rand ( void  )
protected

Definition at line 53 of file oct-rand.cc.

References initialize_mersenne_twister(), and initialize_ranlib_generators().

Referenced by instance_ok().

◆ ~rand()

octave::rand::~rand ( void  )
default

Member Function Documentation

◆ cleanup_instance()

static void octave::rand::cleanup_instance ( void  )
inlinestaticprivate

Definition at line 187 of file oct-rand.h.

Referenced by instance_ok().

◆ distribution() [1/2]

static void octave::rand::distribution ( const std::string &  d)
inlinestatic

Definition at line 106 of file oct-rand.h.

References d.

◆ distribution() [2/2]

◆ do_distribution() [1/2]

void octave::rand::do_distribution ( const std::string &  d)
private

◆ do_distribution() [2/2]

std::string octave::rand::do_distribution ( void  )
private

◆ do_exponential_distribution()

void octave::rand::do_exponential_distribution ( void  )
private

Definition at line 272 of file oct-rand.cc.

References expon_dist, F77_FUNC(), and switch_to_generator().

◆ do_float_nd_array()

FloatNDArray octave::rand::do_float_nd_array ( const dim_vector dims,
float  a = 1. 
)
private

◆ do_gamma_distribution()

void octave::rand::do_gamma_distribution ( void  )
private

Definition at line 286 of file oct-rand.cc.

References F77_FUNC(), gamma_dist, and switch_to_generator().

◆ do_nd_array()

NDArray octave::rand::do_nd_array ( const dim_vector dims,
double  a = 1. 
)
private

◆ do_normal_distribution()

void octave::rand::do_normal_distribution ( void  )
private

Definition at line 265 of file oct-rand.cc.

References F77_FUNC(), normal_dist, and switch_to_generator().

◆ do_poisson_distribution()

void octave::rand::do_poisson_distribution ( void  )
private

Definition at line 279 of file oct-rand.cc.

References F77_FUNC(), poisson_dist, and switch_to_generator().

◆ do_reset() [1/2]

void octave::rand::do_reset ( void  )
private

Definition at line 138 of file oct-rand.cc.

References initialize_ranlib_generators(), and use_old_generators.

◆ do_reset() [2/2]

void octave::rand::do_reset ( const std::string &  d)
private

◆ do_scalar()

template<typename T >
template float octave::rand::do_scalar< float > ( a = 1)
private

◆ do_seed() [1/2]

void octave::rand::do_seed ( double  s)
private

◆ do_seed() [2/2]

double octave::rand::do_seed ( void  )
private

◆ do_state() [1/2]

uint32NDArray octave::rand::do_state ( const std::string &  d)
private

Definition at line 144 of file oct-rand.cc.

References current_distribution, d, get_dist_id(), and rand_states.

◆ do_state() [2/2]

void octave::rand::do_state ( const uint32NDArray s,
const std::string &  d 
)
private

◆ do_uniform_distribution()

void octave::rand::do_uniform_distribution ( void  )
private

Definition at line 258 of file oct-rand.cc.

References F77_FUNC(), switch_to_generator(), and uniform_dist.

◆ do_vector()

template<typename T >
template Array< float > octave::rand::do_vector< float > ( octave_idx_type  n,
a = 1 
)
private

◆ exponential() [1/3]

template<>
double octave::rand::exponential ( void  )
private

◆ exponential() [2/3]

template<>
float octave::rand::exponential ( void  )
private

◆ exponential() [3/3]

template<typename T >
T octave::rand::exponential ( void  )
private

◆ exponential_distribution()

static void octave::rand::exponential_distribution ( void  )
inlinestatic

Definition at line 124 of file oct-rand.h.

Referenced by do_distribution(), and do_rand().

◆ fill() [1/2]

◆ fill() [2/2]

◆ float_nd_array()

static FloatNDArray octave::rand::float_nd_array ( const dim_vector dims,
float  a = 1.0 
)
inlinestatic

Definition at line 177 of file oct-rand.h.

Referenced by do_rand().

◆ float_scalar()

static float octave::rand::float_scalar ( float  a = 1.0)
inlinestatic

Definition at line 150 of file oct-rand.h.

References NaN.

Referenced by do_rand().

◆ float_vector()

static Array<float> octave::rand::float_vector ( octave_idx_type  n,
float  a = 1.0 
)
inlinestatic

Definition at line 163 of file oct-rand.h.

References Array< float >, and n.

◆ gamma() [1/3]

template<>
double octave::rand::gamma ( double  a)
private

Definition at line 355 of file oct-rand.cc.

References dgengam(), F77_FUNC(), octave::math::isfinite(), NaN, retval, and use_old_generators.

◆ gamma() [2/3]

template<>
float octave::rand::gamma ( float  a)
private

Definition at line 437 of file oct-rand.cc.

References F77_FUNC(), fgengam(), octave::math::isfinite(), NaN, retval, and use_old_generators.

◆ gamma() [3/3]

template<typename T >
T octave::rand::gamma ( a)
private

◆ gamma_distribution()

static void octave::rand::gamma_distribution ( void  )
inlinestatic

Definition at line 136 of file oct-rand.h.

Referenced by do_distribution(), and do_rand().

◆ get_dist_id()

int octave::rand::get_dist_id ( const std::string &  d)
private

◆ get_internal_state()

uint32NDArray octave::rand::get_internal_state ( void  )
private

◆ initialize_mersenne_twister()

void octave::rand::initialize_mersenne_twister ( void  )
private

◆ initialize_ranlib_generators()

void octave::rand::initialize_ranlib_generators ( void  )
private

◆ instance_ok()

bool octave::rand::instance_ok ( void  )
static

Definition at line 62 of file oct-rand.cc.

References rand(), singleton_cleanup_list::add(), cleanup_instance(), instance, and retval.

◆ nd_array()

static NDArray octave::rand::nd_array ( const dim_vector dims,
double  a = 1.0 
)
inlinestatic

Definition at line 170 of file oct-rand.h.

Referenced by do_rand(), and Frandperm().

◆ normal() [1/3]

template<>
double octave::rand::normal ( void  )
private

◆ normal() [2/3]

template<>
float octave::rand::normal ( void  )
private

◆ normal() [3/3]

template<typename T >
T octave::rand::normal ( void  )
private

◆ normal_distribution()

static void octave::rand::normal_distribution ( void  )
inlinestatic

Definition at line 118 of file oct-rand.h.

Referenced by do_distribution(), and do_rand().

◆ poisson() [1/3]

template<>
double octave::rand::poisson ( double  a)
private

◆ poisson() [2/3]

template<>
float octave::rand::poisson ( float  a)
private

◆ poisson() [3/3]

template<typename T >
T octave::rand::poisson ( a)
private

◆ poisson_distribution()

static void octave::rand::poisson_distribution ( void  )
inlinestatic

Definition at line 130 of file oct-rand.h.

Referenced by do_distribution(), and do_rand().

◆ reset() [1/2]

static void octave::rand::reset ( const std::string &  d)
inlinestatic

Definition at line 92 of file oct-rand.h.

References d.

◆ reset() [2/2]

static void octave::rand::reset ( void  )
inlinestatic

Definition at line 71 of file oct-rand.h.

Referenced by do_rand().

◆ save_state()

void octave::rand::save_state ( void  )
private

Definition at line 608 of file oct-rand.cc.

References current_distribution, get_internal_state(), and rand_states.

Referenced by do_scalar(), and fill().

◆ scalar()

static double octave::rand::scalar ( double  a = 1.0)
inlinestatic

Definition at line 143 of file oct-rand.h.

References NaN.

Referenced by do_rand().

◆ seed() [1/2]

static void octave::rand::seed ( double  s)
inlinestatic

Definition at line 64 of file oct-rand.h.

◆ seed() [2/2]

static double octave::rand::seed ( void  )
inlinestatic

Definition at line 57 of file oct-rand.h.

References NaN.

Referenced by do_rand().

◆ set_internal_state()

void octave::rand::set_internal_state ( const uint32NDArray s)
private

◆ state() [1/2]

static uint32NDArray octave::rand::state ( const std::string &  d = "")
inlinestatic

Definition at line 78 of file oct-rand.h.

References d.

Referenced by do_rand().

◆ state() [2/2]

static void octave::rand::state ( const uint32NDArray s,
const std::string &  d = "" 
)
inlinestatic

Definition at line 84 of file oct-rand.h.

References d.

◆ switch_to_generator()

void octave::rand::switch_to_generator ( int  dist)
private

◆ uniform() [1/3]

template<>
double octave::rand::uniform ( void  )
private

◆ uniform() [2/3]

template<>
float octave::rand::uniform ( void  )
private

◆ uniform() [3/3]

template<typename T >
T octave::rand::uniform ( void  )
private

◆ uniform_distribution()

static void octave::rand::uniform_distribution ( void  )
inlinestatic

Definition at line 112 of file oct-rand.h.

Referenced by do_distribution(), and do_rand().

◆ vector()

Member Data Documentation

◆ current_distribution

int octave::rand::current_distribution
private

◆ instance

rand * octave::rand::instance = nullptr
staticprivate

Definition at line 185 of file oct-rand.h.

Referenced by instance_ok().

◆ rand_states

std::map<int, uint32NDArray> octave::rand::rand_states
private

◆ use_old_generators

bool octave::rand::use_old_generators
private

The documentation for this class was generated from the following files: