26 #if defined (HAVE_CONFIG_H)
77 union d2i {
double d; int32_t i[2]; };
99 assert (hi > lo && lo >= 0);
101 i = (i > 0 ? i : -i);
116 union d2i {
double d; int32_t i[2]; };
159 if (old_dist != new_dist)
166 if (old_dist != new_dist)
180 if (old_dist != new_dist)
186 if (old_dist != new_dist)
217 (*current_liboctave_error_handler)
252 (*current_liboctave_error_handler)
253 (
"rand: invalid distribution ID = %d", id);
294 double rand::uniform<double> (
void)
307 double rand::normal<double> (
void)
320 double rand::exponential<double> (
void)
333 double rand::poisson<double> (
double a)
355 double rand::gamma<double> (
double a)
367 retval = rand_gamma<double> (a);
373 float rand::uniform<float> (
void)
386 float rand::normal<float> (
void)
399 float rand::exponential<float> (
void)
412 float rand::poisson<float> (
float a)
437 float rand::gamma<float> (
float a)
449 retval = rand_gamma<float> (a);
454 template <
typename T>
470 retval = exponential<T> ();
482 (*current_liboctave_error_handler)
493 template double rand::do_scalar<double> (
double);
494 template float rand::do_scalar<float> (
float);
496 template <
typename T>
509 (*current_liboctave_error_handler) (
"rand: invalid negative argument");
556 int hour = tm.
hour () + 1;
557 int minute = tm.
min () + 1;
558 int second = tm.
sec () + 1;
560 int32_t s0 = tm.
mday () * hour * minute * second;
561 int32_t s1 = hour * minute * second;
567 F77_FUNC (setcgn, SETCGN) (stored_distribution);
617 if (
d ==
"uniform" ||
d ==
"rand")
619 else if (
d ==
"normal" ||
d ==
"randn")
621 else if (
d ==
"exponential" ||
d ==
"rande")
623 else if (
d ==
"poisson" ||
d ==
"randp")
625 else if (
d ==
"gamma" ||
d ==
"randg")
629 (
"rand: invalid distribution '%s'",
d.c_str ());
638 const uint32_t *sdata =
reinterpret_cast <const uint32_t *
> (s.
data ());
665 std::generate_n (v,
len, [](
void) {
double x;
F77_FUNC (
dgenunf, DGENUNF) (0.0, 1.0,
x);
return x; });
672 std::generate_n (v,
len, [](
void) {
double x;
F77_FUNC (
dgennor, DGENNOR) (0.0, 1.0,
x);
return x; });
707 std::generate_n (v,
len, [a](
void) {
double x;
F77_FUNC (
dgengam, DGENGAM) (1.0, a,
x);
return x; });
710 rand_gamma<double> (a,
len, v);
714 (*current_liboctave_error_handler)
733 std::generate_n (v,
len, [](
void) {
float x;
F77_FUNC (
fgenunf, FGENUNF) (0.0f, 1.0f,
x);
return x; });
740 std::generate_n (v,
len, [](
void) {
float x;
F77_FUNC (
fgennor, FGENNOR) (0.0f, 1.0f,
x);
return x; });
775 std::generate_n (v,
len, [a](
void) {
float x;
F77_FUNC (
fgengam, FGENGAM) (1.0f, a,
x);
return x; });
778 rand_gamma<float> (a,
len, v);
782 (*current_liboctave_error_handler)
N Dimensional Array with copy-on-write semantics.
octave_idx_type numel(void) const
Number of elements in the array.
const T * data(void) const
Size of the specified dimension.
const T * fortran_vec(void) const
Size of the specified dimension.
Vector representing the dimensions (size) of an Array.
bool all_zero(void) const
void do_normal_distribution(void)
int get_dist_id(const std::string &d)
void do_exponential_distribution(void)
void do_poisson_distribution(void)
std::map< int, uint32NDArray > rand_states
Array< T > do_vector(octave_idx_type n, T a=1)
static void cleanup_instance(void)
void fill(octave_idx_type len, double *v, double a)
static void normal_distribution(void)
void initialize_mersenne_twister(void)
uint32NDArray get_internal_state(void)
void set_internal_state(const uint32NDArray &s)
static void poisson_distribution(void)
void do_gamma_distribution(void)
uint32NDArray do_state(const std::string &d)
void switch_to_generator(int dist)
static void exponential_distribution(void)
FloatNDArray do_float_nd_array(const dim_vector &dims, float a=1.)
std::string do_distribution(void)
static void gamma_distribution(void)
void initialize_ranlib_generators(void)
static void uniform_distribution(void)
void do_uniform_distribution(void)
NDArray do_nd_array(const dim_vector &dims, double a=1.)
static bool instance_ok(void)
subroutine getsd(iseed1, iseed2)
OCTAVE_NORETURN liboctave_error_handler current_liboctave_error_handler
F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
F77_RET_T const F77_DBLE * x
float_format native_float_format(void)
@ flt_fmt_ieee_big_endian
static int32_t force_to_fit_range(int32_t i, int32_t lo, int32_t hi)
double rand_normal< double >(void)
void set_mersenne_twister_state(const uint32_t *save)
template void rand_poisson< float >(float, octave_idx_type, float *)
float rand_normal< float >(void)
template void rand_poisson< double >(double, octave_idx_type, double *)
double rand_exponential< double >(void)
float rand_exponential< float >(void)
void init_mersenne_twister(const uint32_t s)
float rand_uniform< float >(void)
void get_mersenne_twister_state(uint32_t *save)
double rand_uniform< double >(void)
octave_value::octave_value(const Array< char > &chm, char type) return retval
static std::string current_distribution
subroutine setall(iseed1, iseed2)
subroutine setsd(iseed1, iseed2)
subroutine fignpoi(mu, result)
subroutine fgennor(av, sd, result)
subroutine dgenunf(low, high, result)
subroutine fgenexp(av, result)
subroutine dgengam(a, r, result)
subroutine dgenexp(av, result)
subroutine fgengam(a, r, result)
subroutine fgenunf(low, high, result)
subroutine dgennor(av, sd, result)
subroutine dignpoi(mu, result)
F77_RET_T F77_FUNC(xerbla, XERBLA)(F77_CONST_CHAR_ARG_DEF(s_arg