25 #if defined (HAVE_CONFIG_H)
30 #include <unordered_map>
54 const std::string& distribution,
bool additional_arg =
false)
58 bool is_single =
false;
60 if (nargin > 0 &&
args(nargin-1).is_string ())
64 if (s_arg ==
"single")
69 else if (s_arg ==
"double")
76 error (
"%s: at least one argument is required", fcn);
77 else if (
args(0).is_string ())
78 additional_arg =
false;
81 a =
args(0).xarray_value (
"%s: dimension must be a scalar integer", fcn);
126 else if (s_arg ==
"seed")
128 else if (s_arg ==
"state" || s_arg ==
"twister")
130 else if (s_arg ==
"uniform")
132 else if (s_arg ==
"normal")
134 else if (s_arg ==
"exponential")
136 else if (s_arg ==
"poisson")
138 else if (s_arg ==
"gamma")
141 error (
"%s: unrecognized string argument", fcn);
148 error (
"%s: NaN is invalid matrix dimension", fcn);
162 error (
"%s: all elements of range must be integers", fcn);
174 dims(
i) = base >= 0 ? base : 0;
188 catch (octave::execution_exception&
e)
190 error (e,
"%s: dimensions must be a scalar or array of integers", fcn);
201 dims(
i) = elt >=0 ? elt : 0;
221 if (
args(idx+1).is_real_scalar ())
223 double d =
args(idx+1).double_value ();
227 else if (
args(idx+1).is_string ()
228 &&
args(idx+1).string_value () ==
"reset")
231 error (
"%s: seed must be a real scalar", fcn);
233 else if (ts ==
"state" || ts ==
"twister")
235 if (
args(idx+1).is_string ()
236 &&
args(idx+1).string_value () ==
"reset")
247 error (
"%s: unrecognized string argument", fcn);
256 args(idx+
i).xidx_type_value (
257 "%s: dimension must be a scalar or array of integers",
261 dims(
i) = elt >= 0 ? elt : 0;
286 error (
"%s: mismatch in argument size", fcn);
310 error (
"%s: mismatch in argument size", fcn);
745 error (
"randg: insufficient arguments");
747 return do_rand (
args, nargin,
"randg",
"gamma",
true);
967 int nargin =
args.length ();
970 error (
"randp: insufficient arguments");
972 return do_rand (
args, nargin,
"randp",
"poisson",
true);
1077 int nargin =
args.length ();
1079 if (nargin < 1 || nargin > 2)
1086 error (
"randperm: M and N must be non-negative");
1089 error (
"randperm: M must be less than or equal to N");
1093 bool short_shuffle = m < n/5;
1105 catch (
const std::bad_alloc&)
1110 short_shuffle =
true;
1121 std::unordered_map<octave_idx_type, octave_idx_type>
map (m);
1155 rvec[
i] = ivec[
i] + 1;
bool is_range(void) const
static void exponential_distribution(void)
static ColumnVector state(const std::string &d="")
static octave_value do_rand(const octave_value_list &args, int nargin, const char *fcn, const std::string &distribution, bool additional_arg=false)
OCTAVE_EXPORT octave_value_list isa nd deftypefn *return ovl(args(0).is_integer_type())
OCTINTERP_API void print_usage(void)
octave_idx_type numel(void) const
Number of elements in the array.
bool is_scalar_type(void) const
void resize(int n, int fill_value=0)
#define DEFUN(name, args_name, nargout_name, doc)
void error(const char *fmt,...)
static float float_scalar(float a=1.0)
const_iterator end(void) const
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
calling an anonymous function involves an overhead quite comparable to the overhead of an m file function Passing a handle to a built in function is because the interpreter is not involved in the internal loop For a
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
static std::string current_distribution
void add_fcn(void(*fcn)(void))
std::string string_value(bool force=false) const
nd deftypefn *octave_map m
static void gamma_distribution(void)
Range range_value(void) const
bool is_matrix_type(void) const
bool is_string(void) const
octave_idx_type numel(void) const
void resize(const dim_vector &dv, const T &rfv)
static void poisson_distribution(void)
the exceeded dimensions are set to if fewer subscripts than dimensions are the exceeding dimensions are merged into the final requested dimension For consider the following dims
void err_wrong_type_arg(const char *name, const char *s)
octave::unwind_protect frame
static NDArray nd_array(const dim_vector &dims, double a=1.0)
static FloatNDArray float_nd_array(const dim_vector &dims, float a=1.0)
=val(i)}if ode{val(i)}occurs in table i
octave_idx_type nint_big(double x)
static void normal_distribution(void)
bool all_elements_are_ints(void) const
static std::string distribution(void)
Array< int > int_vector_value(bool req_int=false, bool frc_str_conv=false, bool frc_vec_conv=false) const
const T * fortran_vec(void) const
static double scalar(double a=1.0)
double double_value(bool frc_str_conv=false) const
Vector representing the dimensions (size) of an Array.
void chop_trailing_singletons(void)
static void uniform_distribution(void)
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string