26#if defined (HAVE_CONFIG_H)
55GetPerms (
const Array<T>& ar_in,
bool uniq_v =
false)
62 std::iota (&myvidx[0], &myvidx[m], 0);
64 const T *Ar = ar_in.
data ();
85 if constexpr (std::is_same<T, octave_value>::value)
87 isequal = Ar[i].is_equal (Ar[j]);
89 isequal = (Ar[i] == Ar[j]);
91 if (myvidx[j] > myvidx[i] && isequal)
93 myvidx[j] = myvidx[i];
98 denom *= Factorial (N_el);
103 denom *= Factorial (N_el);
104 nr = Factorial (m) / denom;
110 std::sort (myvidx, myvidx + m, std::greater<octave_idx_type> ());
115 T *Res = res.rwdata ();
122 Res[i + j * n] = Ar[myvidx[j]];
125 while (std::next_permutation (myvidx, myvidx + m, std::greater<int> ()));
185 int nargin = args.length ();
187 if (nargin < 1 || nargin > 2)
196 const charMatrix opt = args (1).char_matrix_value ();
197 const char *str = opt.
data ();
198 if (std::string (str, opt.
cols ()) !=
"unique")
200 error (
"perms: option must be the string \"unique\".");
205 if (! (args (0).is_matrix_type () || args (0).is_range ()
206 || args (0).iscell () || args (0).is_scalar_type ()
207 || args (0).isstruct ()))
209 error (
"perms: V must be a matrix, range, cell array, "
210 "struct, or a scalar.");
213 std::string clname = args (0).class_name ();
216 if (clname ==
"double")
217 retval = GetPerms<double> (args (0).array_value (), uniq_v);
218 else if (clname ==
"single")
219 retval = GetPerms<float> (args (0).float_array_value (), uniq_v);
220 else if (clname ==
"logical")
221 retval = GetPerms<bool> (args (0).bool_array_value (), uniq_v);
222 else if (clname ==
"char")
223 retval = GetPerms<char> (args (0).char_array_value (), uniq_v);
224 else if (clname ==
"int8")
225 retval = GetPerms<octave_int8> (args (0).int8_array_value (), uniq_v);
226 else if (clname ==
"int16")
227 retval = GetPerms<octave_int16> (args (0).int16_array_value (), uniq_v);
228 else if (clname ==
"int32")
229 retval = GetPerms<octave_int32> (args (0).int32_array_value (), uniq_v);
230 else if (clname ==
"int64")
231 retval = GetPerms<octave_int64> (args (0).int64_array_value (), uniq_v);
232 else if (clname ==
"uint8")
233 retval = GetPerms<octave_uint8> (args (0).uint8_array_value (), uniq_v);
234 else if (clname ==
"uint16")
235 retval = GetPerms<octave_uint16> (args (0).uint16_array_value (), uniq_v);
236 else if (clname ==
"uint32")
237 retval = GetPerms<octave_uint32> (args (0).uint32_array_value (), uniq_v);
238 else if (clname ==
"uint64")
239 retval = GetPerms<octave_uint64> (args (0).uint64_array_value (), uniq_v);
240 else if (clname ==
"cell")
241 retval = GetPerms<octave_value> (args (0).cell_value (), uniq_v);
242 else if (clname ==
"struct")
244 const octave_map map_in (args (0).map_value ());
254 if (fn.
numel () == 0)
262 out.
assign (fn (i), GetPerms<octave_value>
263 (map_in.
contents (fn (i)), uniq_v));
271 warning (
"perms: unable to permute for class %s", clname.c_str ());
346OCTAVE_END_NAMESPACE (octave)
N Dimensional Array with copy-on-write semantics.
octave_idx_type cols() const
const T * data() const
Size of the specified dimension.
octave_idx_type numel() const
Number of elements in the array.
Vector representing the dimensions (size) of an Array.
string_vector fieldnames() const
const Cell & contents(const_iterator p) const
octave_idx_type numel() const
void assign(const std::string &k, const Cell &val)
octave_idx_type numel() const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
void warning(const char *fmt,...)
void error(const char *fmt,...)
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.