tools

Declared in include/lasyten/tools.h.

lasyten::NotImplemented

class NotImplemented : public std::logic_error[source]

Public Functions

NotImplemented(std::string name)[source]

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 ', '.

bool lasyten::is_iterable(py::object a)[source]

If the given object is iterable.

py::object lasyten::to_iterable(py::object a)[source]

If a is 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 permutation as swaps of neighboring positions: each returned index j means swap(j, j + 1), i.e. the permutation [*range(j), j + 1, j, *range(j + 2, n)]. Applying those swaps in order to range(n) yields permutation. This is the shared helper behind Coupling::permute and PermuteLegsInstructionEngine.

Parameters:

permutation – A permutation of range(n). permutation[k] is the original index that ends up at position k.

Returns:

Swap positions j (each representing j <-> j + 1). Throws std::invalid_argument if permutation is not a permutation of range(n).

Subheaders