26 #if defined (HAVE_CONFIG_H)
54 : m_current_distribution (uniform_dist), m_use_old_generators (false),
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)
205 retval =
"exponential";
217 (*current_liboctave_error_handler)
252 (*current_liboctave_error_handler)
253 (
"rand: invalid distribution ID = %d", id);
367 retval = rand_gamma<double> (a);
449 retval = rand_gamma<float> (a);
454 template <
typename T>
462 retval = uniform<T> ();
466 retval = normal<T> ();
470 retval = exponential<T> ();
474 retval = poisson<T> (a);
478 retval = gamma<T> (a);
482 (*current_liboctave_error_handler)
493 template OCTAVE_API double rand::do_scalar<double> (
double);
494 template OCTAVE_API float rand::do_scalar<float> (
float);
496 template <
typename T>
509 (*current_liboctave_error_handler) (
"rand: invalid negative argument");
558 int hour = tm.hour () + 1;
559 int minute = tm.min () + 1;
560 int second = tm.sec () + 1;
562 int32_t s0 = tm.mday () * hour * minute * second;
563 int32_t s1 = hour * minute * second;
569 F77_FUNC (setcgn, SETCGN) (stored_distribution);
619 if (
d ==
"uniform" ||
d ==
"rand")
621 else if (
d ==
"normal" ||
d ==
"randn")
623 else if (
d ==
"exponential" ||
d ==
"rande")
625 else if (
d ==
"poisson" ||
d ==
"randp")
627 else if (
d ==
"gamma" ||
d ==
"randg")
631 (
"rand: invalid distribution '%s'",
d.c_str ());
640 const uint32_t *sdata =
reinterpret_cast <const uint32_t *
> (s.
data ());
667 std::generate_n (v,
len, [](
void) {
double x;
F77_FUNC (
dgenunf, DGENUNF) (0.0, 1.0,
x);
return x; });
674 std::generate_n (v,
len, [](
void) {
double x;
F77_FUNC (
dgennor, DGENNOR) (0.0, 1.0,
x);
return x; });
709 std::generate_n (v,
len, [a](
void) {
double x;
F77_FUNC (
dgengam, DGENGAM) (1.0, a,
x);
return x; });
712 rand_gamma<double> (a,
len, v);
716 (*current_liboctave_error_handler)
735 std::generate_n (v,
len, [](
void) {
float x;
F77_FUNC (
fgenunf, FGENUNF) (0.0f, 1.0f,
x);
return x; });
742 std::generate_n (v,
len, [](
void) {
float x;
F77_FUNC (
fgennor, FGENNOR) (0.0f, 1.0f,
x);
return x; });
777 std::generate_n (v,
len, [a](
void) {
float x;
F77_FUNC (
fgengam, FGENGAM) (1.0f, a,
x);
return x; });
780 rand_gamma<float> (a,
len, v);
784 (*current_liboctave_error_handler)
OCTARRAY_API void clear(void)
OCTARRAY_OVERRIDABLE_FUNC_API const T * data(void) const
Size of the specified dimension.
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type numel(void) const
Number of elements in the array.
OCTARRAY_API T * fortran_vec(void)
Size of the specified dimension.
Vector representing the dimensions (size) of an Array.
bool all_zero(void) const
static void gamma_distribution(void)
OCTAVE_API void do_gamma_distribution(void)
OCTAVE_API void do_poisson_distribution(void)
bool m_use_old_generators
OCTAVE_API NDArray do_nd_array(const dim_vector &dims, double a=1.)
OCTAVE_API void fill(octave_idx_type len, double *v, double a)
OCTAVE_API void set_internal_state(const uint32NDArray &s)
OCTAVE_API void do_uniform_distribution(void)
OCTAVE_API void save_state(void)
OCTAVE_API void do_exponential_distribution(void)
OCTAVE_API T do_scalar(T a=1)
OCTAVE_API Array< T > do_vector(octave_idx_type n, T a=1)
static void uniform_distribution(void)
OCTAVE_API void switch_to_generator(int dist)
OCTAVE_API uint32NDArray do_state(const std::string &d)
static void exponential_distribution(void)
OCTAVE_API FloatNDArray do_float_nd_array(const dim_vector &dims, float a=1.)
static bool instance_ok(void)
OCTAVE_API void do_reset()
OCTAVE_API void initialize_ranlib_generators(void)
OCTAVE_API std::string do_distribution(void)
OCTAVE_API uint32NDArray get_internal_state(void)
OCTAVE_API int get_dist_id(const std::string &d)
OCTAVE_API void initialize_mersenne_twister(void)
std::map< int, uint32NDArray > m_rand_states
static void cleanup_instance(void)
OCTAVE_API void do_normal_distribution(void)
static void poisson_distribution(void)
static void normal_distribution(void)
int m_current_distribution
OCTAVE_API double do_seed(void)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
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)
void get_mersenne_twister_state(uint32_t *save)
void set_mersenne_twister_state(const uint32_t *save)
OCTAVE_API double rand_uniform< double >(void)
void init_mersenne_twister(const uint32_t s)
OCTAVE_API float rand_exponential< float >(void)
OCTAVE_API float rand_normal< float >(void)
OCTAVE_API float rand_uniform< float >(void)
OCTAVE_API double rand_normal< double >(void)
OCTAVE_API double rand_exponential< double >(void)
template void rand_poisson< double >(double, octave_idx_type, double *)
template void rand_poisson< float >(float, octave_idx_type, float *)
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