Skip to main content

Vector

Trait Vector 

Source
pub trait Vector: Sized {
    type Element;
    type ElementOutput<'a>
       where Self: 'a;

Show 19 methods // Required methods fn from_elements(xs: &[Self::Element]) -> Self where Self::Element: Clone; fn from_owned_elements(xs: Vec<Self::Element>) -> Self; fn zero(dimension: u64) -> Self; fn standard_basis_vector(dimension: u64, index: u64) -> Self; fn push(&mut self, x: Self::Element); fn set_dimension(&mut self, dimension: u64); fn set_zero(&mut self); fn sort(&mut self); fn to_elements(&self) -> Vec<Self::Element> where Self::Element: Clone; fn into_elements(self) -> Vec<Self::Element>; fn elements_ref(&self) -> &[Self::Element]; fn dimension(&self) -> u64; fn is_zero(&self) -> bool; fn pivot(&self) -> Option<Self::ElementOutput<'_>>; fn pivot_index(&self) -> Option<u64>; fn height_index(&self) -> Option<u64>; fn standard_basis_index(&self) -> Option<u64>; fn max_bits(&self) -> (u64, bool); fn sum_max_bits(&self) -> (u64, u64);
}
Expand description

What every vector type has in common: a vector of a fixed dimension, stored as its elements in order.

The functions here are the ones whose meaning does not depend on what the elements are. Each implementation documents its own complexity and gives its own examples.

Required Associated Types§

Source

type Element

The type of an element.

Source

type ElementOutput<'a> where Self: 'a

What pivot returns.

This is a reference to an Element when the vector holds elements that are expensive to copy, and an Element itself when one is cheap to copy.

Required Methods§

Source

fn from_elements(xs: &[Self::Element]) -> Self
where Self::Element: Clone,

Converts a slice to a vector, cloning the elements.

The vector’s dimension is the length of the slice. Every slice is a valid vector, so this cannot fail; the empty slice gives the 0-dimensional vector.

Source

fn from_owned_elements(xs: Vec<Self::Element>) -> Self

Converts a Vec to a vector, taking ownership of it.

The vector’s dimension is the length of the Vec. Every Vec is a valid vector, so this cannot fail, and nothing is copied or allocated.

Source

fn zero(dimension: u64) -> Self

Returns the zero vector of a given dimension: a vector of dimension zeros.

Source

fn standard_basis_vector(dimension: u64, index: u64) -> Self

Returns a standard basis vector: the vector of a given dimension whose element at index is 1 and whose other elements are 0.

Source

fn push(&mut self, x: Self::Element)

Appends an element to the end of a vector, increasing its dimension by 1.

Source

fn set_dimension(&mut self, dimension: u64)

Sets the dimension of a vector, removing elements from the end if the new dimension is smaller, and appending zeros if it is larger.

Source

fn set_zero(&mut self)

Sets every element of a vector to zero, keeping its dimension.

Source

fn sort(&mut self)

Sorts the elements of a vector in ascending order, keeping its dimension.

Source

fn to_elements(&self) -> Vec<Self::Element>
where Self::Element: Clone,

Returns a vector’s elements as a Vec, cloning them.

Source

fn into_elements(self) -> Vec<Self::Element>

Returns a vector’s elements as a Vec, taking ownership of the vector.

The Vec is what from_owned_elements would take back.

Source

fn elements_ref(&self) -> &[Self::Element]

Returns a reference to a vector’s elements, as a slice.

Source

fn dimension(&self) -> u64

Returns the dimension of a vector: the number of its elements.

Source

fn is_zero(&self) -> bool

Determines whether every element of a vector is zero. This includes the 0-dimensional vector, which has no elements.

Source

fn pivot(&self) -> Option<Self::ElementOutput<'_>>

Returns the pivot of a vector: its first nonzero element.

This is the element that leads the vector when it is a row of a matrix in echelon form. Returns None if every element is zero, which includes the 0-dimensional vector.

Source

fn pivot_index(&self) -> Option<u64>

Returns the index of the pivot of a vector: the position of its first nonzero element.

Indices start at 0, as they do for Index. Returns None if every element is zero, which includes the 0-dimensional vector. When it returns Some(i), pivot is the element at i.

Source

fn height_index(&self) -> Option<u64>

Returns the index of an element of largest height: the first one, when several share it.

The height of an integer is its absolute value, and the height of a rational number $p/q$ in lowest terms is $\max(|p|, q)$. Returns None for the 0-dimensional vector.

Source

fn standard_basis_index(&self) -> Option<u64>

Determines whether a vector is a standard basis vector, returning the index of its 1 if it is.

A standard basis vector has a single element equal to 1 and every other element 0, as standard_basis_vector builds. Returns None for every other vector, including the zero vectors and the 0-dimensional vector. When it returns Some(i), i is also the pivot_index, and the vector equals standard_basis_vector(self.dimension(), i).

Source

fn max_bits(&self) -> (u64, bool)

Returns the number of significant bits of a vector’s height, together with whether any of its elements is negative.

The bit count is the largest bit length of any element’s height, or 0 for the 0-dimensional vector; it is what Height::height_significant_bits returns.

Source

fn sum_max_bits(&self) -> (u64, u64)

Returns the number of significant bits of a vector’s $\ell^1$ norm, the sum of the absolute values of its elements, together with the number of significant bits of its height.

The counts are what L1Norm::l1_norm_significant_bits and Height::height_significant_bits return, computed together in one pass where possible. The height of the 0-dimensional vector is 0, and so, for integer elements, is its norm.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T: PrimitiveUnsigned> Vector for UnsignedVector<T>

Source§

type Element = T

Source§

type ElementOutput<'a> = T where Self: 'a