26#if defined (HAVE_CONFIG_H)
55GetPerms (
const Array<T>& ar_in,
bool uniq_v =
false)
58 double nr = Factorial (m);
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];
97 nr /= Factorial (count);
104 std::sort (myvidx, myvidx + m, std::greater<octave_idx_type> ());
109 T *Res = res.rwdata ();
116 Res[i + j * n] = Ar[myvidx[j]];
119 while (std::next_permutation (myvidx, myvidx + m, std::greater<int> ()));
179 int nargin = args.length ();
181 if (nargin < 1 || nargin > 2)
190 const charMatrix opt = args (1).char_matrix_value ();
191 const char *str = opt.
data ();
192 if (std::string (str, opt.
cols ()) !=
"unique")
194 error (
"perms: option must be the string \"unique\".");
199 if (! (args (0).is_matrix_type () || args (0).is_range ()
200 || args (0).iscell () || args (0).is_scalar_type ()
201 || args (0).isstruct ()))
203 error (
"perms: V must be a matrix, range, cell array, "
204 "struct, or a scalar.");
207 std::string clname = args (0).class_name ();
210 if (clname ==
"double")
211 retval = GetPerms<double> (args (0).array_value (), uniq_v);
212 else if (clname ==
"single")
213 retval = GetPerms<float> (args (0).float_array_value (), uniq_v);
214 else if (clname ==
"logical")
215 retval = GetPerms<bool> (args (0).bool_array_value (), uniq_v);
216 else if (clname ==
"char")
217 retval = GetPerms<char> (args (0).char_array_value (), uniq_v);
218 else if (clname ==
"int8")
219 retval = GetPerms<octave_int8> (args (0).int8_array_value (), uniq_v);
220 else if (clname ==
"int16")
221 retval = GetPerms<octave_int16> (args (0).int16_array_value (), uniq_v);
222 else if (clname ==
"int32")
223 retval = GetPerms<octave_int32> (args (0).int32_array_value (), uniq_v);
224 else if (clname ==
"int64")
225 retval = GetPerms<octave_int64> (args (0).int64_array_value (), uniq_v);
226 else if (clname ==
"uint8")
227 retval = GetPerms<octave_uint8> (args (0).uint8_array_value (), uniq_v);
228 else if (clname ==
"uint16")
229 retval = GetPerms<octave_uint16> (args (0).uint16_array_value (), uniq_v);
230 else if (clname ==
"uint32")
231 retval = GetPerms<octave_uint32> (args (0).uint32_array_value (), uniq_v);
232 else if (clname ==
"uint64")
233 retval = GetPerms<octave_uint64> (args (0).uint64_array_value (), uniq_v);
234 else if (clname ==
"cell")
235 retval =
Cell (GetPerms<octave_value> (args (0).cell_value (), uniq_v));
236 else if (clname ==
"struct")
238 const octave_map map_in (args (0).map_value ());
248 if (fn.
numel () == 0)
256 out.
assign (fn (i), GetPerms<octave_value>
257 (map_in.
contents (fn (i)), uniq_v));
265 warning (
"perms: unable to permute for class %s", clname.c_str ());
348OCTAVE_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.