Vector

Trait Vector 

Source
pub trait Vector<S>
where S: Integer, Self: Clone + Copy + Eq + Hash + Index<usize, Output = S> + FromIterator<S> + VectorOps<S, Self> + for<'a> VectorOps<S, &'a Self> + Div<S, Output = Self> + for<'a> Div<&'a S, Output = Self> + Rem<S, Output = Self> + for<'a> Rem<&'a S, Output = Self> + Div<Self, Output = Self> + for<'a> Div<&'a Self, Output = Self> + Rem<Self, Output = Self> + for<'a> Rem<&'a Self, Output = Self> + Sum<Self> + for<'a> Sum<&'a Self>,
{ type DefaultLayout: Layout<S, Self>; const DIM: usize;
Show 17 methods // Required methods fn with<F>(f: F) -> Self where F: Fn(usize) -> S; fn as_slice(&self) -> &[S]; fn as_mut_slice(&mut self) -> &mut [S]; fn norm_l1(&self) -> S; fn norm_l_infty(&self) -> S; fn norm_l2_squared(&self) -> S; fn componentwise_cmp(&self, other: &Self) -> Option<Ordering>; fn lex_cmp(&self, other: &Self) -> Ordering; // Provided methods fn zero() -> Self { ... } fn ones() -> Self { ... } fn is_zero(&self) -> bool { ... } fn min(&self, other: Self) -> Self { ... } fn max(&self, other: Self) -> Self { ... } fn signum(&self) -> Self { ... } fn unit_vecs() -> UnitVecs<S, Self> { ... } fn unit_vecs_l1() -> UnitVecsL1<S, Self> { ... } fn unit_vecs_l_infty() -> UnitVecsLInfty<S, Self> { ... }
}
Expand description

Required traits and operations for vectors.

Required Associated Constants§

Source

const DIM: usize

The dimension of the vectors in this type.

Required Associated Types§

Source

type DefaultLayout: Layout<S, Self>

The default layout to use with this vector.

Required Methods§

Source

fn with<F>(f: F) -> Self
where F: Fn(usize) -> S,

Create a vector from a function which computes the coordinates.

The function must return a scalar value for each possible coordinate index.

§Example
assert_eq!(v4d(0, 1, 2, 3), Vec4d::with(|i| i64::try_from(i).unwrap()));
Source

fn as_slice(&self) -> &[S]

Returns a slice containing the coordinates of the vector.

Source

fn as_mut_slice(&mut self) -> &mut [S]

Returns a mutable slice containing the coordinates of the vector.

Source

fn norm_l1(&self) -> S

Returns the L1 norm of the vector.

This is also called the taxicab, Manhatten or city block norm.

Source

fn norm_l_infty(&self) -> S

Returns the L∞ norm of the vector.

This is also called the maximum or Chebychev norm.

Source

fn norm_l2_squared(&self) -> S

Returns the square of the L2-norm of the vector.

The L2-norm is also called the Euclidean norm and is the standard notion of the length of a vector.

Source

fn componentwise_cmp(&self, other: &Self) -> Option<Ordering>

Returns the partial ordering by component of two vectors.

Source

fn lex_cmp(&self, other: &Self) -> Ordering

Returns the lexicographic total ordering for this and another vector.

That is, the first different coordinate decides the ordering. This is useful as an arbitrary total ordering for sorting, but is not intended to be otherwise meaningful.

Provided Methods§

Source

fn zero() -> Self

Creates the zero vector.

Source

fn ones() -> Self

Creates a vector of ones.

Source

fn is_zero(&self) -> bool

Returns true if a vector is the zero vector.

Source

fn min(&self, other: Self) -> Self

Apply min by component

Source

fn max(&self, other: Self) -> Self

Apply max by component

Source

fn signum(&self) -> Self

Signum by component.

Maps a vector to a unit step in the L∞ norm. This is a step on a shortest path w.r.t. L∞ along the vector.

Source

fn unit_vecs() -> UnitVecs<S, Self>

Returns an iterator that yields the unit vectors.

Source

fn unit_vecs_l1() -> UnitVecsL1<S, Self>

Returns an iterator that yields the vectors to orthogonal neighbours.

These are the vectors with L1 norm equal to 1.

Source

fn unit_vecs_l_infty() -> UnitVecsLInfty<S, Self>

Returns an iterator that yields the vectors with L∞ norm equal to 1.

These correspond to a single orthogonal or diagonal step.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<S: Integer> Vector<S> for Vec2d<S>

Source§

const DIM: usize = 2usize

Source§

type DefaultLayout = Layout2d<S>

Source§

impl<S: Integer> Vector<S> for Vec3d<S>

Source§

const DIM: usize = 3usize

Source§

type DefaultLayout = Layout3d<S>

Source§

impl<S: Integer> Vector<S> for Vec4d<S>

Source§

const DIM: usize = 4usize

Source§

type DefaultLayout = Layout4d<S>