Struct perm_vec::Perm[][src]

pub struct Perm { /* fields omitted */ }

Represents a reordering operation on an array.

See the Permute trait for more information.

Implementations

impl Perm[src]

pub fn eye(n: usize) -> Perm[src]

Construct the identity perm of a given length.

pub fn len(&self) -> usize[src]

Get the length of the permutation.

pub fn argsort<T: Ord>(xs: &[T]) -> Perm[src]

Compute the Perm that, when applied to the input slice, would (stably) sort it.

pub fn argsort_unstable<T: Ord>(xs: &[T]) -> Perm[src]

Compute a Perm that, when applied to the input slice, would sort it. (not necessarily stably)

pub fn from_vec(vec: Vec<usize>) -> Result<Perm, InvalidPermutationError>[src]

Construct a perm. Useful for literals in unit tests.

The representation accepted by this is comparable to indexing with an integer array in numpy. If the kth element of the permutation vector is value, then applying the permutation will pull the data at index value into index k.

This performs O(n log n) validation on the data to verify that it satisfies the invariants of Perm. It also inverts the perm (an O(n) operation).

pub fn from_raw_inv(inv: Vec<usize>) -> Result<Perm, InvalidPermutationError>[src]

Construct a perm from the vector internally used to represent it.

The format taken by this method is actually the inverse of the format accepted by from_vec. If the kth element of the permutation vector is value, then applying the permutation will push the data at index k over to index value. This format is generally trickier to think about, but is superior to the from_vec representation in terms of efficiency.

This performs O(n log n) validation on the data to verify that it satisfies the invariants of Perm.

pub unsafe fn from_raw_inv_unchecked(inv: Vec<usize>) -> Perm[src]

No-op constructor. Still performs checking in debug builds.

Safety

inv must contain every element in (0..inv.len()), or else the behavior is undefined.

pub fn append_mut(&mut self, other: &Perm)[src]

Construct a permutation of length a.len() + b.len().

Mathematically speaking, this computes the "direct sum" of two permutations.

The inserted elements will be shifted by this permutation's length, so that they operate on an entirely independent set of data from the existing elements.

pub fn random(n: usize) -> Perm[src]

Construct a random permutation of the given length.

pub fn into_vec(self) -> Vec<usize>[src]

Recover the vector representation of the permutation.

See Perm::from_vec for more details about this representation.

This has a runtime cost of O(n), because Perm does not actually store this vector. See Perm::into_raw_inv for a constant-time alternative.

pub fn into_raw_inv(self) -> Vec<usize>[src]

Obtain the vector that is internally used to represent the permutation.

This representation is actually the inverse of the representation produced by Perm::into_vec. See Perm::from_raw_inv for more information.

#[must_use = "not an in-place operation"]pub fn inverted(&self) -> Perm[src]

Get the inverse of this permutation.

pub fn shift_right(self, amt: usize) -> Self[src]

Compose with the permutation that shifts elements forward (performing self first)

To construct the shift permutation itself, use Perm::eye(n).shift_right(amt).

pub fn shift_left(self, amt: usize) -> Self[src]

Compose with the permutation that shifts elements backward (performing self first)

To construct the shift permutation itself, use Perm::eye(n).shift_left(amt).

pub fn shift_signed(self, n: isize) -> Self[src]

Compose with the permutation that shifts elements to the right by a signed offset.

pub fn permute_index(&self, i: usize) -> usize[src]

Apply the permutation to an index. O(1).

Calling this on the indices contained in a sparse-format data structure will produce the same indices as if the corresponding dense-format data structure were permuted.

Panics

Panics if i is out of bounds for the permutation length.

pub fn with_outer(&self, slower: &Perm) -> Perm[src]

Construct the outer product of self and slower, with self being the fast (inner) index.

The resulting Perm will permute blocks of size self.len() according to slower, and will permute elements within each block by self.

pub fn with_inner(&self, faster: &Perm) -> Perm[src]

Construct the outer product of self and faster, with self being the slow (outer) index.

pub fn pow_unsigned(&self, mut exp: u64) -> Perm[src]

Compute the permutation that applies this permutation exp times in a row.

This uses exponentiation by squaring to run in O(log(exp)) time.

pub fn pow_signed(&self, exp: i64) -> Perm[src]

Compute the permutation that applies this permutation exp times in a row.

This version of the function takes a signed value, so that negative values can produce powers of the inverse.

This uses exponentiation by squaring to run in O(log(exp)) time.

impl Perm[src]

pub fn then(&self, other: &Perm) -> Perm[src]

Flipped group operator, which composes left-to-right.

Very simply. a.then(b) == b.of(a). The flipped order can feel more natural when using method syntax, or if you are dealing with matrix equations written in a row-centric formalism.

Additionally, it has a straightforward relation to the group action:

x.permuted_by(a).permuted_by(b) == x.permuted_by(a.then(b))

pub fn of(&self, other: &Perm) -> Perm[src]

Conventional group operator, which composes right-to-left.

Trait Implementations

impl Clone for Perm[src]

impl Debug for Perm[src]

impl Eq for Perm[src]

impl Hash for Perm[src]

impl PartialEq<Perm> for Perm[src]

impl Permute for Perm[src]

impl StructuralEq for Perm[src]

impl StructuralPartialEq for Perm[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.