25 #if defined (HAVE_CONFIG_H) 30 #include <unordered_map> 82 const std::string& distribution,
bool additional_arg =
false)
86 bool is_single =
false;
92 if (s_arg ==
"single")
97 else if (s_arg ==
"double")
104 error (
"%s: at least one argument is required",
fcn);
105 else if (args(0).is_string ())
106 additional_arg =
false;
109 a = args(0).xarray_value (
"%s: dimension must be a scalar integer",
fcn);
148 if (
tmp.is_string ())
154 else if (s_arg ==
"seed")
156 else if (s_arg ==
"state" || s_arg ==
"twister")
158 else if (s_arg ==
"uniform")
160 else if (s_arg ==
"normal")
162 else if (s_arg ==
"exponential")
164 else if (s_arg ==
"poisson")
166 else if (s_arg ==
"gamma")
169 error (
"%s: unrecognized string argument",
fcn);
171 else if (
tmp.is_scalar_type ())
173 double dval =
tmp.double_value ();
176 error (
"%s: NaN is invalid matrix dimension",
fcn);
185 else if (
tmp.is_range ())
190 error (
"%s: all elements of range must be integers",
fcn);
202 dims(
i) = (base >= 0 ? base : 0);
208 else if (
tmp.is_matrix_type ())
214 iv =
tmp.int_vector_value (
true);
216 catch (octave::execution_exception&
e)
218 error (
e,
"%s: dimensions must be a scalar or array of integers",
fcn);
229 dims(
i) = (elt >=0 ? elt : 0);
249 if (args(idx+1).is_real_scalar ())
251 double d = args(idx+1).double_value ();
255 else if (args(idx+1).is_string ()
256 && args(idx+1).string_value () ==
"reset")
259 error (
"%s: seed must be a real scalar",
fcn);
261 else if (ts ==
"state" || ts ==
"twister")
263 if (args(idx+1).is_string ()
264 && args(idx+1).string_value () ==
"reset")
281 error (
"%s: unrecognized string argument",
fcn);
290 args(idx+
i).xidx_type_value (
291 "%s: dimension must be a scalar or array of integers",
295 dims(
i) = (elt >= 0 ? elt : 0);
309 dims.chop_trailing_singletons ();
319 if (
a.dims () !=
dims)
320 error (
"%s: mismatch in argument size",
fcn);
343 if (
a.dims () !=
dims)
344 error (
"%s: mismatch in argument size",
fcn);
450 return do_rand (args, args.length (),
"rand",
"uniform");
543 DEFUN (randn, args, ,
576 return do_rand (args, args.length (),
"randn",
"normal");
610 DEFUN (rande, args, ,
643 return do_rand (args, args.length (),
"rande",
"exponential");
679 DEFUN (randg, args, ,
780 int nargin = args.length ();
783 error (
"randg: insufficient arguments");
954 DEFUN (randp, args, ,
1005 int nargin = args.length ();
1008 error (
"randp: insufficient arguments");
1099 DEFUN (randperm, args, ,
1115 int nargin = args.length ();
1124 error (
"randperm: M and N must be non-negative");
1127 error (
"randperm: M must be less than or equal to N");
1131 bool short_shuffle = m < n/5;
1143 catch (
const std::bad_alloc&)
1148 short_shuffle =
true;
1159 std::unordered_map<octave_idx_type, octave_idx_type>
map (m);
1193 rvec[
i] = ivec[
i] + 1;
static void exponential_distribution(void)
static octave_value do_rand(const octave_value_list &args, int nargin, const char *fcn, const std::string &distribution, bool additional_arg=false)
OCTINTERP_API void print_usage(void)
bool all_elements_are_ints(void) const
const T * fortran_vec(void) const
void add_fcn(void(*fcn)(void))
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
void error(const char *fmt,...)
std::complex< T > floor(const std::complex< T > &x)
const_iterator end(void) const
static float float_scalar(float a=1.0)
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 const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &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
static std::string current_distribution
static void gamma_distribution(void)
octave_idx_type numel(void) const
void resize(const dim_vector &dv, const T &rfv)
Resizing (with fill).
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)
OCTAVE_EXPORT octave_value_list isa nd deftypefn *return ovl(args(0).isinteger())
static FloatNDArray float_nd_array(const dim_vector &dims, float a=1.0)
octave_idx_type nint_big(double x)
static void normal_distribution(void)
static std::string distribution(void)
static double scalar(double a=1.0)
octave_idx_type numel(void) const
Number of elements in the array.
Vector representing the dimensions (size) of an Array.
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
static uint32NDArray state(const std::string &d="")