tools
Declared in include/lasyten/tools.h.
lasyten::NotImplemented
Free functions
-
std::string lasyten::format_like_list(py::iterable it)[source]
Format elements of an iterable as if it were a plain list.
Format elements of an iterable as if it were a plain list.
This means surrounding them with brackets and separating them by
', '.
-
py::object lasyten::to_iterable(py::object a)[source]
If
ais not iterable or a string, return [a], else return a.
-
int64 lasyten::to_valid_idx(int64 idx, int64 length)[source]
Convert to a valid index into the given length, with python convention of negative indices from back
-
std::vector<int64> lasyten::permutation_as_swaps(std::vector<int64> const &permutation)[source]
Decompose a permutation into a sequence of adjacent swaps.
Realizes
permutationas swaps of neighboring positions: each returned indexjmeansswap(j, j + 1), i.e. the permutation[*range(j), j + 1, j, *range(j + 2, n)]. Applying those swaps in order torange(n)yieldspermutation. This is the shared helper behindCoupling::permuteandPermuteLegsInstructionEngine.- Parameters:
permutation – A permutation of
range(n).permutation[k]is the original index that ends up at positionk.- Returns:
Swap positions
j(each representingj <-> j + 1). Throwsstd::invalid_argumentifpermutationis not a permutation ofrange(n).