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§
Sourcetype ElementOutput<'a>
where
Self: 'a
type ElementOutput<'a> where Self: 'a
Required Methods§
Sourcefn from_elements(xs: &[Self::Element]) -> Self
fn from_elements(xs: &[Self::Element]) -> Self
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.
Sourcefn from_owned_elements(xs: Vec<Self::Element>) -> Self
fn from_owned_elements(xs: Vec<Self::Element>) -> Self
Sourcefn zero(dimension: u64) -> Self
fn zero(dimension: u64) -> Self
Returns the zero vector of a given dimension: a vector of dimension zeros.
Sourcefn standard_basis_vector(dimension: u64, index: u64) -> Self
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.
Sourcefn push(&mut self, x: Self::Element)
fn push(&mut self, x: Self::Element)
Appends an element to the end of a vector, increasing its dimension by 1.
Sourcefn set_dimension(&mut self, dimension: u64)
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.
Sourcefn to_elements(&self) -> Vec<Self::Element>
fn to_elements(&self) -> Vec<Self::Element>
Returns a vector’s elements as a Vec, cloning them.
Sourcefn into_elements(self) -> Vec<Self::Element>
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.
Sourcefn elements_ref(&self) -> &[Self::Element]
fn elements_ref(&self) -> &[Self::Element]
Returns a reference to a vector’s elements, as a slice.
Sourcefn is_zero(&self) -> bool
fn is_zero(&self) -> bool
Determines whether every element of a vector is zero. This includes the 0-dimensional vector, which has no elements.
Sourcefn pivot(&self) -> Option<Self::ElementOutput<'_>>
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.
Sourcefn pivot_index(&self) -> Option<u64>
fn pivot_index(&self) -> Option<u64>
Sourcefn height_index(&self) -> Option<u64>
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.
Sourcefn standard_basis_index(&self) -> Option<u64>
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).
Sourcefn max_bits(&self) -> (u64, bool)
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.
Sourcefn sum_max_bits(&self) -> (u64, u64)
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".