155 std::default_random_engine::result_type seed =
156 std::default_random_engine::default_seed);
182 std::default_random_engine::default_seed) {
210 std::default_random_engine::result_type seed =
211 std::default_random_engine::default_seed) {
233 storage_t::const_iterator
end()
const {
return storage.end(); }
252 void print(std::ostream &os, uint8_t precision = 0,
253 uint8_t width = 0)
const;
369 *
this = std::move(other);
376 this->
storage = std::move(other.storage);
377 std::swap(this->
type, other.type);
378 std::swap(this->
reverse_, other.reverse_);
379 other.clear_and_deallocate();
412 for (
size_t i =
size(); i-- > 0;)
414 std::swap(p[i], p[This(i)]);
417 for (
size_t i = 0; i <
size(); ++i)
419 std::swap(p[i], p[This(i)]);
427 std::copy(init.begin(), init.end(), permutation.begin());
439 for (
size_t i =
size(); i-- > 0;)
444 for (
size_t i = 0; i <
size(); ++i)
456 for (
size_t i =
size(); i-- > 0;)
461 for (
size_t i = 0; i <
size(); ++i)
std::ostream & operator<<(std::ostream &os, const HouseholderQR &qr)
Print the Q and R matrices of a HouseholderQR object.
void swap_columns(size_t a, size_t b)
Swap two columns of the matrix.
void swap_rows(size_t a, size_t b)
Swap two rows of the matrix.
size_t rows() const
Get the number of rows of the matrix.
size_t cols() const
Get the number of columns of the matrix.
Class that represents matrices that permute the rows or columns of other matrices.
storage_t::const_iterator begin() const
Get the iterator to the first element of the swapping sequence.
PermutationMatrix & operator=(std::initializer_list< size_t > init)
Assign the given permutation to the matrix.
@ RowPermutation
Can be used for permuting rows only.
@ Unspecified
Can be used for permuting rows or columns.
@ ColumnPermutation
Can be used for permuting columns only.
size_t size() const
Get the size of the permutation matrix.
void fill_random(std::default_random_engine::result_type seed=std::default_random_engine::default_seed)
Fill the matrix with a random permutation.
static PermutationMatrix from_permutation(Permutation permutation, Type type=Unspecified)
Create a permutation matrix from the given permutation.
void reverse()
Reverse the order of the permutations.
Permutation to_permutation() const
Convert a permutation matrix into a mathematical permutation.
storage_t::iterator end()
Get the iterator to the element past the end of the swapping sequence.
PermutationMatrix & operator=(const PermutationMatrix &)=default
Default copy assignment.
PermutationMatrix(const PermutationMatrix &)=default
Default copy constructor.
PermutationMatrix()=default
Default constructor.
void permute_columns(Matrix &A) const
Apply the permutation to the columns of matrix A.
void resize(size_t size)
Resize the permutation matrix.
void transpose_inplace()
Transpose or invert the permutation matrix.
bool is_reversed() const
Check if the permutation should be applied in reverse.
storage_t::const_iterator cend() const
Get the iterator to the element past the end of the swapping sequence.
const size_t & operator()(size_t index) const
Get the element at the given position in the swap sequence.
PermutationMatrix(Type type)
Create an empty permutation matrix with the given type.
static PermutationMatrix random(size_t rows, Type type=Unspecified, std::default_random_engine::result_type seed=std::default_random_engine::default_seed)
Create a random permutation matrix.
size_t num_elems() const
Get the number of elements in the matrix:
void fill_from_permutation(Permutation permutation)
Create a permutation matrix from the given permutation.
void set_type(Type type)
Set the type of permutation matrix (whether it permutes rows or columns, or unspecified).
Type get_type() const
Get the type of permutation matrix (whether it permutes rows or columns, or unspecified).
storage_t Permutation
Type that represents a permutation (in the mathematical sense, a permutation of the integers 0 throug...
size_t & operator()(size_t index)
Get the element at the given position in the swap sequence.
size_t rows() const
Get the number of rows of the permutation matrix.
PermutationMatrix(size_t rows, Type type=Unspecified)
Create a permutation matrix without permutations.
storage_t::const_iterator cbegin() const
Get the iterator to the first element of the swapping sequence.
static PermutationMatrix identity(size_t rows, Type type=Unspecified)
Create an identity permutation matrix.
void clear_and_deallocate()
Set the size to zero, and deallocate the storage.
util::storage_t< size_t > storage_t
Container to store the elements of the permutation matrix internally.
void fill_identity()
Fill the matrix as an identity permutation.
SquareMatrix to_matrix(Type type=Unspecified) const
Convert a permutation matrix into a full matrix.
size_t cols() const
Get the number of columns of the permutation matrix.
storage_t::iterator begin()
Get the iterator to the first element of the swapping sequence.
static Permutation identity_permutation(size_t length)
Return the identity permutation (0, 1, 2, 3, ..., length-1).
storage_t::const_iterator end() const
Get the iterator to the element past the end of the swapping sequence.
void permute_rows(Matrix &A) const
Apply the permutation to the rows of matrix A.
void print(std::ostream &os, uint8_t precision=0, uint8_t width=0) const
Print a permutation matrix.
static Permutation random_permutation(size_t length, std::default_random_engine::result_type seed=std::default_random_engine::default_seed)
Return a random permutation of the integers 0 through length-1.
A row vector (1×n matrix).
static SquareMatrix identity(size_t rows)
Create a square identity matrix.
A column vector (n×1 matrix).
Matrix operator*(const PermutationMatrix &P, const Matrix &A)
Left application of permutation matrix (P permutes rows of A).
PermutationMatrix transpose(const PermutationMatrix &P)
Transpose a permutation matrix (inverse permutation).
std::vector< T > storage_t
Container to store the elements of a matrix internally.